mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-27 13:38:40 +00:00
Merge remote-tracking branch 'origin/main' into migrate-tutorial-fanchor
This commit is contained in:
commit
33322be948
@ -83,42 +83,49 @@ export const getAudioContext = () => {
|
|||||||
if (!audioContext) {
|
if (!audioContext) {
|
||||||
return setDefaultAudioContext();
|
return setDefaultAudioContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
return audioContext;
|
return audioContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
let workletsLoading;
|
let workletsLoading;
|
||||||
|
|
||||||
function loadWorklets() {
|
function loadWorklets() {
|
||||||
if (workletsLoading) {
|
if (!workletsLoading) {
|
||||||
return workletsLoading;
|
workletsLoading = getAudioContext().audioWorklet.addModule(workletsUrl);
|
||||||
}
|
}
|
||||||
workletsLoading = getAudioContext().audioWorklet.addModule(workletsUrl);
|
|
||||||
return workletsLoading;
|
return workletsLoading;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function should be called on first user interaction (to avoid console warning)
|
// this function should be called on first user interaction (to avoid console warning)
|
||||||
export async function initAudio(options = {}) {
|
export async function initAudio(options = {}) {
|
||||||
const { disableWorklets = false } = options;
|
const { disableWorklets = false } = options;
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window === 'undefined') {
|
||||||
await getAudioContext().resume();
|
return;
|
||||||
if (!disableWorklets) {
|
|
||||||
await loadWorklets().catch((err) => {
|
|
||||||
console.warn('could not load AudioWorklet effects coarse, crush and shape', err);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log('disableWorklets: AudioWorklet effects coarse, crush and shape are skipped!');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
await getAudioContext().resume();
|
||||||
|
if (disableWorklets) {
|
||||||
|
logger('[superdough]: AudioWorklets disabled with disableWorklets');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await loadWorklets();
|
||||||
|
logger('[superdough] AudioWorklets loaded');
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('could not load AudioWorklet effects', err);
|
||||||
|
}
|
||||||
|
logger('[superdough] ready');
|
||||||
}
|
}
|
||||||
|
let audioReady;
|
||||||
export async function initAudioOnFirstClick(options) {
|
export async function initAudioOnFirstClick(options) {
|
||||||
return new Promise((resolve) => {
|
if (!audioReady) {
|
||||||
document.addEventListener('click', async function listener() {
|
audioReady = new Promise((resolve) => {
|
||||||
await initAudio(options);
|
document.addEventListener('click', async function listener() {
|
||||||
resolve();
|
document.removeEventListener('click', listener);
|
||||||
document.removeEventListener('click', listener);
|
await initAudio(options);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
return audioReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
let delays = {};
|
let delays = {};
|
||||||
|
|||||||
@ -10,10 +10,10 @@ import cx from '@src/cx.mjs';
|
|||||||
import { transpiler } from '@strudel/transpiler';
|
import { transpiler } from '@strudel/transpiler';
|
||||||
import {
|
import {
|
||||||
getAudioContext,
|
getAudioContext,
|
||||||
initAudioOnFirstClick,
|
|
||||||
webaudioOutput,
|
webaudioOutput,
|
||||||
resetGlobalEffects,
|
resetGlobalEffects,
|
||||||
resetLoadedSounds,
|
resetLoadedSounds,
|
||||||
|
initAudioOnFirstClick,
|
||||||
} from '@strudel/webaudio';
|
} from '@strudel/webaudio';
|
||||||
import { defaultAudioDeviceName } from '../settings.mjs';
|
import { defaultAudioDeviceName } from '../settings.mjs';
|
||||||
import { getAudioDevices, setAudioDevice } from './util.mjs';
|
import { getAudioDevices, setAudioDevice } from './util.mjs';
|
||||||
@ -42,9 +42,10 @@ import { getMetadata } from '../metadata_parser';
|
|||||||
|
|
||||||
const { latestCode } = settingsMap.get();
|
const { latestCode } = settingsMap.get();
|
||||||
|
|
||||||
let modulesLoading, presets, drawContext, clearCanvas, isIframe;
|
let modulesLoading, presets, drawContext, clearCanvas, isIframe, audioReady;
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
initAudioOnFirstClick();
|
audioReady = initAudioOnFirstClick();
|
||||||
modulesLoading = loadModules();
|
modulesLoading = loadModules();
|
||||||
presets = prebake();
|
presets = prebake();
|
||||||
drawContext = getDrawContext();
|
drawContext = getDrawContext();
|
||||||
@ -88,6 +89,7 @@ export function Repl({ embedded = false }) {
|
|||||||
clearHydra();
|
clearHydra();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
beforeEval: () => audioReady,
|
||||||
afterEval: (all) => {
|
afterEval: (all) => {
|
||||||
const { code } = all;
|
const { code } = all;
|
||||||
setLatestCode(code);
|
setLatestCode(code);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user