fix: selectInstrument auto-inits SpessaSynth if not ready
Root cause: selectInstrument called before getAudioContext triggers init. _initialized=false → selectInstrument returns immediately → no sound bank. Fix: selectInstrument creates AudioContext + calls init() if not ready, waits for completion before proceeding with bank/program routing.
This commit is contained in:
@@ -188,9 +188,22 @@
|
|||||||
// ════════════════════════════════════════════════
|
// ════════════════════════════════════════════════
|
||||||
selectInstrument: async function (channel, bank, program, sfId) {
|
selectInstrument: async function (channel, bank, program, sfId) {
|
||||||
console.log("[SonicSF][DEBUG] PHASE3: selectInstrument ch=" + channel + " bank=" + bank + " prog=" + program + " sf=" + sfId + " _initialized=" + _initialized);
|
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) {
|
if (!_initialized || !_synthInstance) {
|
||||||
console.log("[SonicSF][DEBUG] PHASE3: engine not ready, returning");
|
console.log("[SonicSF][DEBUG] PHASE3: engine not ready, triggering init...");
|
||||||
return;
|
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
|
// Phase 2 first: ensure SoundFont is loaded
|
||||||
if (sfId) {
|
if (sfId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user