Skip to main content
Glama

add_pitchbends_by_index

Add pitch bend effects to a specific track in a MIDI file using track index, pitch values, and timing parameters for musical expression.

Instructions

Add pitchbends to midi file by track index

Input Schema

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

Implementation Reference

  • The handler function that loads the MIDI file using loadMidiFile, retrieves the track by index using getTrackByIndex, iterates over the provided pitchbends and adds each one to the track using track.addPitchBend(pitchbend), then saves the modified MIDI file.
    withErrorHandling(({ filePath, trackIndex, pitchbends }) => { // 读取文件 const midi = loadMidiFile(filePath) // 查找轨道 const track = getTrackByIndex(midi, trackIndex) // 添加弯音 pitchbends.forEach(pitchbend => { track.addPitchBend(pitchbend) }) // 保存文件 saveMidiFile(midi, filePath) return { content: [ { type: 'text', text: 'add pitchbend success', }, ] } })
  • src/main.ts:279-308 (registration)
    Registers the 'add_pitchbends_by_index' tool with the MCP server, including description, input schema, and the handler function.
    server.tool( 'add_pitchbends_by_index', 'Add pitchbends to midi file by track index', { filePath: z.string().describe('Absoulate File Path to midi file'), trackIndex: z.number().describe('Track index number'), pitchbends: z.array(PitchBendInterfaceSchema) }, withErrorHandling(({ filePath, trackIndex, pitchbends }) => { // 读取文件 const midi = loadMidiFile(filePath) // 查找轨道 const track = getTrackByIndex(midi, trackIndex) // 添加弯音 pitchbends.forEach(pitchbend => { track.addPitchBend(pitchbend) }) // 保存文件 saveMidiFile(midi, filePath) return { content: [ { type: 'text', text: 'add pitchbend success', }, ] } }) )
  • Zod schema defining the structure of a single pitchbend event: {value: number, time?: number | ticks?: number}.
    export const PitchBendInterfaceSchema = z.object({ value: z.number(), }).and(z.union([ z.object({ time: z.number(), }), z.object({ ticks: z.number(), }) ]))
  • Helper function to safely retrieve a MIDI track by index, throwing an error if out of range. Used in the 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