This commit is contained in:
2025-11-14 01:53:18 +01:00
parent e7ffcda096
commit 8941ee13bc
29 changed files with 3752 additions and 122 deletions

View File

@ -12,28 +12,46 @@ export class ExecutionContext {
this.contentProvider = provider;
}
/**
* Check if content is a complete CSD file
*/
private isCSDContent(code: string): boolean {
return code.includes('<CsoundSynthesizer>') &&
code.includes('<CsInstruments>');
}
/**
* Execute entire file (composition mode: full restart)
*/
async executeFile(): Promise<void> {
const content = this.contentProvider?.() ?? '';
console.log('[ExecutionContext] Content from provider:', content.substring(0, 100));
console.log('[ExecutionContext] Content length:', content.length);
if (!content.trim()) {
console.log('[ExecutionContext] Content is empty, aborting');
return;
}
this.initialized = false;
await this.csound.stop();
await this.csound.evaluate(content);
this.initialized = true;
}
/**
* Execute code block (live coding mode: incremental evaluation)
* If the code is a complete CSD file, routes to executeFile() instead
*/
async executeBlock(code: string): Promise<void> {
if (!code.trim()) {
return;
}
// If this is a complete CSD file, use composition mode
if (this.isCSDContent(code)) {
return await this.executeFile();
}
if (!this.initialized) {
await this.csound.restart();
this.initialized = true;
@ -81,6 +99,7 @@ export class ExecutionContext {
}
// Default: orchestra code (instrument definitions, opcodes, etc.)
await this.csound.compileOrchestra(trimmed);
// Use evalCode() to maintain macro context from initial CSD compilation
await this.csound.evalCode(trimmed);
}
}