mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 05:38:34 +00:00
repl reset default dict
+ add mechanism to get a module by name from dynamic imports
This commit is contained in:
parent
d4eebf1a77
commit
305715277c
@ -22,6 +22,7 @@ export const evalScope = async (...args) => {
|
||||
globalThis[name] = value;
|
||||
});
|
||||
});
|
||||
return modules;
|
||||
};
|
||||
|
||||
function safeEval(str, options = {}) {
|
||||
|
||||
@ -5,3 +5,5 @@ export * from './tonal.mjs';
|
||||
export * from './voicings.mjs';
|
||||
|
||||
import './ireal.mjs';
|
||||
|
||||
export const packageName = '@strudel/tonal';
|
||||
|
||||
@ -48,6 +48,14 @@ if (typeof window !== 'undefined') {
|
||||
isIframe = window.location !== window.parent.location;
|
||||
}
|
||||
|
||||
async function getModule(name) {
|
||||
if (!modulesLoading) {
|
||||
return;
|
||||
}
|
||||
const modules = await modulesLoading;
|
||||
return modules.find((m) => m.packageName === name);
|
||||
}
|
||||
|
||||
export function Repl({ embedded = false }) {
|
||||
const isEmbedded = embedded || isIframe;
|
||||
const { panelPosition, isZen } = useSettings();
|
||||
@ -163,6 +171,7 @@ export function Repl({ embedded = false }) {
|
||||
};
|
||||
|
||||
const resetEditor = async () => {
|
||||
(await getModule('@strudel/tonal'))?.resetVoicings();
|
||||
resetGlobalEffects();
|
||||
clearCanvas();
|
||||
resetLoadedSounds();
|
||||
@ -188,10 +197,7 @@ export function Repl({ embedded = false }) {
|
||||
logger(`[repl] ✨ loading random tune "${patternData.id}"`);
|
||||
setActivePattern(patternData.id);
|
||||
setViewingPatternData(patternData);
|
||||
clearCanvas();
|
||||
resetLoadedSounds();
|
||||
resetGlobalEffects();
|
||||
await prebake(); // declare default samples
|
||||
await resetEditor();
|
||||
editorRef.current.setCode(code);
|
||||
editorRef.current.repl.evaluate(code);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user