fix: piano roll tab có thể play với soundfont

This commit is contained in:
2026-07-23 20:34:52 +07:00
parent a21266736c
commit dac661e6c6
8 changed files with 460 additions and 134 deletions
+22 -12
View File
@@ -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);