mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-22 02:58:32 +00:00
fixed
This commit is contained in:
parent
8f7194144d
commit
8be5e9d2eb
@ -27,6 +27,7 @@ export function getSound(s) {
|
|||||||
export const resetLoadedSounds = () => soundMap.set({});
|
export const resetLoadedSounds = () => soundMap.set({});
|
||||||
|
|
||||||
let audioContext;
|
let audioContext;
|
||||||
|
export const isAudioInitialized = () => audioContext != null;
|
||||||
|
|
||||||
export const setDefaultAudioContext = () => {
|
export const setDefaultAudioContext = () => {
|
||||||
audioContext = new AudioContext();
|
audioContext = new AudioContext();
|
||||||
@ -37,17 +38,12 @@ export const getAudioContext = () => {
|
|||||||
if (!audioContext) {
|
if (!audioContext) {
|
||||||
return setDefaultAudioContext();
|
return setDefaultAudioContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
return audioContext;
|
return audioContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
let workletsLoading;
|
export async function loadWorklets() {
|
||||||
|
return await getAudioContext().audioWorklet.addModule(workletsUrl);
|
||||||
function loadWorklets() {
|
|
||||||
if (workletsLoading) {
|
|
||||||
return workletsLoading;
|
|
||||||
}
|
|
||||||
workletsLoading = getAudioContext().audioWorklet.addModule(workletsUrl);
|
|
||||||
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)
|
||||||
@ -56,11 +52,15 @@ export async function initAudio(options = {}) {
|
|||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
await getAudioContext().resume();
|
await getAudioContext().resume();
|
||||||
if (!disableWorklets) {
|
if (!disableWorklets) {
|
||||||
await loadWorklets().catch((err) => {
|
await loadWorklets()
|
||||||
console.warn('could not load AudioWorklet effects coarse, crush and shape', err);
|
.catch((err) => {
|
||||||
});
|
console.warn('could not load AudioWorklet effects', err);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
logger('audio worklets loaded');
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('disableWorklets: AudioWorklet effects coarse, crush and shape are skipped!');
|
logger('disableWorklets: AudioWorklet effects skipped!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,10 +10,11 @@ import cx from '@src/cx.mjs';
|
|||||||
import { transpiler } from '@strudel/transpiler';
|
import { transpiler } from '@strudel/transpiler';
|
||||||
import {
|
import {
|
||||||
getAudioContext,
|
getAudioContext,
|
||||||
initAudioOnFirstClick,
|
initAudio,
|
||||||
webaudioOutput,
|
webaudioOutput,
|
||||||
resetGlobalEffects,
|
resetGlobalEffects,
|
||||||
resetLoadedSounds,
|
resetLoadedSounds,
|
||||||
|
isAudioInitialized,
|
||||||
} 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';
|
||||||
@ -44,7 +45,6 @@ const { latestCode } = settingsMap.get();
|
|||||||
|
|
||||||
let modulesLoading, presets, drawContext, clearCanvas, isIframe;
|
let modulesLoading, presets, drawContext, clearCanvas, isIframe;
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
initAudioOnFirstClick();
|
|
||||||
modulesLoading = loadModules();
|
modulesLoading = loadModules();
|
||||||
presets = prebake();
|
presets = prebake();
|
||||||
drawContext = getDrawContext();
|
drawContext = getDrawContext();
|
||||||
@ -83,11 +83,16 @@ export function Repl({ embedded = false }) {
|
|||||||
onUpdateState: (state) => {
|
onUpdateState: (state) => {
|
||||||
setReplState({ ...state });
|
setReplState({ ...state });
|
||||||
},
|
},
|
||||||
onToggle: (playing) => {
|
onToggle: async (playing) => {
|
||||||
if (!playing) {
|
if (!playing) {
|
||||||
clearHydra();
|
clearHydra();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
beforeEval: async () => {
|
||||||
|
if (!isAudioInitialized()) {
|
||||||
|
await initAudio();
|
||||||
|
}
|
||||||
|
},
|
||||||
afterEval: (all) => {
|
afterEval: (all) => {
|
||||||
const { code } = all;
|
const { code } = all;
|
||||||
setLatestCode(code);
|
setLatestCode(code);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user