compose_rhythm
Create complex rhythms by combining lines, loops, and vibes with weighted components and tempo control for creative workflows.
Instructions
Compose a complex rhythm from lines, loops, and vibes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name for the composed rhythm | |
| components | Yes | Components and their weights | |
| tempo | No | Base tempo in BPM |
Implementation Reference
- index.js:746-810 (handler)The handler function that executes the compose_rhythm tool, validating inputs, generating composite rhythm, storing it, and returning visualization.composeRhythm(args) { const { name, components, tempo = 120 } = args; if (!name || name.trim().length === 0) { return { content: [ { type: 'text', text: `❌ Rhythm name is required. Please provide a name for the composed rhythm.`, }, ], }; } if (!components || components.length === 0) { return { content: [ { type: 'text', text: `❌ No components provided for rhythm composition. Please specify at least one component with element and weight.`, }, ], }; } // Validate components const validComponents = components.filter(c => c.element && typeof c.weight === 'number'); const invalidComponents = components.filter(c => !c.element || typeof c.weight !== 'number'); if (validComponents.length === 0) { return { content: [ { type: 'text', text: `❌ No valid components found. Each component must have an 'element' (string) and 'weight' (number).\n\nInvalid components: ${invalidComponents.length}`, }, ], }; } const composition = { name, components: validComponents, tempo, created_at: new Date().toISOString(), }; const rhythmPattern = this.generateCompositeRhythm(validComponents); this.rhythms.set(`composed_${name}`, rhythmPattern); let resultText = `🎼 Rhythm composed: "${name}"\n\nTempo: ${tempo} BPM\nComponents:\n${validComponents.map(c => ` • ${c.element}: ${(c.weight * 100).toFixed(0)}%`).join('\n')}\n\n${this.visualizeCompositeRhythm(validComponents)}\n\nComposite rhythm created and available for use.`; if (invalidComponents.length > 0) { resultText += `\n\n⚠️ Warning: ${invalidComponents.length} invalid components were skipped.`; } return { content: [ { type: 'text', text: resultText, }, ], }; }
- index.js:246-274 (schema)The tool schema definition including name, description, and input schema for validation.{ name: 'compose_rhythm', description: 'Compose a complex rhythm from lines, loops, and vibes', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name for the composed rhythm', }, components: { type: 'array', items: { type: 'object', properties: { element: { type: 'string' }, weight: { type: 'number' }, }, }, description: 'Components and their weights', }, tempo: { type: 'number', description: 'Base tempo in BPM', }, }, required: ['name', 'components'], }, },
- index.js:347-348 (registration)The switch case registration that routes calls to the composeRhythm handler.case 'compose_rhythm': return this.composeRhythm(args);
- index.js:1017-1031 (helper)Helper function called by the handler to generate the composite rhythm generator.generateCompositeRhythm(components) { const composite = { pattern: [], index: 0 }; components.forEach(comp => { const weight = comp.weight || 0.5; composite.pattern.push(weight); }); return { next() { const value = composite.pattern[composite.index]; composite.index = (composite.index + 1) % composite.pattern.length; return value; }, }; }
- index.js:1033-1038 (helper)Helper function to visualize the composite rhythm weights as a bar chart.visualizeCompositeRhythm(components) { return components.map(c => { const bars = Math.ceil(c.weight * 10); return '█'.repeat(bars) + '░'.repeat(10 - bars); }).join(' | '); }