Skip to main content
Glama

add_pitchbends_by_index

Add pitchbends to a MIDI file by specifying a track index and defining pitchbend values with precise timing or ticks for enhanced musical expression.

Instructions

Add pitchbends to midi file by track index

Input Schema

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

Implementation Reference

  • Core handler function that loads the MIDI file using loadMidiFile, retrieves the track using getTrackByIndex, iterates over pitchbends and calls track.addPitchBend for each, then saves the file with saveMidiFile.
    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 input schema for the 'add_pitchbends_by_index' tool parameters.
    { filePath: z.string().describe('Absoulate File Path to midi file'), trackIndex: z.number().describe('Track index number'), pitchbends: z.array(PitchBendInterfaceSchema) },
  • Zod schema defining the structure of a single pitchbend object: value and either time or ticks.
    export const PitchBendInterfaceSchema = z.object({ value: z.number(), }).and(z.union([ z.object({ time: z.number(), }), z.object({ ticks: z.number(), }) ]))
  • src/main.ts:279-308 (registration)
    Registration of the 'add_pitchbends_by_index' tool using server.tool, including name, description, input schema, and handler.
    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', }, ] } }) )
  • Helper function to safely retrieve a track by index from the MIDI object, 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