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);