From 16e33b2e6ac20961dba8014660b1e9d1de02a791 Mon Sep 17 00:00:00 2001 From: 3dtours Date: Mon, 27 Jul 2026 16:00:11 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=5FactiveNotes=20l=C6=B0u=20array=20chan?= =?UTF-8?q?nel=20cho=20m=E1=BB=97i=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cùng MIDI pitch 60, track 1→ch0, track 2→ch1 cùng key '0:60' → single value bị overwrite, stopNote chỉ stop 1 channel. Fix: _activeNotes[key] = [ch1, ch2, ...], stopNote iterate all. --- app/static/js/services/soundfontPlayer.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/static/js/services/soundfontPlayer.js b/app/static/js/services/soundfontPlayer.js index d976037..3dbea9b 100644 --- a/app/static/js/services/soundfontPlayer.js +++ b/app/static/js/services/soundfontPlayer.js @@ -321,9 +321,15 @@ if (channel < 0 || channel > 15) return; if (_initialized && _fluidModule) { var key = channel + ':' + pitch; - var mappedCh = _activeNotes[key]; - console.log("[SonicSF] stopNote ch:", channel, "pitch:", pitch, "key:", key, "mappedCh:", mappedCh, "activeKeys:", Object.keys(_activeNotes)); - if (mappedCh === undefined) mappedCh = channel; + var mappedChs = _activeNotes[key]; + if (mappedChs === undefined) { + if (_activeNotes['_' + key]) mappedChs = _activeNotes['_' + key]; + } + if (mappedChs === undefined) mappedChs = [channel]; + if (!Array.isArray(mappedChs)) mappedChs = [mappedChs]; + for (var i = 0; i < mappedChs.length; i++) { + try { _fluidModule._fluid_synth_noteoff(_synthPtr, mappedChs[i], pitch); } catch (e) {} + } delete _activeNotes[key]; try { var r1 = _fluidModule._fluid_synth_noteoff(_synthPtr, mappedCh, pitch); @@ -397,13 +403,19 @@ try { console.log("[SonicSF] noteOn ch:", ch, "pitch:", midiPitch, "vel:", midiVel); _fluidModule._fluid_synth_noteon(_synthPtr, ch, midiPitch, midiVel); - _activeNotes[(_origChannel !== undefined ? _origChannel : 0) + ':' + midiPitch] = ch; var noteMapKey = (_origChannel !== undefined ? _origChannel : 0) + ':' + midiPitch; + if (!_activeNotes[noteMapKey]) _activeNotes[noteMapKey] = []; + if (_activeNotes[noteMapKey].indexOf(ch) === -1) _activeNotes[noteMapKey].push(ch); if (durationMs > 0 && durationMs < 60000) { scheduledNote.off = setTimeout(function () { try { _fluidModule._fluid_synth_noteoff(_synthPtr, ch, midiPitch); - delete _activeNotes[(_origChannel !== undefined ? _origChannel : 0) + ':' + midiPitch]; + var arr = _activeNotes[noteMapKey]; + if (arr) { + var idx = arr.indexOf(ch); + if (idx >= 0) arr.splice(idx, 1); + if (arr.length === 0) delete _activeNotes[noteMapKey]; + } } catch (e) {} }, durSec * 1000); }