transpose
Transpose musical notes by a specified number of semitones to adjust pitch in music patterns for Strudel.cc live coding.
Instructions
Transpose notes by semitones
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| semitones | Yes | Semitones to transpose |
Implementation Reference
- The main handler for the 'transpose' tool within the executeTool switch statement. Validates input, retrieves the current pattern, transposes it using the transposePattern helper, writes the result back, and returns a confirmation message.case 'transpose': // Semitones can be positive or negative, just validate it's a number if (typeof args.semitones !== 'number' || !Number.isInteger(args.semitones)) { throw new Error('Semitones must be an integer'); } const toTranspose = await this.getCurrentPatternSafe(); const transposed = this.transposePattern(toTranspose, args.semitones); await this.writePatternSafe(transposed); return `Transposed ${args.semitones} semitones`;
- src/server/EnhancedMCPServerFixed.ts:155-165 (registration)Registration of the 'transpose' tool in the getTools() method, including name, description, and input schema definition.{ name: 'transpose', description: 'Transpose notes by semitones', inputSchema: { type: 'object', properties: { semitones: { type: 'number', description: 'Semitones to transpose' } }, required: ['semitones'] } },
- The core helper function that implements the transposition logic by parsing note names and octaves in the pattern string using regex and shifting them by the specified semitones, handling octave wrapping.private transposePattern(pattern: string, semitones: number): string { // Simple transpose implementation - would need more sophisticated parsing return pattern.replace(/([a-g][#b]?)(\d)/gi, (match, note, octave) => { const noteMap: Record<string, number> = { 'c': 0, 'c#': 1, 'd': 2, 'd#': 3, 'e': 4, 'f': 5, 'f#': 6, 'g': 7, 'g#': 8, 'a': 9, 'a#': 10, 'b': 11 }; const currentNote = note.toLowerCase(); const noteValue = noteMap[currentNote] || 0; const newNoteValue = (noteValue + semitones + 12) % 12; const noteNames = ['c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#', 'a', 'a#', 'b']; const newOctave = parseInt(octave) + Math.floor((noteValue + semitones) / 12); return noteNames[newNoteValue] + newOctave; }); }