wip live coding mode
This commit is contained in:
@ -12,8 +12,10 @@
|
||||
import InputDialog from './lib/components/ui/InputDialog.svelte';
|
||||
import { createCsoundDerivedStores, type LogEntry } from './lib/csound';
|
||||
import { type CsoundProject } from './lib/project-system';
|
||||
import { DEFAULT_CSOUND_TEMPLATE } from './lib/config/templates';
|
||||
import { DEFAULT_CSOUND_TEMPLATE, LIVECODING_TEMPLATE } from './lib/config/templates';
|
||||
import { createAppContext, setAppContext } from './lib/contexts/app-context';
|
||||
import { createExecutionStrategy, type ExecutionStrategy } from './lib/csound/execution-strategies';
|
||||
import type { ProjectMode } from './lib/project-system/types';
|
||||
import {
|
||||
PanelLeftClose,
|
||||
PanelLeftOpen,
|
||||
@ -35,6 +37,8 @@
|
||||
|
||||
let analyserNode = $state<AnalyserNode | null>(null);
|
||||
let interpreterLogs = $state<LogEntry[]>([]);
|
||||
let currentStrategy = $state<ExecutionStrategy | null>(null);
|
||||
let currentMode = $state<ProjectMode>('composition');
|
||||
|
||||
let logsUnsubscribe: (() => void) | undefined;
|
||||
|
||||
@ -84,6 +88,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
function handleNewLiveCodingFile() {
|
||||
const result = projectEditor.requestSwitch(
|
||||
() => projectEditor.createNew(LIVECODING_TEMPLATE)
|
||||
);
|
||||
|
||||
if (result === 'confirm-unsaved') {
|
||||
uiState.showUnsavedChangesDialog();
|
||||
}
|
||||
}
|
||||
|
||||
function handleFileSelect(project: CsoundProject | null) {
|
||||
if (!project) return;
|
||||
|
||||
@ -96,9 +110,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function handleExecute(code: string) {
|
||||
async function handleExecute(code: string, source: 'selection' | 'block' | 'document') {
|
||||
try {
|
||||
await csound.evaluate(code);
|
||||
if (!currentStrategy) {
|
||||
currentStrategy = createExecutionStrategy(currentMode);
|
||||
}
|
||||
|
||||
const fullContent = projectEditor.content;
|
||||
await currentStrategy.execute(csound, code, fullContent, source);
|
||||
} catch (error) {
|
||||
console.error('Execution error:', error);
|
||||
}
|
||||
@ -120,7 +139,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function handleMetadataUpdate(projectId: string, updates: { title?: string; author?: string }) {
|
||||
async function handleMetadataUpdate(projectId: string, updates: { title?: string; author?: string; mode?: import('./lib/project-system/types').ProjectMode }) {
|
||||
await projectEditor.updateMetadata(updates);
|
||||
}
|
||||
|
||||
@ -168,6 +187,33 @@
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
const mode = projectEditor.currentProject?.mode || 'composition';
|
||||
|
||||
if (mode !== currentMode) {
|
||||
const oldMode = currentMode;
|
||||
currentMode = mode;
|
||||
|
||||
// IMPORTANT: Only create new strategy if mode actually changed
|
||||
// Reset the old strategy if switching away from livecoding
|
||||
if (oldMode === 'livecoding' && currentStrategy) {
|
||||
const liveCodingStrategy = currentStrategy as any;
|
||||
if (liveCodingStrategy.reset) {
|
||||
liveCodingStrategy.reset();
|
||||
}
|
||||
}
|
||||
|
||||
currentStrategy = createExecutionStrategy(mode);
|
||||
|
||||
if (mode === 'livecoding' && oldMode === 'composition') {
|
||||
console.log('Switched to live coding mode');
|
||||
} else if (mode === 'composition' && oldMode === 'livecoding') {
|
||||
csound.stop().catch(console.error);
|
||||
console.log('Switched to composition mode');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const panelTabs = [
|
||||
{
|
||||
id: 'editor',
|
||||
@ -191,6 +237,7 @@
|
||||
{projectManager}
|
||||
onFileSelect={handleFileSelect}
|
||||
onNewFile={handleNewFile}
|
||||
onNewLiveCodingFile={handleNewLiveCodingFile}
|
||||
onMetadataUpdate={handleMetadataUpdate}
|
||||
selectedProjectId={projectEditor.currentProjectId}
|
||||
/>
|
||||
@ -278,6 +325,7 @@
|
||||
onExecute={handleExecute}
|
||||
logs={interpreterLogs}
|
||||
{editorSettings}
|
||||
mode={currentMode}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user