get_pitchbends_by_index
Extract pitch bend data from a MIDI file using a specific track index to analyze or modify musical expression in the selected track.
Instructions
Get pitchbends 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:180-192 (handler)The inline handler function for the get_pitchbends_by_index tool. It loads the MIDI file, retrieves the specified track using getTrackByIndex, extracts the pitchBends from the track's JSON representation, and returns them serialized as JSON in a text content block.withErrorHandling(({ filePath, trackIndex }) => { const midi = loadMidiFile(filePath) const track = getTrackByIndex(midi, trackIndex) const pitchbends = track.toJSON().pitchBends return { content: [ { type: 'text', text: JSON.stringify(pitchbends), }, ] } })
- src/main.ts:176-179 (schema)Input parameter schema defined using Zod, specifying filePath (string) and trackIndex (number).{ filePath: z.string().describe('Absoulate File Path to midi file'), trackIndex: z.number().describe('Track index number'), },
- src/main.ts:173-193 (registration)The server.tool call that registers the get_pitchbends_by_index tool with the MCP server, including name, description, input schema, and handler.server.tool( 'get_pitchbends_by_index', 'Get pitchbends 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 pitchbends = track.toJSON().pitchBends return { content: [ { type: 'text', text: JSON.stringify(pitchbends), }, ] } }) )
- src/utils/obj-utils.ts:1-6 (helper)Helper function used by the handler to safely retrieve a track from the MIDI object by its index, throwing an error if out of bounds.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] }