From 400856c0a3cd31c190acedac8df6cb1216cef00f Mon Sep 17 00:00:00 2001 From: 3dtours Date: Sun, 26 Jul 2026 20:15:24 +0700 Subject: [PATCH] fix: add init guard, log selectablePresetList count - Add missing if (_initialized && _synthInstance) return to init() - soundBank is main-thread proxy, worklet has actual presets - Check selectablePresetList.length from soundBankManager (worklet state) - Log when presets are empty (SpessaSynth parser issue) --- app/static/js/services/soundfontPlayer.js | 36 +++++++---------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/app/static/js/services/soundfontPlayer.js b/app/static/js/services/soundfontPlayer.js index 4ce6f28..951e5eb 100644 --- a/app/static/js/services/soundfontPlayer.js +++ b/app/static/js/services/soundfontPlayer.js @@ -64,6 +64,7 @@ // PHASE 1: Init SpessaSynth // ════════════════════════════════════════════════ init: async function (audioContext) { + if (_initialized && _synthInstance) return; console.log("[SonicSF][DEBUG] PHASE1: init start"); if (!window.SpessaSynthClass || !window.__SpessaSynthCDN) { console.warn("[SonicSF][DEBUG] PHASE1: SpessaSynth CDN not available"); @@ -152,32 +153,15 @@ if (ok) { _currentSfId = sfId; const bankCount = _synthInstance.soundBankManager?.soundBankList?.length ?? 0; - console.log("[SonicSF][DEBUG] PHASE2d: addSoundBank SUCCESS. _currentSfId=" + _currentSfId + " total banks=" + bankCount); - // Try to enumerate presets from loaded bank - try { - const sb = _synthInstance.soundBankManager?.soundBankList?.[0]?.soundBank; - if (sb) { - const allKeys = Object.keys(sb); - console.log("[SonicSF][DEBUG] PHASE2d: soundBank keys=" + JSON.stringify(allKeys.slice(0, 20))); - console.log("[SonicSF][DEBUG] PHASE2d: soundBank.presets length=" + (sb.presets?.length ?? "undefined")); - console.log("[SonicSF][DEBUG] PHASE2d: soundBank.instruments length=" + (sb.instruments?.length ?? "undefined")); - console.log("[SonicSF][DEBUG] PHASE2d: soundBank.samples length=" + (sb.samples?.length ?? "undefined")); - console.log("[SonicSF][DEBUG] PHASE2d: soundBank._presetList length=" + (sb._presetList?.length ?? "undefined")); - if (sb.presets && sb.presets.length > 0) { - console.log("[SonicSF][DEBUG] PHASE2d: presets in loaded bank=" + sb.presets.length); - for (let i = 0; i < Math.min(sb.presets.length, 10); i++) { - const p = sb.presets[i]; - const pk = Object.keys(p).slice(0, 8); - console.log("[SonicSF][DEBUG] PHASE2d: preset[" + i + "] name=" + p.name + " keys=" + JSON.stringify(pk) + " bank=" + p.bankMSB + "/" + p.bankLSB + " prog=" + p.program + " drum=" + p.isGMGSDrum); - } - } else { - console.warn("[SonicSF][DEBUG] PHASE2d: soundBank.presets is EMPTY — parser didn't extract presets"); - } - } else { - console.warn("[SonicSF][DEBUG] PHASE2d: soundBankList[0] is EMPTY"); - } - } catch (e) { - console.warn("[SonicSF][DEBUG] PHASE2d: preset enumeration failed:", e); + const sb = _synthInstance.soundBankManager?.soundBankList?.[0]; + console.log("[SonicSF][DEBUG] PHASE2d: addSoundBank SUCCESS. _currentSfId=" + _currentSfId + " total banks=" + bankCount + " sb_exists=" + !!sb); + // soundBank is only stored on the worklet side (not main thread). + // Check selectablePresetList count (proxy for worklet state) + const spl = _synthInstance.soundBankManager?.selectablePresetList?.length ?? 0; + console.log("[SonicSF][DEBUG] PHASE2d: selectablePresetList.length=" + spl); + if (spl === 0) { + // The bank was registered but presets are empty - parser issue. + console.warn("[SonicSF][DEBUG] PHASE2d: presets EMPTY. SpessaSynth parser couldn't extract presets from SF2."); } return true; } else {