generate_pattern
Create music patterns for TidalCycles/Strudel by specifying style, key, and tempo, with optional auto-play functionality.
Instructions
Generate complete pattern from style with optional auto-play
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| style | Yes | Music style (techno/house/dnb/ambient/etc) | |
| key | No | Musical key | |
| bpm | No | Tempo in BPM | |
| auto_play | No | Start playback immediately (default: false) |
Implementation Reference
- Defines the input schema and metadata for the 'generate_pattern' MCP tool.name: 'generate_pattern', description: 'Generate complete pattern from style with optional auto-play', inputSchema: { type: 'object', properties: { style: { type: 'string', description: 'Music style (techno/house/dnb/ambient/etc)' }, key: { type: 'string', description: 'Musical key' }, bpm: { type: 'number', description: 'Tempo in BPM' }, auto_play: { type: 'boolean', description: 'Start playback immediately (default: false)' } }, required: ['style'] }
- Executes the generate_pattern tool: validates parameters, delegates generation to PatternGenerator, writes pattern to editor, supports auto-play.case 'generate_pattern': InputValidator.validateStringLength(args.style, 'style', 100, false); if (args.key) { InputValidator.validateRootNote(args.key); } if (args.bpm !== undefined) { InputValidator.validateBPM(args.bpm); } const generated = this.generator.generateCompletePattern( args.style, args.key || 'C', args.bpm || 120 ); await this.writePatternSafe(generated); // Auto-play if requested - Issue #38 if (args.auto_play && this.isInitialized) { await this.controller.play(); return `Generated ${args.style} pattern. Playing.`; } return `Generated ${args.style} pattern`;
- Generates the full Strudel pattern code by composing drums, bassline, chords, and melody tailored to the music style, key, and BPM.generateCompletePattern(style: string, key: string = 'C', bpm: number = 120): string { const drums = this.generateDrumPattern(style, 0.7); const bass = this.generateBassline(key, style); const scale = this.theory.generateScale(key, style === 'jazz' ? 'dorian' : 'minor'); const melody = this.generateMelody(scale); const chordStyle = style === 'jazz' ? 'jazz' : style === 'house' ? 'pop' : style === 'techno' ? 'edm' : 'pop'; const progression = this.theory.generateChordProgression(key, chordStyle as any); const chords = this.generateChords(progression, style === 'ambient' ? 'pad' : 'stab'); return `// ${style} pattern in ${key} at ${bpm} BPM setcpm(${bpm}) stack( // Drums ${drums}, // Bass ${bass}, // Chords ${chords}.gain(0.6), // Melody ${melody}.struct("~ 1 ~ 1 1 ~ 1 ~").delay(0.25).room(0.3).gain(0.5) ).gain(0.8)`; }
- src/server/EnhancedMCPServerFixed.ts:571-573 (registration)Registers all tools including generate_pattern via ListToolsRequestSchema handler that returns the tools list from getTools().this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: this.getTools() }));