add_track
Add a new track to a MIDI file to expand musical arrangements and organize different instrument parts.
Instructions
Add a new track to midi file and return the new track info
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absoulate File Path to midi file |
Implementation Reference
- src/main.ts:316-332 (handler)Handler function for the 'add_track' tool: loads the MIDI file, adds a new track using midi.addTrack(), saves the file, and returns the new track info as JSON string.withErrorHandling(({ filePath }) => { // 读取文件 const midi = loadMidiFile(filePath) // 添加新轨道 const newTrack = midi.addTrack() // 保存文件 saveMidiFile(midi, filePath) return { content: [ { type: 'text', text: JSON.stringify(newTrack), }, ] } })
- src/main.ts:313-315 (schema)Input schema for 'add_track' tool, requiring absolute file path to the MIDI file.{ filePath: z.string().describe('Absoulate File Path to midi file'), },
- src/main.ts:310-333 (registration)Registration of the 'add_track' tool with server.tool, including description, input schema, and handler.server.tool( 'add_track', 'Add a new track to midi file and return the new track info', { filePath: z.string().describe('Absoulate File Path to midi file'), }, withErrorHandling(({ filePath }) => { // 读取文件 const midi = loadMidiFile(filePath) // 添加新轨道 const newTrack = midi.addTrack() // 保存文件 saveMidiFile(midi, filePath) return { content: [ { type: 'text', text: JSON.stringify(newTrack), }, ] } }) )