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 /** Jump to piece time t while playing (same variation). */
10 seek?(t: number): void;
11 /** While playing: waiting for the background computation to catch up, and how far along (0..1). */
12 status?(): { buffering: boolean; fill: number };
13 /** Called every animation frame, playing or not. */
14 draw(): void;
15 readonly playing: boolean;
16 /** Current piece time in seconds. */
17 now(): number;
18 /** Total length in seconds, including any tail. */
19 length(): number;
20 /** A short message for every listener (e.g. "checking this device…"), or null. */
21 notice?(): string | null;
22 /** Diagnostic values shown in author mode. */
23 readouts(): Record<string, string>;
24 /** Called when the piece reaches its end on its own. */
25 onEnded?: () => void;
26 dispose(): void;
27}
29export interface Composition {
30 /** used in the URL, e.g. "01-poincare" */
31 id: string;
32 /** not listed on the album page (reachable by its URL), e.g. an exploration lab */
33 hidden?: boolean;
34 title: string;
35 schema: ParamSpec[];
36 /** The published settings: the contents of the composition's defaults.json */
37 defaults: Partial<Params>;
38 /** `params` is live: read it whenever needed so author edits take effect immediately. */
39 create(view: HTMLElement, params: () => Params): Piece;
40}