oof
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user