Files
oldboy/src/lib/templates/template-registry.ts
2025-10-15 12:56:15 +02:00

163 lines
2.6 KiB
TypeScript

import type { ProjectMode } from '../project-system/types';
export interface CsoundTemplate {
id: string;
name: string;
mode: ProjectMode;
content: string;
}
const EMPTY_TEMPLATE: CsoundTemplate = {
id: 'empty',
name: 'Empty',
mode: 'composition',
content: `<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs = 1
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>
`
};
const CLASSIC_TEMPLATE: CsoundTemplate = {
id: 'classic',
name: 'Classic',
mode: 'composition',
content: `<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs = 1
instr 1
iFreq = p4
iAmp = p5
kEnv madsr 0.01, 0.1, 0.6, 0.2
aOsc oscili iAmp * kEnv, iFreq
outs aOsc, aOsc
endin
</CsInstruments>
<CsScore>
i 1 0.0 0.5 261.63 0.3
i 1 0.5 0.5 329.63 0.3
i 1 1.0 0.5 392.00 0.3
i 1 1.5 0.5 523.25 0.3
</CsScore>
</CsoundSynthesizer>
`
};
const LIVECODING_TEMPLATE: CsoundTemplate = {
id: 'livecoding',
name: 'Live Coding',
mode: 'livecoding',
content: `gaReverb init 0
instr 1
kFreq chnget "freq"
kFreq = (kFreq == 0 ? p4 : kFreq)
kAmp = p5
kEnv linsegr 0, 0.01, 1, 0.1, 0.7, 0.2, 0
aOsc vco2 kAmp * kEnv, kFreq
aFilt moogladder aOsc, 2000, 0.3
outs aFilt, aFilt
gaReverb = gaReverb + aFilt * 0.3
endin
instr 2
iFreq = p4
iAmp = p5
kEnv linsegr 0, 0.005, 1, 0.05, 0.5, 0.1, 0
aOsc vco2 iAmp * kEnv, iFreq, 10
aFilt butterlp aOsc, 800
outs aFilt, aFilt
endin
instr 99
aL, aR freeverb gaReverb, gaReverb, 0.8, 0.5
outs aL, aR
gaReverb = 0
endin
; Start reverb (always on)
i 99 0 -1
i 1 0 2 440 0.3
; Arpeggio
i 1 0 0.5 261.63 0.2
i 1 0.5 0.5 329.63 0.2
i 1 1.0 0.5 392.00 0.2
i 1 1.5 0.5 523.25 0.2
; Bass line
i 2 0 0.5 130.81 0.4
i 2 0.5 0.5 146.83 0.4
i 2 1.0 0.5 164.81 0.4
i 2 1.5 0.5 130.81 0.4
; Long note for channel control
i 1 0 10 440 0.3
freq = 440
freq = 554.37
freq = 659.25
; Turn off instrument 1
i -1 0 0
`
};
const TEMPLATE_REGISTRY: CsoundTemplate[] = [
EMPTY_TEMPLATE,
LIVECODING_TEMPLATE,
CLASSIC_TEMPLATE
];
export class TemplateRegistry {
private templates: Map<string, CsoundTemplate>;
constructor() {
this.templates = new Map(
TEMPLATE_REGISTRY.map(template => [template.id, template])
);
}
getAll(): CsoundTemplate[] {
return Array.from(this.templates.values());
}
getById(id: string): CsoundTemplate | undefined {
return this.templates.get(id);
}
getEmpty(): CsoundTemplate {
return EMPTY_TEMPLATE;
}
}
export const templateRegistry = new TemplateRegistry();