sc_play_pattern
Generate rhythmic patterns and musical sequences by defining note events with timing parameters to create melodies, beats, and phrases in SuperCollider.
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 that parses the pattern array, constructs a SuperCollider Routine to sequence synth plays with delays, and executes the code on the server.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 definition and registration in the tools list, 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 validation inside the handler matching the tool's input schema.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(), }) ),