Skip to main content
Glama

add_controlchanges_by_index

Add control change messages to a specific track in a MIDI file using track index, enabling precise automation and parameter adjustments for MIDI editing.

Instructions

Add controlchanges to midi file by track index

Input Schema

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

Implementation Reference

  • Handler function that loads the MIDI file, retrieves the specified track, adds each control change using track.addCC(), saves the modified MIDI file, and returns a success message.
    withErrorHandling(({ filePath, trackIndex, controlchanges }) => { // 读取文件 const midi = loadMidiFile(filePath) // 查找轨道 const track = getTrackByIndex(midi, trackIndex) // 添加控制器变化 controlchanges.forEach(controlchange => { track.addCC(controlchange) }) // 保存文件 saveMidiFile(midi, filePath) return { content: [ { type: 'text', text: 'add controlchange success', }, ] } })
  • Zod schema defining the structure of a control change object: {number, value} unioned with either {time} or {ticks}, used for validating tool input parameters.
    export const ControlChangeInterfaceSchema = z.object({ number: z.number(), value: z.number(), }).and(z.union([ z.object({ time: z.number(), }), z.object({ ticks: z.number(), }) ]))
  • src/main.ts:248-277 (registration)
    Registers the MCP tool 'add_controlchanges_by_index' with the server, including input schema validation using Zod and the error-handling wrapper around the handler.
    server.tool( 'add_controlchanges_by_index', 'Add controlchanges to midi file by track index', { filePath: z.string().describe('Absoulate File Path to midi file'), trackIndex: z.number().describe('Track index number'), controlchanges: z.array(ControlChangeInterfaceSchema) }, withErrorHandling(({ filePath, trackIndex, controlchanges }) => { // 读取文件 const midi = loadMidiFile(filePath) // 查找轨道 const track = getTrackByIndex(midi, trackIndex) // 添加控制器变化 controlchanges.forEach(controlchange => { track.addCC(controlchange) }) // 保存文件 saveMidiFile(midi, filePath) return { content: [ { type: 'text', text: 'add controlchange success', }, ] } }) )
  • Utility function to safely retrieve a MIDI track by index, throwing an error if the index is out of bounds; used in the tool handler.
    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