| 1 | // Strudel and superdough ship no type declarations. Rather than let every call |
| 2 | // into them degrade to `any`, this describes the slice of their surface the TUI |
| 3 | // actually uses — which is small, and is exactly the boundary worth pinning |
| 4 | // down, since a rename upstream is otherwise a runtime crash. |
| 5 | |
| 6 | declare module '@strudel/core' { |
| 7 | /** A single scheduled event: a value over a timespan. */ |
| 8 | export interface Hap { |
| 9 | value: Record<string, unknown> & { s?: string; note?: unknown; n?: unknown }; |
| 10 | whole?: { begin: { valueOf(): number }; end: { valueOf(): number } }; |
| 11 | context?: { locations?: Array<{ start: number; end: number }> }; |
| 12 | } |
| 13 | |
| 14 | export interface Pattern { |
| 15 | queryArc(begin: number, end: number): Hap[]; |
| 16 | } |
| 17 | |
| 18 | export interface Scheduler { |
| 19 | cps: number; |
| 20 | started: boolean; |
| 21 | pattern?: Pattern; |
| 22 | now(): number; |
| 23 | } |
| 24 | |
| 25 | export interface ReplState { |
| 26 | code: string; |
| 27 | activeCode: string; |
| 28 | started: boolean; |
| 29 | error?: Error; |
| 30 | } |
| 31 | |
| 32 | export type Output = (hap: Hap, deadline: number, duration: number, cps: number) => void; |
| 33 | |
| 34 | export interface ReplOptions { |
| 35 | defaultOutput: Output; |
| 36 | getTime: () => number; |
| 37 | transpiler?: unknown; |
| 38 | afterEval?: (state: ReplState) => void; |
| 39 | onEvalError?: (err: Error) => void; |
| 40 | onToggle?: (started: boolean) => void; |
| 41 | } |
| 42 | |
| 43 | export interface Repl { |
| 44 | scheduler: Scheduler; |
| 45 | state: ReplState; |
| 46 | evaluate(code: string, autostart?: boolean): Promise<unknown>; |
| 47 | start(): void; |
| 48 | stop(): void; |
| 49 | pause(): void; |
| 50 | toggle(): void; |
| 51 | setCps(cps: number): void; |
| 52 | } |
| 53 | |
| 54 | export function repl(options: ReplOptions): Repl; |
| 55 | export function evalScope(...modules: unknown[]): Promise<void>; |
| 56 | export const controls: Record<string, unknown>; |
| 57 | export const silence: Pattern; |
| 58 | } |
| 59 | |
| 60 | declare module '@strudel/transpiler' { |
| 61 | export const transpiler: unknown; |
| 62 | } |
| 63 | |
| 64 | declare module '@strudel/mini'; |
| 65 | declare module '@strudel/tonal'; |
| 66 | |
| 67 | declare module 'superdough' { |
| 68 | import type { Hap } from '@strudel/core'; |
| 69 | |
| 70 | export function setAudioContext(ctx: AudioContext): AudioContext; |
| 71 | export function getAudioContext(): AudioContext; |
| 72 | export function loadWorklets(): Promise<void>; |
| 73 | export function superdough( |
| 74 | value: Hap['value'] & { cps?: number }, |
| 75 | deadline: number, |
| 76 | duration: number, |
| 77 | cps?: number, |
| 78 | ): void; |
| 79 | export function samples(url: string): Promise<void>; |
| 80 | export function aliasBank(url: string): Promise<void>; |
| 81 | export function registerSynthSounds(): Promise<void>; |
| 82 | export function registerZZFXSounds(): Promise<void>; |
| 83 | export function setLogger(fn: (message: string, type?: string) => void): void; |
| 84 | } |
| 85 | |
| 86 | declare module 'node-web-audio-api/polyfill.js'; |