From ce7d23c35191f010a857fbf0552b6cd9b8aea14e Mon Sep 17 00:00:00 2001 From: 3dtours Date: Mon, 27 Jul 2026 15:54:06 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=5ForigChannel=20tr=C3=A1nh=20channel=20?= =?UTF-8?q?b=E1=BB=8B=20ghi=20=C4=91=C3=A8=20b=E1=BB=9Fi=20mappedCh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Line 378: 'if (channel===undefined) channel=ch' gán channel = FluidSynth channel (2), sau đó _activeNotes key dùng channel (2) thay vì MIDI channel (0). stopNote lookup bằng 0 → key mismatch. Fix: _origChannel = channel ngay đầu hàm, dùng _origChannel cho key. --- app/static/js/services/soundfontPlayer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/static/js/services/soundfontPlayer.js b/app/static/js/services/soundfontPlayer.js index bdaf5a4..281b7b3 100644 --- a/app/static/js/services/soundfontPlayer.js +++ b/app/static/js/services/soundfontPlayer.js @@ -356,6 +356,7 @@ var midiVel = Math.min(127, Math.max(1, Math.floor( typeof velocity === 'number' ? (velocity > 1 ? velocity : velocity * 127) : 100 ))); + var _origChannel = channel; var ch = channel; var usedBank = 0, usedProg = 0; if (synthEngine) { @@ -375,7 +376,6 @@ try { _fluidModule._fluid_synth_program_change(_synthPtr, ch, usedProg); } catch (e) {} - if (channel === undefined) channel = ch; } else if (program !== undefined) { usedProg = program; if (ch === undefined) ch = 0; @@ -394,13 +394,13 @@ try { console.log("[SonicSF] noteOn ch:", ch, "pitch:", midiPitch, "vel:", midiVel); _fluidModule._fluid_synth_noteon(_synthPtr, ch, midiPitch, midiVel); - _activeNotes[(channel !== undefined ? channel : 0) + ':' + midiPitch] = ch; - var noteMapKey = (channel !== undefined ? channel : 0) + ':' + midiPitch; + _activeNotes[(_origChannel !== undefined ? _origChannel : 0) + ':' + midiPitch] = ch; + var noteMapKey = (_origChannel !== undefined ? _origChannel : 0) + ':' + midiPitch; if (durationMs > 0 && durationMs < 60000) { scheduledNote.off = setTimeout(function () { try { _fluidModule._fluid_synth_noteoff(_synthPtr, ch, midiPitch); - delete _activeNotes[noteMapKey]; + delete _activeNotes[(_origChannel !== undefined ? _origChannel : 0) + ':' + midiPitch]; } catch (e) {} }, durSec * 1000); }