export type SchedulerType = "interval" | "worker" | "audioWorklet"; export type ClockTickEvent = { audioTime: number; timeMs: DOMHighResTimeStamp; tick: number; bpm: number; ppqn: number; }; /** * Tick event callback signature. */ export type TickCallback = (e: ClockTickEvent) => void; export interface MidiClockOptions { /** Beats per minute. Default is 120. */ bpm?: number; /** Pulses (ticks) per quarter note. Default is 24. */ ppqn?: number; /** How far ahead (ms) to schedule events. Default is 50 ms. */ lookahead?: number; /** Interval (ms) between scheduler ticks. Default is 20 ms. */ interval?: number; /** Optional AudioContext for sample-accurate audioTime. */ audioContext?: AudioContext; /** Scheduling backend. Default: "interval" */ scheduler?: SchedulerType; } type EventType = "tick"; /** * A drift-less, performance.now()-based clock for musical timing. * Emits "tick" events at a resolution defined by PPQN (ticks per quarter note). */ export declare class DeadOnClock { private _bpm; private _ppqn; private lookahead; private interval; private tickIntervalMs; private scheduler; private startPerf; private nextTickPerf; private tickCount; private running; private scheduledEvents; private listeners; private audioContext?; private startAudioTime; private startPerfTime; private lastEmittedTick; private intervalTimer; private worker; private workletNode; private workletModuleLoaded; get bpm(): number; get ppqn(): number; get started(): boolean; get currentScheduler(): SchedulerType; get currentLookahead(): number; constructor(options?: MidiClockOptions); /** * Subscribe to tick events (one per PPQN pulse). */ on(event: EventType, callback: TickCallback): void; /** * Unsubscribe from tick events. */ off(event: EventType, callback: TickCallback): void; /** * Start the clock. Emits tick events until stopped. * Returns a Promise when using the "audioWorklet" scheduler * (due to async module loading), otherwise returns void. */ start(): Promise; /** * Stop the clock. No further tick events will fire until restart. */ stop(): void; /** * Change the bpm on the fly. Resets interval calculation. */ setBpm(bpm: number): void; setPpqn(ppqn: number): void; /** * Change the lookahead on the fly and propagate to the active backend. */ setLookahead(ms: number): void; /** * Switch the scheduling backend. If the clock is running, it will be * stopped on the old backend and restarted on the new one. */ setScheduler(type: SchedulerType): Promise; /** * Schedule a one-off callback at the specified performance.now() timestamp. */ scheduleAt(callback: () => void, timeMs: number): void; /** * Create an inline Web Worker from the compiled clock-worker source. * Returns null if Workers or Blob URLs are unavailable. */ private createWorker; /** * Process a single tick received from the Worker. */ private handleWorkerTick; private startAudioWorklet; private stopAudioWorklet; private emitTick; /** * Core scheduling loop (main-thread fallback). * Looks ahead and emits tick callbacks. */ private schedule; } export {};