play_note
Generate musical notes in Sonic Pi by specifying MIDI note numbers, synth types, duration, and filter parameters to create custom sounds.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| note | Yes | MIDI note number (0-127) | |
| synth | No | Synth to use (e.g. :saw, :beep, :prophet) | |
| sustain | No | Note duration in seconds | |
| cutoff | No | Filter cutoff frequency |
Implementation Reference
- src/server.ts:51-68 (handler)Handler function that implements the core logic of the 'play_note' tool by generating Sonic Pi code and sending it via OSC.async ({ note, synth = ":beep", sustain = 1, cutoff = 100 }: PlayNoteParams) => { try { const code = ` use_synth ${synth} play ${note}, sustain: ${sustain}, cutoff: ${cutoff} `; this.oscClient.send('/run-code', code); return { content: [{ type: "text", text: `Playing note ${note} with synth ${synth} (sustain: ${sustain}s, cutoff: ${cutoff})` }] }; } catch (error) { console.error('Error in play_note:', error); throw new Error('Failed to play note'); } }
- src/server.ts:45-50 (schema)Zod schema for input validation of the 'play_note' tool parameters.{ note: z.number().min(0).max(127).describe("MIDI note number (0-127)"), synth: z.string().optional().describe("Synth to use (e.g. :saw, :beep, :prophet)"), sustain: z.number().optional().describe("Note duration in seconds"), cutoff: z.number().optional().describe("Filter cutoff frequency") },
- src/server.ts:44-44 (registration)The string identifier used to register the 'play_note' tool in the MCP server."play_note",
- src/server.ts:9-14 (helper)TypeScript interface providing type safety for the 'play_note' handler parameters.interface PlayNoteParams { note: number; synth?: string; sustain?: number; cutoff?: number; }