import "../core/context/Destination"; import "../core/clock/Transport"; import { Param } from "../core/context/Param"; import { OutputNode, ToneAudioNode, ToneAudioNodeOptions } from "../core/context/ToneAudioNode"; import { Decibels, Seconds, Time } from "../core/type/Units"; import { BasicPlaybackState, StateTimeline } from "../core/util/StateTimeline"; declare type onStopCallback = (source: Source) => void; export interface SourceOptions extends ToneAudioNodeOptions { volume: Decibels; mute: boolean; onstop: onStopCallback; } /** * Base class for sources. Sources have start/stop methods * and the ability to be synced to the * start/stop of this.context.transport. * * @example * //Multiple state change events can be chained together, * //but must be set in the correct order and with ascending times * * // OK * state.start().stop("+0.2"); * // AND * state.start().stop("+0.2").start("+0.4").stop("+0.7") * * // BAD * state.stop("+0.2").start(); * // OR * state.start("+0.3").stop("+0.2"); * */ export declare abstract class Source extends ToneAudioNode { /** * The output volume node */ private _volume; /** * The output note */ output: OutputNode; /** * Sources have no inputs */ input: undefined; /** * The volume of the output in decibels. * @example * source.volume.value = -6; */ volume: Param; /** * The callback to invoke when the source is stopped. */ onstop: onStopCallback; /** * Keep track of the scheduled state. */ protected _state: StateTimeline<{ duration?: Seconds; offset?: Seconds; /** * Either the buffer is explicitly scheduled to end using the stop method, * or it's implicitly ended when the buffer is over. */ implicitEnd?: boolean; }>; /** * The synced `start` callback function from the transport */ protected _synced: boolean; /** * Keep track of all of the scheduled event ids */ private _scheduled; /** * Placeholder functions for syncing/unsyncing to transport */ private _syncedStart; private _syncedStop; constructor(options: SourceOptions); static getDefaults(): SourceOptions; /** * Returns the playback state of the source, either "started" or "stopped". */ readonly state: BasicPlaybackState; /** * Mute the output. * @example * //mute the output * source.mute = true; */ mute: boolean; protected abstract _start(time: Time, offset?: Time, duration?: Time): void; protected abstract _stop(time: Time): void; abstract restart(time: Time, offset?: Time, duration?: Time): this; /** * Ensure that the scheduled time is not before the current time. * Should only be used when scheduled unsynced. */ private _clampToCurrentTime; /** * Start the source at the specified time. If no time is given, * start the source now. * @param time When the source should be started. * @example * source.start("+0.5"); //starts the source 0.5 seconds from now */ start(time?: Time, offset?: Time, duration?: Time): this; /** * Stop the source at the specified time. If no time is given, * stop the source now. * @param time When the source should be stopped. * @example * source.stop(); // stops the source immediately */ stop(time?: Time): this; /** * Sync the source to the Transport so that all subsequent * calls to `start` and `stop` are synced to the TransportTime * instead of the AudioContext time. * * @example * //sync the source so that it plays between 0 and 0.3 on the Transport's timeline * source.sync().start(0).stop(0.3); * //start the transport. * this.context.transport.start(); * * @example * //start the transport with an offset and the sync'ed sources * //will start in the correct position * source.sync().start(0.1); * //the source will be invoked with an offset of 0.4 = (0.5 - 0.1) * this.context.transport.start("+0.5", 0.5); */ sync(): this; /** * Unsync the source to the Transport. See Source.sync */ unsync(): this; /** * Clean up. */ dispose(): this; } export {};