From ea8ecd4b2a4da2ad26f918b1f3876dd4c5161dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Forment?= Date: Wed, 15 Oct 2025 12:42:56 +0200 Subject: [PATCH] Trying to do better but it's hard --- csound-live-code | 1 + src/App.svelte | 52 ++++++++++- src/lib/components/editor/Editor.svelte | 14 ++- src/lib/csound/engine.ts | 109 ++++++++++++------------ src/lib/csound/execution-context.ts | 4 + src/lib/csound/execution-strategies.ts | 83 +++--------------- src/lib/csound/store.ts | 25 +++--- src/lib/editor/block-eval.ts | 47 +++++++++- src/lib/templates/template-registry.ts | 28 ++---- 9 files changed, 200 insertions(+), 163 deletions(-) create mode 160000 csound-live-code diff --git a/csound-live-code b/csound-live-code new file mode 160000 index 0000000..71b9973 --- /dev/null +++ b/csound-live-code @@ -0,0 +1 @@ +Subproject commit 71b9973520f6491bc8773418360e1e3b479f7cff diff --git a/src/App.svelte b/src/App.svelte index 17acd60..3ea49b8 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -31,6 +31,7 @@ FileStack, PanelLeftOpen, PanelRightOpen, + CircleStop, } from "lucide-svelte"; const appContext = createAppContext(); @@ -44,7 +45,7 @@ uiState, executionContext, } = appContext; - const csoundDerived = createCsoundDerivedStores(csound); + const { logs: csoundLogs, initialized, compiled, running } = createCsoundDerivedStores(csound); let analyserNode = $state(null); let interpreterLogs = $state([]); @@ -91,9 +92,27 @@ projectEditor.loadProject(projectToLoad); } - logsUnsubscribe = csoundDerived.logs.subscribe((logs) => { + logsUnsubscribe = csoundLogs.subscribe((logs) => { interpreterLogs = logs; }); + + const handleKeyDown = (e: KeyboardEvent) => { + if ((e.ctrlKey || e.metaKey) && e.key === '.') { + e.preventDefault(); + handleStop(); + } + + if ((e.ctrlKey || e.metaKey) && e.key === 's') { + e.preventDefault(); + handleSave(); + } + }; + + window.addEventListener('keydown', handleKeyDown); + + return () => { + window.removeEventListener('keydown', handleKeyDown); + }; }); onDestroy(async () => { @@ -220,6 +239,14 @@ } } + async function handleStop() { + try { + await csound.stop(); + } catch (error) { + console.error("Failed to stop:", error); + } + } + $effect(() => { if (uiState.scopePopupVisible || uiState.spectrogramPopupVisible) { analyserNode = csound.getAnalyserNode(); @@ -281,6 +308,14 @@
{#snippet leftActions()} +