Skip to main content
Glama

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
NameRequiredDescriptionDefault
semitonesYesSemitones 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`;
  • 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; }); }

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/williamzujkowski/strudel-mcp-server'

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