fix: piano roll tab có thể play với soundfont
This commit is contained in:
@@ -2,20 +2,30 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// Web Audio API fallback synth
|
||||
let audioCtx = null;
|
||||
let gainNode = null;
|
||||
const activeOscillators = {};
|
||||
|
||||
function getCtx() {
|
||||
if (!audioCtx) {
|
||||
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
gainNode = audioCtx.createGain();
|
||||
gainNode.gain.value = 0.3;
|
||||
gainNode.connect(audioCtx.destination);
|
||||
// Use the shared AudioContext from the main app (lazy init)
|
||||
let __gainNode = null;
|
||||
const getCtx = () => {
|
||||
if (typeof getAudioContext === 'function') {
|
||||
const ctx = getAudioContext();
|
||||
if (!__gainNode) {
|
||||
__gainNode = ctx.createGain();
|
||||
__gainNode.gain.value = 0.3;
|
||||
__gainNode.connect(ctx.destination);
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
return audioCtx;
|
||||
}
|
||||
if (!window.__sharedAudioCtx) {
|
||||
window.__sharedAudioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
}
|
||||
if (!__gainNode) {
|
||||
__gainNode = window.__sharedAudioCtx.createGain();
|
||||
__gainNode.gain.value = 0.3;
|
||||
__gainNode.connect(window.__sharedAudioCtx.destination);
|
||||
}
|
||||
return window.__sharedAudioCtx;
|
||||
};
|
||||
|
||||
const SonicSF = {
|
||||
loadedFonts: {},
|
||||
@@ -131,7 +141,7 @@
|
||||
|
||||
osc.connect(noteGain);
|
||||
|
||||
const dest = destinationNode || gainNode || ctx.destination;
|
||||
const dest = destinationNode || __gainNode || ctx.destination;
|
||||
noteGain.connect(dest);
|
||||
|
||||
osc.start(startAt);
|
||||
|
||||
Reference in New Issue
Block a user