analyze
Analyzes audio to extract musical patterns and structures for use in TidalCycles/Strudel music generation and live coding.
Instructions
Complete audio analysis
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server/EnhancedMCPServerFixed.ts:267-270 (registration)Registers the 'analyze' MCP tool in the tools list returned by getTools(), including name, description, and input schema (no parameters).name: 'analyze', description: 'Complete audio analysis', inputSchema: { type: 'object', properties: {} } },
- Primary MCP tool handler for 'analyze'. Validates initialization and delegates to StrudelController.analyzeAudio() which performs the actual analysis.case 'analyze': if (!this.isInitialized) { return 'Browser not initialized. Run init first.'; } return await this.controller.analyzeAudio();
- src/StrudelController.ts:269-273 (handler)Intermediate handler in StrudelController that forwards the analysis request to the AudioAnalyzer instance.async analyzeAudio(): Promise<AudioAnalysisResult> { if (!this._page) throw new Error('Browser not initialized. Run init tool first.'); return await this.analyzer.getAnalysis(this._page); }
- src/AudioAnalyzer.ts:179-219 (handler)Core analysis handler. Uses page.evaluate to call the injected JavaScript analyzer in the browser, which computes FFT-based features like average, peak, frequency bands, etc. Includes caching.async getAnalysis(page: Page): Promise<AudioAnalysisResult> { // Client-side caching with local fallback const now = Date.now(); if (this._analysisCache && (now - this._cacheTimestamp) < this.ANALYSIS_CACHE_TTL) { return this._analysisCache; } const result = await page.evaluate(() => { const analyzer = (window as any).strudelAudioAnalyzer; if (!analyzer) { return { connected: false, error: 'Analyzer not initialized. Audio context may not have started yet.', hint: 'Try playing a pattern first to initialize the audio context.' }; } if (!analyzer.isConnected) { return { connected: false, error: 'Analyzer not connected to audio output.', hint: 'Play a pattern to connect the analyzer to Strudel audio output.' }; } const analysis = analyzer.analyze(); // Add diagnostic info if no audio detected if (analysis.features && analysis.features.isSilent) { analysis.hint = 'Audio analyzer connected but no audio detected. Ensure pattern is playing.'; } return analysis; }); // Update cache this._analysisCache = result; this._cacheTimestamp = now; return result; }
- src/types/AudioAnalysis.ts:56-61 (schema)TypeScript interfaces defining the input/output structure for audio analysis results, used throughout the implementation chain.export interface AudioAnalysisResult { connected: boolean; timestamp?: number; features?: AudioAnalysisFeatures; error?: string; }