Skip to main content
Glama

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

NameRequiredDescriptionDefault
filePathYesAbsoulate File Path to midi file
trackIndexYesTrack index number

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "filePath": { "description": "Absoulate File Path to midi file", "type": "string" }, "trackIndex": { "description": "Track index number", "type": "number" } }, "required": [ "filePath", "trackIndex" ], "type": "object" }

Implementation Reference

  • 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), }, ] } })
  • 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), }, ] } }) )
  • 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] }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xiaolaa2/midi-file-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server