diff --git a/app/static/js/services/soundfontPlayer.js b/app/static/js/services/soundfontPlayer.js index 3404253..8faea4a 100644 --- a/app/static/js/services/soundfontPlayer.js +++ b/app/static/js/services/soundfontPlayer.js @@ -188,9 +188,22 @@ // ════════════════════════════════════════════════ selectInstrument: async function (channel, bank, program, sfId) { console.log("[SonicSF][DEBUG] PHASE3: selectInstrument ch=" + channel + " bank=" + bank + " prog=" + program + " sf=" + sfId + " _initialized=" + _initialized); + // Auto-init: create AudioContext + init SpessaSynth if not ready if (!_initialized || !_synthInstance) { - console.log("[SonicSF][DEBUG] PHASE3: engine not ready, returning"); - return; + console.log("[SonicSF][DEBUG] PHASE3: engine not ready, triggering init..."); + try { + const ctx = new (window.AudioContext || window.webkitAudioContext)(); + if (ctx.state === 'suspended') await ctx.resume(); + await this.init(ctx); + } catch (e) { + console.error("[SonicSF][DEBUG] PHASE3: auto-init failed:", e); + return; + } + if (!_initialized || !_synthInstance) { + console.warn("[SonicSF][DEBUG] PHASE3: engine still not ready after auto-init"); + return; + } + console.log("[SonicSF][DEBUG] PHASE3: auto-init complete"); } // Phase 2 first: ensure SoundFont is loaded if (sfId) {