Skip to main content
Glama

get_controlchanges_by_index

Extract control change data from a specific track in a MIDI file by providing the file path and track index number.

Instructions

Get controlchanges from midi file by track index

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsoulate File Path to midi file
trackIndexYesTrack index number

Implementation Reference

  • Handler function that loads MIDI file using loadMidiFile, retrieves track using getTrackByIndex, extracts control changes with track.toJSON().controlChanges, and returns JSON-formatted text response.
    withErrorHandling(({ filePath, trackIndex }) => { const midi = loadMidiFile(filePath) const track = getTrackByIndex(midi, trackIndex) const controlchanges = track.toJSON().controlChanges return { content: [ { type: 'text', text: JSON.stringify(controlchanges), }, ] } })
  • src/main.ts:195-215 (registration)
    Registration of the get_controlchanges_by_index tool via server.tool, including name, description, input schema, and error-wrapped handler.
    server.tool( 'get_controlchanges_by_index', 'Get controlchanges 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 controlchanges = track.toJSON().controlChanges return { content: [ { type: 'text', text: JSON.stringify(controlchanges), }, ] } }) )
  • Zod input schema validating filePath (string) and trackIndex (number).
    { filePath: z.string().describe('Absoulate File Path to midi file'), trackIndex: z.number().describe('Track index number'), },
  • Helper function to retrieve a specific track from the MIDI object by index with bounds checking.
    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] }
  • Helper function to load a MIDI file from disk using @tonejs/midi and fs.readFileSync.
    export function loadMidiFile(filePath: string) { const midiData = fs.readFileSync(filePath) const midi = new Midi(midiData) return midi }

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