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 now = ctx.currentTime;
|
||||||
const delay = (typeof startTime === 'number' && startTime > now) ? (startTime - now) : 0;
|
const delay = (typeof startTime === 'number' && startTime > now) ? (startTime - now) : 0;
|
||||||
const noteId = { on: null, off: null };
|
const noteId = { on: null, off: null };
|
||||||
_scheduledNotes.push(noteId);
|
|
||||||
const doNote = () => {
|
const doNote = () => {
|
||||||
try {
|
try {
|
||||||
_synthInstance.noteOn(channel, midiPitch, midiVel);
|
_synthInstance.noteOn(channel, midiPitch, midiVel);
|
||||||
|
// Scheduled notes (timeline playback): auto noteOff after duration
|
||||||
|
// Immediate notes (MIDI keyboard): keep sounding until stopNote/stopAll
|
||||||
|
if (delay > 0) {
|
||||||
noteId.off = setTimeout(() => {
|
noteId.off = setTimeout(() => {
|
||||||
try { _synthInstance.noteOff(channel, midiPitch); } catch (e) {}
|
try { _synthInstance.noteOff(channel, midiPitch); } catch (e) {}
|
||||||
const idx = _scheduledNotes.indexOf(noteId);
|
|
||||||
if (idx >= 0) _scheduledNotes.splice(idx, 1);
|
|
||||||
}, durSec * 1000);
|
}, durSec * 1000);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("[SonicSF] SpessaSynth noteOn error:", e);
|
console.warn("[SonicSF] SpessaSynth noteOn error:", e);
|
||||||
this._playNoteOsc(note, velocity, durationMs, startTime, program, null, channel, synthEngine);
|
this._playNoteOsc(note, velocity, durationMs, startTime, program, null, channel, synthEngine);
|
||||||
@@ -210,10 +211,9 @@
|
|||||||
};
|
};
|
||||||
if (delay > 0) {
|
if (delay > 0) {
|
||||||
noteId.on = setTimeout(doNote, delay * 1000);
|
noteId.on = setTimeout(doNote, delay * 1000);
|
||||||
|
_scheduledNotes.push(noteId);
|
||||||
} else {
|
} else {
|
||||||
doNote();
|
doNote();
|
||||||
const idx = _scheduledNotes.indexOf(noteId);
|
|
||||||
if (idx >= 0) _scheduledNotes.splice(idx, 1);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user