fix: _activeNotes lưu array channel cho mỗi key
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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user