get_notes_by_index
Retrieve musical notes from a specific track in a MIDI file using track index to access and analyze individual instrument data.
Instructions
Get notes from midi file by track index
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absoulate File Path to midi file | |
| trackIndex | Yes | Track index number |
Implementation Reference
- src/main.ts:151-171 (handler)Primary implementation block: registers and defines the handler for 'get_notes_by_index' tool. Includes inline schema, loads MIDI file, retrieves track by index, extracts and JSONifies notes for return.server.tool( 'get_notes_by_index', 'Get notes from midi file by track index', { filePath: z.string().describe('Absoulate File Path to midi file'), trackIndex: z.number().describe('Track index number'), }, withErrorHandling(({ filePath, trackIndex }) => { const midi = loadMidiFile(filePath) const track = getTrackByIndex(midi, trackIndex) const notes = track.notes.map((note: any) => note.toJSON()) return { content: [ { type: 'text', text: JSON.stringify(notes), }, ] } }) )
- src/utils/obj-utils.ts:1-6 (helper)Supporting helper function called by the tool handler to safely retrieve a MIDI track by its index.export function getTrackByIndex(midi: any, trackIndex: number) { if (trackIndex < 0 || trackIndex >= midi.tracks.length) { throw new Error('Track index out of range') } return midi.tracks[trackIndex] }
- src/utils/file-util.ts:5-9 (helper)Supporting helper function called by the tool handler to load a MIDI file from the filesystem into a Midi object.export function loadMidiFile(filePath: string) { const midiData = fs.readFileSync(filePath) const midi = new Midi(midiData) return midi }