generate_polyrhythm
Create complex polyrhythms by combining multiple sound patterns with different rhythmic cycles for experimental music composition.
Instructions
Generate polyrhythm
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sounds | Yes | Sounds to use | |
| patterns | Yes | Pattern numbers |
Implementation Reference
- src/services/PatternGenerator.ts:246-256 (handler)Core handler function that implements generate_polyrhythm by stacking individual Euclidean rhythms (using Strudel's .euclid) for each provided sound and pattern length over 16 steps.generatePolyrhythm(sounds: string[], patterns: number[]): string { if (sounds.length !== patterns.length) { throw new Error('Number of sounds must match number of patterns'); } const rhythms = sounds.map((sound, i) => { return `s("${sound}").euclid(${patterns[i]}, 16)`; }); return `stack(\n ${rhythms.join(',\n ')}\n)`; }
- src/server/EnhancedMCPServerFixed.ts:482-492 (registration)MCP tool registration in getTools(), including name, description, and input schema defining sounds (array of strings) and patterns (array of numbers).name: 'generate_polyrhythm', description: 'Generate polyrhythm', inputSchema: { type: 'object', properties: { sounds: { type: 'array', items: { type: 'string' }, description: 'Sounds to use' }, patterns: { type: 'array', items: { type: 'number' }, description: 'Pattern numbers' } }, required: ['sounds', 'patterns'] } },
- Input schema for validating tool arguments: arrays of sounds and patterns.inputSchema: { type: 'object', properties: { sounds: { type: 'array', items: { type: 'string' }, description: 'Sounds to use' }, patterns: { type: 'array', items: { type: 'number' }, description: 'Pattern numbers' } }, required: ['sounds', 'patterns'] }
- Server-side dispatch handler: validates inputs, calls PatternGenerator.generatePolyrhythm, appends to current pattern, writes to editor, and returns confirmation.case 'generate_polyrhythm': args.sounds.forEach((sound: string) => { InputValidator.validateStringLength(sound, 'sound', 100, false); }); args.patterns.forEach((pattern: number) => { InputValidator.validatePositiveInteger(pattern, 'pattern'); }); const poly = this.generator.generatePolyrhythm(args.sounds, args.patterns); const currentPoly = await this.getCurrentPatternSafe(); const newPolyPattern = currentPoly ? currentPoly + '\n' + poly : poly; await this.writePatternSafe(newPolyPattern); return `Generated polyrhythm`;