From e2e992cbdaf08e6f70359962f4aa0b1f285d2339 Mon Sep 17 00:00:00 2001 From: Xiaohan-Tian <157918347+Xiaohan-Tian@users.noreply.github.com> Date: Tue, 12 Aug 2025 20:01:51 -0700 Subject: [PATCH] when converting KGTrack to ABC Notation Music Sheet, we should display the drum instrument name instead of the real track name in case the real track name can't indicate the track is using drum pitch notes. --- src/agent/tools/ReadMusicTool.ts | 38 ++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/agent/tools/ReadMusicTool.ts b/src/agent/tools/ReadMusicTool.ts index 97e4658..cf39a80 100644 --- a/src/agent/tools/ReadMusicTool.ts +++ b/src/agent/tools/ReadMusicTool.ts @@ -4,6 +4,7 @@ import { KGMidiTrack } from '../../core/track/KGMidiTrack'; import { KGMidiRegion } from '../../core/region/KGMidiRegion'; import { convertRegionToABCNotation } from '../../util/abcNotationUtil'; import { KEY_SIGNATURE_MAP } from '../../constants/coreConstants'; +import { FLUIDR3_INSTRUMENT_MAP } from '../../constants/generalMidiConstants'; /** * Tool for reading music content from the project @@ -31,6 +32,25 @@ export class ReadMusicTool extends BaseTool { } }; + /** + * Get the display name for percussion instruments, or null if not percussion + */ + private getPercussionDisplayName(track: KGMidiTrack): string | null { + try { + const instrument = track.getInstrument(); + const instrumentInfo = FLUIDR3_INSTRUMENT_MAP[instrument]; + + if (instrumentInfo && instrumentInfo.group === 'PERCUSSION_KIT') { + return instrumentInfo.displayName; + } + + return null; + } catch (error) { + console.error('Error getting percussion display name:', error); + return null; + } + } + async execute(params: Record): Promise { try { // Validate parameters @@ -168,8 +188,22 @@ export class ReadMusicTool extends BaseTool { const trackNumber = index + 1; const trackName = track.getName() || `Track ${trackNumber}`; - // hardcode the 1st track to be the melody, other track names are the same as the original track names - output += `Track ${trackNumber} - ${trackNumber === 1 ? 'Melody' : trackName}:\n`; + // Check if this track uses a percussion instrument + const percussionDisplayName = this.getPercussionDisplayName(track); + + let displayTrackName: string; + if (percussionDisplayName) { + // Use percussion instrument display name for all percussion tracks + displayTrackName = percussionDisplayName; + } else if (trackNumber === 1) { + // Use "Melody" for the first non-percussion track + displayTrackName = 'Melody'; + } else { + // Use original track name for other non-percussion tracks + displayTrackName = trackName; + } + + output += `Track ${trackNumber} - ${displayTrackName}:\n`; // Get all regions from the track and convert each one const regions = track.getRegions().filter(region => region instanceof KGMidiRegion) as KGMidiRegion[];