Skip to main content
Glama

get_controlchanges_by_index

Extract control changes from a MIDI file by specifying the track index. Input the file path and track index to retrieve detailed control change data for analysis or manipulation.

Instructions

Get controlchanges 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

  • src/main.ts:195-215 (registration)
    Registers the 'get_controlchanges_by_index' tool. Includes input schema for filePath and trackIndex, and the inline handler that loads the MIDI file using loadMidiFile, gets the track using getTrackByIndex, extracts controlChanges from track.toJSON(), and returns as JSON text.
    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), }, ] } }) )
  • The core handler function for the tool, wrapped by withErrorHandling. Loads MIDI, retrieves track, gets controlChanges, and formats 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), }, ] } })
  • Zod schema defining the structure of ControlChange objects, which matches the format of the controlchanges returned by the tool's handler.
    export const ControlChangeInterfaceSchema = z.object({ number: z.number(), value: z.number(), }).and(z.union([ z.object({ time: z.number(), }), z.object({ ticks: z.number(), }) ]))
  • Helper function called in the handler to safely retrieve a track by index from the MIDI object.
    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 called in the handler to load and parse the MIDI file from the given file path.
    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