fix: immediate notes (MIDI keyboard) have NO auto noteOff timeout
- Scheduled notes (delay>0, timeline playback): still set auto noteOff - Immediate notes (delay=0, MIDI keyboard): keep sounding until stopNote or stopAll - Remove _scheduledNotes push/pop for immediate notes (no timeout to track)
This commit is contained in:
@@ -194,15 +194,16 @@
|
||||
const now = ctx.currentTime;
|
||||
const delay = (typeof startTime === 'number' && startTime > now) ? (startTime - now) : 0;
|
||||
const noteId = { on: null, off: null };
|
||||
_scheduledNotes.push(noteId);
|
||||
const doNote = () => {
|
||||
try {
|
||||
_synthInstance.noteOn(channel, midiPitch, midiVel);
|
||||
noteId.off = setTimeout(() => {
|
||||
try { _synthInstance.noteOff(channel, midiPitch); } catch (e) {}
|
||||
const idx = _scheduledNotes.indexOf(noteId);
|
||||
if (idx >= 0) _scheduledNotes.splice(idx, 1);
|
||||
}, durSec * 1000);
|
||||
// Scheduled notes (timeline playback): auto noteOff after duration
|
||||
// Immediate notes (MIDI keyboard): keep sounding until stopNote/stopAll
|
||||
if (delay > 0) {
|
||||
noteId.off = setTimeout(() => {
|
||||
try { _synthInstance.noteOff(channel, midiPitch); } catch (e) {}
|
||||
}, durSec * 1000);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("[SonicSF] SpessaSynth noteOn error:", e);
|
||||
this._playNoteOsc(note, velocity, durationMs, startTime, program, null, channel, synthEngine);
|
||||
@@ -210,10 +211,9 @@
|
||||
};
|
||||
if (delay > 0) {
|
||||
noteId.on = setTimeout(doNote, delay * 1000);
|
||||
_scheduledNotes.push(noteId);
|
||||
} else {
|
||||
doNote();
|
||||
const idx = _scheduledNotes.indexOf(noteId);
|
||||
if (idx >= 0) _scheduledNotes.splice(idx, 1);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user