import type { AudioEngine } from "./audio.ts"; import type { ParamSpec, Params } from "./params.ts"; /** A running (or ready-to-run) performance of a composition, bound to a view element. */ export interface Piece { /** Start (or restart) from piece time `offset` seconds. Resolves once sound has begun. */ start(audio: AudioEngine, offset: number): Promise; stop(): void; /** Called every animation frame, playing or not. */ draw(): void; readonly playing: boolean; /** Current piece time in seconds. */ now(): number; /** Total length in seconds, including any tail. */ length(): number; /** A short message for every listener (e.g. "checking this device…"), or null. */ notice?(): string | null; /** Diagnostic values shown in author mode. */ readouts(): Record; /** Called when the piece reaches its end on its own. */ onEnded?: () => void; dispose(): void; } export interface Composition { /** used in the URL, e.g. "01-poincare" */ id: string; title: string; schema: ParamSpec[]; /** The published settings: the contents of the composition's defaults.json */ defaults: Partial; /** `params` is live: read it whenever needed so author edits take effect immediately. */ create(view: HTMLElement, params: () => Params): Piece; }