sc_play_pattern
Play rhythmic patterns or note sequences to create melodies, beats, and musical phrases using SuperCollider audio synthesis.
Instructions
Play a rhythmic pattern or sequence of notes. Useful for creating melodies, beats, or musical phrases.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | Array of note events with timing |
Implementation Reference
- src/index.ts:391-437 (handler)Handler for the 'sc_play_pattern' tool. Validates input pattern array using Zod, generates SuperCollider Routine code to sequence synth plays with delays, executes via scServer, returns confirmation.case 'sc_play_pattern': { const schema = z.object({ pattern: z.array( z.object({ synth: z.string(), freq: z.number().optional(), duration: z.number().optional(), delay: z.number().optional(), amp: z.number().optional(), }) ), }); const { pattern } = schema.parse(args); if (!scServer.getBooted() || !synthDefsLoaded) { return { content: [{ type: 'text', text: 'Error: SuperCollider server is not running. Call sc_boot first.' }], isError: true, }; } // Build a Routine to play the pattern const events = pattern.map((event, i) => { const params = Object.entries(event) .filter(([key]) => key !== 'synth' && key !== 'delay') .map(([key, value]) => `\\${key}, ${value}`) .join(', '); const delay = event.delay || 0; return `${delay}.wait; Synth(\\${event.synth}, [${params}]);`; }); const code = ` Routine({ ${events.join('\n ')} }).play; `; await scServer.executeCode(code); return { content: [ { type: 'text', text: `Playing pattern with ${pattern.length} events`, }, ], }; }
- src/index.ts:143-166 (registration)Tool registration in the tools array, including name, description, and input schema for the pattern array of synth events.{ name: 'sc_play_pattern', description: 'Play a rhythmic pattern or sequence of notes. Useful for creating melodies, beats, or musical phrases.', inputSchema: { type: 'object', properties: { pattern: { type: 'array', description: 'Array of note events with timing', items: { type: 'object', properties: { synth: { type: 'string' }, freq: { type: 'number' }, duration: { type: 'number' }, delay: { type: 'number' }, amp: { type: 'number' }, }, }, }, }, required: ['pattern'], }, },
- src/index.ts:392-401 (schema)Zod schema used internally in the handler for input validation, matching the tool schema but marking fields optional.const schema = z.object({ pattern: z.array( z.object({ synth: z.string(), freq: z.number().optional(), duration: z.number().optional(), delay: z.number().optional(), amp: z.number().optional(), }) ),