1 | import { InputNode, OutputNode } from "../../core/context/ToneAudioNode.js";
|
2 | import { ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode.js";
|
3 | import { NormalRange, Time } from "../../core/type/Units.js";
|
4 | import { Signal } from "../../signal/Signal.js";
|
5 | type BasicEnvelopeCurve = "linear" | "exponential";
|
6 | export type EnvelopeCurve = EnvelopeCurveName | number[];
|
7 | export interface EnvelopeOptions extends ToneAudioNodeOptions {
|
8 | attack: Time;
|
9 | decay: Time;
|
10 | sustain: NormalRange;
|
11 | release: Time;
|
12 | attackCurve: EnvelopeCurve;
|
13 | releaseCurve: EnvelopeCurve;
|
14 | decayCurve: BasicEnvelopeCurve;
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | export declare class Envelope extends ToneAudioNode<EnvelopeOptions> {
|
44 | readonly name: string;
|
45 | |
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | attack: Time;
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | decay: Time;
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | sustain: NormalRange;
|
98 | |
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | release: Time;
|
117 | |
118 |
|
119 |
|
120 | private _attackCurve;
|
121 | |
122 |
|
123 |
|
124 | private _decayCurve;
|
125 | |
126 |
|
127 |
|
128 | private _releaseCurve;
|
129 | |
130 |
|
131 |
|
132 | protected _sig: Signal<"normalRange">;
|
133 | |
134 |
|
135 |
|
136 | output: OutputNode;
|
137 | |
138 |
|
139 |
|
140 | input: InputNode | undefined;
|
141 | |
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 | constructor(attack?: Time, decay?: Time, sustain?: NormalRange, release?: Time);
|
152 | constructor(options?: Partial<EnvelopeOptions>);
|
153 | static getDefaults(): EnvelopeOptions;
|
154 | /**
|
155 | * Read the current value of the envelope. Useful for
|
156 | * synchronizing visual output to the envelope.
|
157 | */
|
158 | get value(): NormalRange;
|
159 | /**
|
160 | * Get the curve
|
161 | * @param curve
|
162 | * @param direction In/Out
|
163 | * @return The curve name
|
164 | */
|
165 | private _getCurve;
|
166 | /**
|
167 | * Assign a the curve to the given name using the direction
|
168 | * @param name
|
169 | * @param direction In/Out
|
170 | * @param curve
|
171 | */
|
172 | private _setCurve;
|
173 | /**
|
174 | * The shape of the attack.
|
175 | * Can be any of these strings:
|
176 | * * "linear"
|
177 | * * "exponential"
|
178 | * * "sine"
|
179 | * * "cosine"
|
180 | * * "bounce"
|
181 | * * "ripple"
|
182 | * * "step"
|
183 | *
|
184 | * Can also be an array which describes the curve. Values
|
185 | * in the array are evenly subdivided and linearly
|
186 | * interpolated over the duration of the attack.
|
187 | * @example
|
188 | * return Tone.Offline(() => {
|
189 | * const env = new Tone.Envelope(0.4).toDestination();
|
190 | * env.attackCurve = "linear";
|
191 | * env.triggerAttack();
|
192 | * }, 1, 1);
|
193 | */
|
194 | get attackCurve(): EnvelopeCurve;
|
195 | set attackCurve(curve: EnvelopeCurve);
|
196 | /**
|
197 | * The shape of the release. See the attack curve types.
|
198 | * @example
|
199 | * return Tone.Offline(() => {
|
200 | * const env = new Tone.Envelope({
|
201 | * release: 0.8
|
202 | * }).toDestination();
|
203 | * env.triggerAttack();
|
204 | *
|
205 | * env.releaseCurve = [1, 0.3, 0.4, 0.2, 0.7, 0];
|
206 | * env.triggerRelease(0.2);
|
207 | * }, 1, 1);
|
208 | */
|
209 | get releaseCurve(): EnvelopeCurve;
|
210 | set releaseCurve(curve: EnvelopeCurve);
|
211 | /**
|
212 | * The shape of the decay either "linear" or "exponential"
|
213 | * @example
|
214 | * return Tone.Offline(() => {
|
215 | * const env = new Tone.Envelope({
|
216 | * sustain: 0.1,
|
217 | * decay: 0.5
|
218 | * }).toDestination();
|
219 | * env.decayCurve = "linear";
|
220 | * env.triggerAttack();
|
221 | * }, 1, 1);
|
222 | */
|
223 | get decayCurve(): EnvelopeCurve;
|
224 | set decayCurve(curve: EnvelopeCurve);
|
225 | /**
|
226 | * Trigger the attack/decay portion of the ADSR envelope.
|
227 | * @param time When the attack should start.
|
228 | * @param velocity The velocity of the envelope scales the vales.
|
229 | * number between 0-1
|
230 | * @example
|
231 | * const env = new Tone.AmplitudeEnvelope().toDestination();
|
232 | * const osc = new Tone.Oscillator().connect(env).start();
|
233 | * // trigger the attack 0.5 seconds from now with a velocity of 0.2
|
234 | * env.triggerAttack("+0.5", 0.2);
|
235 | */
|
236 | triggerAttack(time?: Time, velocity?: NormalRange): this;
|
237 | /**
|
238 | * Triggers the release of the envelope.
|
239 | * @param time When the release portion of the envelope should start.
|
240 | * @example
|
241 | * const env = new Tone.AmplitudeEnvelope().toDestination();
|
242 | * const osc = new Tone.Oscillator({
|
243 | * type: "sawtooth"
|
244 | * }).connect(env).start();
|
245 | * env.triggerAttack();
|
246 | * // trigger the release half a second after the attack
|
247 | * env.triggerRelease("+0.5");
|
248 | */
|
249 | triggerRelease(time?: Time): this;
|
250 | /**
|
251 | * Get the scheduled value at the given time. This will
|
252 | * return the unconverted (raw) value.
|
253 | * @example
|
254 | * const env = new Tone.Envelope(0.5, 1, 0.4, 2);
|
255 | * env.triggerAttackRelease(2);
|
256 | * setInterval(() => console.log(env.getValueAtTime(Tone.now())), 100);
|
257 | */
|
258 | getValueAtTime(time: Time): NormalRange;
|
259 | /**
|
260 | * triggerAttackRelease is shorthand for triggerAttack, then waiting
|
261 | * some duration, then triggerRelease.
|
262 | * @param duration The duration of the sustain.
|
263 | * @param time When the attack should be triggered.
|
264 | * @param velocity The velocity of the envelope.
|
265 | * @example
|
266 | * const env = new Tone.AmplitudeEnvelope().toDestination();
|
267 | * const osc = new Tone.Oscillator().connect(env).start();
|
268 | * // trigger the release 0.5 seconds after the attack
|
269 | * env.triggerAttackRelease(0.5);
|
270 | */
|
271 | triggerAttackRelease(duration: Time, time?: Time, velocity?: NormalRange): this;
|
272 | /**
|
273 | * Cancels all scheduled envelope changes after the given time.
|
274 | */
|
275 | cancel(after?: Time): this;
|
276 | /**
|
277 | * Connect the envelope to a destination node.
|
278 | */
|
279 | connect(destination: InputNode, outputNumber?: number, inputNumber?: number): this;
|
280 | /**
|
281 | * Render the envelope curve to an array of the given length.
|
282 | * Good for visualizing the envelope curve. Rescales the duration of the
|
283 | * envelope to fit the length.
|
284 | */
|
285 | asArray(length?: number): Promise<Float32Array>;
|
286 | dispose(): this;
|
287 | }
|
288 | interface EnvelopeCurveObject {
|
289 | In: number[];
|
290 | Out: number[];
|
291 | }
|
292 | interface EnvelopeCurveMap {
|
293 | linear: "linear";
|
294 | exponential: "exponential";
|
295 | bounce: EnvelopeCurveObject;
|
296 | cosine: EnvelopeCurveObject;
|
297 | sine: EnvelopeCurveObject;
|
298 | ripple: EnvelopeCurveObject;
|
299 | step: EnvelopeCurveObject;
|
300 | }
|
301 | type EnvelopeCurveName = keyof EnvelopeCurveMap;
|
302 | export {};
|