From f96064cbab3b7eea3b15a78a620eb1bbb9a516c8 Mon Sep 17 00:00:00 2001 From: 3dtours Date: Sun, 26 Jul 2026 20:52:48 +0700 Subject: [PATCH] fix: unload old SoundFont before loading new one - Add _currentSfId tracking - loadSoundFont calls deleteSoundBank(oldId) before addSoundBank(newId) - Skip reload if same sfId requested - Prevents bank accumulation in SpessaSynth --- app/static/js/services/soundfontPlayer.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/static/js/services/soundfontPlayer.js b/app/static/js/services/soundfontPlayer.js index 07d181e..8df6d9e 100644 --- a/app/static/js/services/soundfontPlayer.js +++ b/app/static/js/services/soundfontPlayer.js @@ -34,6 +34,7 @@ let _synthInstance = null; let _initialized = false; let _initPromise = null; + let _currentSfId = null; const SonicSF = { loadedFonts: {}, @@ -60,7 +61,12 @@ loadSoundFont: async function (sfId) { if (!_initialized || !_synthInstance) return false; + if (_currentSfId === sfId) return true; try { + // Unload previous SoundFont + if (_currentSfId) { + try { _synthInstance.soundBankManager.deleteSoundBank(_currentSfId); } catch (e) {} + } const cache = window.SonicSFStorage; let buf = cache ? await cache.getBuffer(sfId) : null; if (!buf) { @@ -72,6 +78,7 @@ } await _synthInstance.soundBankManager.addSoundBank(buf.slice(0), sfId); await _synthInstance.isReady; + _currentSfId = sfId; return true; } catch (e) { console.warn("[SonicSF] loadSoundFont failed:", e);