add_track
Create a new track in a MIDI file and retrieve track details. Specify the absolute file path to integrate additional tracks into your MIDI composition.
Instructions
Add a new track to midi file and return the new track info
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absoulate File Path to midi file |
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"
}
},
"required": [
"filePath"
],
"type": "object"
}
Implementation Reference
- src/main.ts:310-333 (registration)Registration of the 'add_track' tool, including input schema (filePath: string), description, and the handler function that loads the MIDI file, adds a new track, saves the file, and returns the new track as JSON.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), }, ] } }) )
- src/main.ts:316-332 (handler)The handler function for 'add_track' tool: loads MIDI file using loadMidiFile, adds a new track with midi.addTrack(), saves with saveMidiFile, and returns the new track JSON.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: requires absolute filePath to the MIDI file.{ filePath: z.string().describe('Absoulate File Path to midi file'), },