UNPKG

2.82 kBTypeScriptView Raw
1import { Gain } from "../core/context/Gain.js";
2import { ToneAudioNode, ToneAudioNodeOptions } from "../core/context/ToneAudioNode.js";
3import { GainFactor, Seconds, Time } from "../core/type/Units.js";
4import { BasicPlaybackState } from "../core/util/StateTimeline.js";
5export type OneShotSourceCurve = "linear" | "exponential";
6type onEndedCallback = (source: OneShotSource<any>) => void;
7export interface OneShotSourceOptions extends ToneAudioNodeOptions {
8 onended: onEndedCallback;
9 fadeIn: Time;
10 fadeOut: Time;
11 curve: OneShotSourceCurve;
12}
13/**
14 * Base class for fire-and-forget nodes
15 */
16export declare abstract class OneShotSource<Options extends ToneAudioNodeOptions> extends ToneAudioNode<Options> {
17 /**
18 * The callback to invoke after the
19 * source is done playing.
20 */
21 onended: onEndedCallback;
22 /**
23 * Sources do not have input nodes
24 */
25 input: undefined;
26 /**
27 * The start time
28 */
29 protected _startTime: number;
30 /**
31 * The stop time
32 */
33 protected _stopTime: number;
34 /**
35 * The id of the timeout
36 */
37 private _timeout;
38 /**
39 * The public output node
40 */
41 output: Gain;
42 /**
43 * The output gain node.
44 */
45 protected _gainNode: Gain<"gain">;
46 /**
47 * The fadeIn time of the amplitude envelope.
48 */
49 protected _fadeIn: Time;
50 /**
51 * The fadeOut time of the amplitude envelope.
52 */
53 protected _fadeOut: Time;
54 /**
55 * The curve applied to the fades, either "linear" or "exponential"
56 */
57 protected _curve: OneShotSourceCurve;
58 constructor(options: OneShotSourceOptions);
59 static getDefaults(): OneShotSourceOptions;
60 /**
61 * Stop the source node
62 */
63 protected abstract _stopSource(time: Seconds): void;
64 /**
65 * Start the source node at the given time
66 * @param time When to start the node
67 */
68 protected abstract start(time?: Time): this;
69 /**
70 * Start the source at the given time
71 * @param time When to start the source
72 */
73 protected _startGain(time: Seconds, gain?: GainFactor): this;
74 /**
75 * Stop the source node at the given time.
76 * @param time When to stop the source
77 */
78 stop(time?: Time): this;
79 /**
80 * Stop the source at the given time
81 * @param time When to stop the source
82 */
83 protected _stopGain(time: Seconds): this;
84 /**
85 * Invoke the onended callback
86 */
87 protected _onended(): void;
88 /**
89 * Get the playback state at the given time
90 */
91 getStateAtTime: (time: Time) => BasicPlaybackState;
92 /**
93 * Get the playback state at the current time
94 */
95 get state(): BasicPlaybackState;
96 /**
97 * Cancel a scheduled stop event
98 */
99 cancelStop(): this;
100 dispose(): this;
101}
102export {};