Skip to main content
Glama
BradA1878
by BradA1878

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
NameRequiredDescriptionDefault
patternYesArray of note events with timing

Implementation Reference

  • 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'],
      },
    },
  • 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(),
        })
      ),

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BradA1878/mcp-wave'

If you have feedback or need assistance with the MCP directory API, please join our Discord server