1import type { AudioEngine } from "./audio.ts";
2import type { ParamSpec, Params } from "./params.ts";
4/** A running (or ready-to-run) performance of a composition, bound to a view element. */
5export interface Piece {
6 /** Start (or restart) from piece time `offset` seconds. Resolves once sound has begun. */
7 start(audio: AudioEngine, offset: number): Promise<void>;
8 stop(): void;
9 /** Called every animation frame, playing or not. */
10 draw(): void;
11 readonly playing: boolean;
12 /** Current piece time in seconds. */
13 now(): number;
14 /** Total length in seconds, including any tail. */
15 length(): number;
16 /** Diagnostic values shown in author mode. */
17 readouts(): Record<string, string>;
18 /** Called when the piece reaches its end on its own. */
19 onEnded?: () => void;
20 dispose(): void;
21}
23export interface Composition {
24 /** used in the URL, e.g. "01-poincare" */
25 id: string;
26 title: string;
27 schema: ParamSpec[];
28 /** The published settings: the contents of the composition's defaults.json */
29 defaults: Partial<Params>;
30 /** `params` is live: read it whenever needed so author edits take effect immediately. */
31 create(view: HTMLElement, params: () => Params): Piece;
32}