73fe08adouble pendulum: album app with composition 1 (poincaré)Jeremy Magland 1// Instrument interfaces. Real instruments drop in by implementing these and
2// registering in ./index.ts; compositions pick them by name.
4export interface NoteEvent {
5 /** AudioContext time */
6 when: number;
7 freq: number;
8 /** dynamics, 0..1 (overall level is set by the composition's mixer, not here) */
9 velocity: number;
10 /** -1..1 */
11 pan: number;
12 /** seconds; how long the note rings (instrument may interpret freely) */
13 duration: number;
14}
16/** Control over a note after it has been scheduled. */
17export interface NoteHandle {
18 /**
19 * Stop the note's natural decay at `from` (AudioContext time), sustain its level for
20 * `holdLen` seconds, then fade out over `fadeLen` seconds. Used for the final note of a piece.
21 */
22 hold(from: number, holdLen: number, fadeLen: number): void;
23}
25export interface NoteInstrument {
26 /** resolves when the instrument can play (e.g. an AudioWorklet has loaded) */
27 ready?: Promise<void>;
8a22646orbits: limit the orbit count to what the device can play liveJeremy Magland 28 /** share of real time the audio thread spends on this instrument (0..1), if it can tell */
29 load?(): number;
73fe08adouble pendulum: album app with composition 1 (poincaré)Jeremy Magland 30 play(ev: NoteEvent): NoteHandle | null;
31 dispose(): void;
32}
34/** Map the drone's color (0..1) onto one instrument setting. from/to are 0..1 of that setting's range. */
35export interface TimbreMap {
36 target: string;
37 from: number;
38 to: number;
39}
41export interface DroneInstrument {
42 /** resolves when the instrument can play */
43 ready?: Promise<void>;
8a22646orbits: limit the orbit count to what the device can play liveJeremy Magland 44 /** share of real time the audio thread spends on this instrument (0..1), if it can tell */
45 load?(): number;
73fe08adouble pendulum: album app with composition 1 (poincaré)Jeremy Magland 46 start(when: number, freq: number): void;
47 /** Stop with a release ending at `when`. */
48 stop(when: number, release: number): void;
49 /**
50 * Continuous controls, called often.
51 * level: linear gain 0..1; color: 0..1 timbre control (driven by energy).
52 */
53 set(
54 when: number,
55 controls: {
56 level: number;
57 color: number;
58 freq: number;
59 timbre?: TimbreMap[];
60 /** hold the output loudness steady while the timbre changes (instruments that support it) */
61 normalize?: boolean;
62 },
63 ): void;
64 /** current values of mapped settings, for the author readouts */
65 describe?(): string;
66 dispose(): void;
67}
69export interface InstrumentOptions {
70 /** instrument-specific settings, e.g. a pasted modal-synth preset (JSON) */
71 custom?: string;
8a22646orbits: limit the orbit count to what the device can play liveJeremy Magland 72 /** schedule each note's release when it is played (no final-note hold); for device checks */
73 immediateRelease?: boolean;
76export type NoteInstrumentFactory = (ctx: AudioContext, out: AudioNode, opts: InstrumentOptions) => NoteInstrument;
77export type DroneInstrumentFactory = (ctx: AudioContext, out: AudioNode, opts: InstrumentOptions) => DroneInstrument;