fix: lazyInit in playNote, oscillator fallback 2s instead of 60s
This commit is contained in:
@@ -173,7 +173,6 @@
|
||||
stopNote: function (channel, pitch) {
|
||||
if (channel < 0 || channel > 15) return;
|
||||
if (_initialized && _synthInstance) {
|
||||
try { _synthInstance.noteOff(channel, pitch, 127); } catch (e) {}
|
||||
try { _synthInstance.noteOff(channel, pitch); } catch (e) {}
|
||||
try { _synthInstance.noteOff(channel, pitch, 0); } catch (e) {}
|
||||
try { _synthInstance.allNotesOff(channel); } catch (e) {}
|
||||
@@ -182,11 +181,24 @@
|
||||
},
|
||||
|
||||
playNote: function (note, velocity, durationMs, startTime, program, destinationNode, channel, synthEngine) {
|
||||
if (_initialized && _synthInstance) {
|
||||
this._playNoteSpessa(note, velocity, durationMs, startTime, program, channel, synthEngine);
|
||||
if (!_initialized || !_synthInstance) {
|
||||
// Try auto-init — create AudioContext + SpessaSynth
|
||||
this._lazyInit();
|
||||
// Use oscillator as fallback (short duration for keyboard preview)
|
||||
this._playNoteOsc(note, velocity, 2000, startTime, program, destinationNode, channel, synthEngine);
|
||||
return;
|
||||
}
|
||||
this._playNoteOsc(note, velocity, durationMs, startTime, program, destinationNode, channel, synthEngine);
|
||||
this._playNoteSpessa(note, velocity, durationMs, startTime, program, channel, synthEngine);
|
||||
},
|
||||
|
||||
_lazyInit: async function () {
|
||||
if (_initialized && _synthInstance) return;
|
||||
if (_initPromise) return;
|
||||
try {
|
||||
const ctx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
if (ctx.state === 'suspended') await ctx.resume();
|
||||
await this.init(ctx);
|
||||
} catch (e) {}
|
||||
},
|
||||
|
||||
_playNoteSpessa: function (note, velocity, durationMs, startTime, program, channel, synthEngine) {
|
||||
|
||||
Reference in New Issue
Block a user