1 | import { Time, UnitMap, UnitName } from "../type/Units.js";
|
2 | /**
|
3 | * Abstract base class for {@link Param} and {@link Signal}
|
4 | */
|
5 | export declare abstract class AbstractParam<TypeName extends UnitName> {
|
6 | /**
|
7 | * Schedules a parameter value change at the given time.
|
8 | * @param value The value to set the signal.
|
9 | * @param time The time when the change should occur.
|
10 | * @example
|
11 | * return Tone.Offline(() => {
|
12 | * const osc = new Tone.Oscillator(20).toDestination().start();
|
13 | * // set the frequency to 40 at exactly 0.25 seconds
|
14 | * osc.frequency.setValueAtTime(40, 0.25);
|
15 | * }, 0.5, 1);
|
16 | */
|
17 | abstract setValueAtTime(value: UnitMap[TypeName], time: Time): this;
|
18 | /**
|
19 | * Get the signals value at the given time. Subsequent scheduling
|
20 | * may invalidate the returned value.
|
21 | * @param time When to get the value
|
22 | * @example
|
23 | * const signal = new Tone.Signal().toDestination();
|
24 | * // ramp up to '8' over 3 seconds
|
25 | * signal.rampTo(8, 3);
|
26 | * // ramp back down to '0' over 3 seconds
|
27 | * signal.rampTo(0, 3, "+3");
|
28 | * setInterval(() => {
|
29 | * // check the value every 100 ms
|
30 | * console.log(signal.getValueAtTime(Tone.now()));
|
31 | * }, 100);
|
32 | */
|
33 | abstract getValueAtTime(time: Time): UnitMap[TypeName];
|
34 | /**
|
35 | * Creates a schedule point with the current value at the current time.
|
36 | * Automation methods like {@link linearRampToValueAtTime} and {@link exponentialRampToValueAtTime}
|
37 | * require a starting automation value usually set by {@link setValueAtTime}. This method
|
38 | * is useful since it will do a `setValueAtTime` with whatever the currently computed
|
39 | * value at the given time is.
|
40 | * @param time When to add a ramp point.
|
41 | * @example
|
42 | * const osc = new Tone.Oscillator().toDestination().start();
|
43 | * // set the frequency to "G4" in exactly 1 second from now.
|
44 | * osc.frequency.setRampPoint("+1");
|
45 | * osc.frequency.linearRampToValueAtTime("C1", "+2");
|
46 | */
|
47 | abstract setRampPoint(time: Time): this;
|
48 | /**
|
49 | * Schedules a linear continuous change in parameter value from the
|
50 | * previous scheduled parameter value to the given value.
|
51 | * @example
|
52 | * return Tone.Offline(() => {
|
53 | * const signal = new Tone.Signal(0).toDestination();
|
54 | * // the ramp starts from the previously scheduled value
|
55 | * signal.setValueAtTime(0, 0.1);
|
56 | * signal.linearRampToValueAtTime(1, 0.4);
|
57 | * }, 0.5, 1);
|
58 | */
|
59 | abstract linearRampToValueAtTime(value: UnitMap[TypeName], time: Time): this;
|
60 | /**
|
61 | * Schedules an exponential continuous change in parameter value from
|
62 | * the previous scheduled parameter value to the given value.
|
63 | * @example
|
64 | * return Tone.Offline(() => {
|
65 | * const signal = new Tone.Signal(1).toDestination();
|
66 | * // the ramp starts from the previously scheduled value, which must be positive
|
67 | * signal.setValueAtTime(1, 0.1);
|
68 | * signal.exponentialRampToValueAtTime(0, 0.4);
|
69 | * }, 0.5, 1);
|
70 | */
|
71 | abstract exponentialRampToValueAtTime(value: UnitMap[TypeName], time: Time): this;
|
72 | /**
|
73 | * Schedules an exponential continuous change in parameter value from
|
74 | * the current time and current value to the given value over the
|
75 | * duration of the rampTime.
|
76 | * @param value The value to ramp to.
|
77 | * @param rampTime the time that it takes the
|
78 | * value to ramp from it's current value
|
79 | * @param startTime When the ramp should start.
|
80 | * @example
|
81 | * const delay = new Tone.FeedbackDelay(0.5, 0.98).toDestination();
|
82 | * // a short burst of noise through the feedback delay
|
83 | * const noise = new Tone.Noise().connect(delay).start().stop("+0.1");
|
84 | * // making the delay time shorter over time will also make the pitch rise
|
85 | * delay.delayTime.exponentialRampTo(0.01, 20);
|
86 | * @example
|
87 | * return Tone.Offline(() => {
|
88 | * const signal = new Tone.Signal(.1).toDestination();
|
89 | * signal.exponentialRampTo(5, 0.3, 0.1);
|
90 | * }, 0.5, 1);
|
91 | */
|
92 | abstract exponentialRampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;
|
93 | /**
|
94 | * Schedules an linear continuous change in parameter value from
|
95 | * the current time and current value to the given value over the
|
96 | * duration of the rampTime.
|
97 | *
|
98 | * @param value The value to ramp to.
|
99 | * @param rampTime the time that it takes the
|
100 | * value to ramp from it's current value
|
101 | * @param startTime When the ramp should start.
|
102 | * @returns {Param} this
|
103 | * @example
|
104 | * const delay = new Tone.FeedbackDelay(0.5, 0.98).toDestination();
|
105 | * // a short burst of noise through the feedback delay
|
106 | * const noise = new Tone.Noise().connect(delay).start().stop("+0.1");
|
107 | * // making the delay time shorter over time will also make the pitch rise
|
108 | * delay.delayTime.linearRampTo(0.01, 20);
|
109 | * @example
|
110 | * return Tone.Offline(() => {
|
111 | * const signal = new Tone.Signal(1).toDestination();
|
112 | * signal.linearRampTo(0, 0.3, 0.1);
|
113 | * }, 0.5, 1);
|
114 | */
|
115 | abstract linearRampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;
|
116 | /**
|
117 | * Start exponentially approaching the target value at the given time. Since it
|
118 | * is an exponential approach it will continue approaching after the ramp duration. The
|
119 | * rampTime is the time that it takes to reach over 99% of the way towards the value.
|
120 | * @param value The value to ramp to.
|
121 | * @param rampTime the time that it takes the
|
122 | * value to ramp from it's current value
|
123 | * @param startTime When the ramp should start.
|
124 | * @example
|
125 | * @example
|
126 | * return Tone.Offline(() => {
|
127 | * const signal = new Tone.Signal(1).toDestination();
|
128 | * signal.targetRampTo(0, 0.3, 0.1);
|
129 | * }, 0.5, 1);
|
130 | */
|
131 | abstract targetRampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;
|
132 | /**
|
133 | * Start exponentially approaching the target value at the given time. Since it
|
134 | * is an exponential approach it will continue approaching after the ramp duration. The
|
135 | * rampTime is the time that it takes to reach over 99% of the way towards the value. This methods
|
136 | * is similar to setTargetAtTime except the third argument is a time instead of a 'timeConstant'
|
137 | * @param value The value to ramp to.
|
138 | * @param time When the ramp should start.
|
139 | * @param rampTime the time that it takes the value to ramp from it's current value
|
140 | * @example
|
141 | * const osc = new Tone.Oscillator().toDestination().start();
|
142 | * // exponential approach over 4 seconds starting in 1 second
|
143 | * osc.frequency.exponentialApproachValueAtTime("C4", "+1", 4);
|
144 | */
|
145 | abstract exponentialApproachValueAtTime(value: UnitMap[TypeName], time: Time, rampTime: Time): this;
|
146 | /**
|
147 | * Start exponentially approaching the target value at the given time with
|
148 | * a rate having the given time constant.
|
149 | * @param value
|
150 | * @param startTime
|
151 | * @param timeConstant
|
152 | */
|
153 | abstract setTargetAtTime(value: UnitMap[TypeName], startTime: Time, timeConstant: number): this;
|
154 | /**
|
155 | * Sets an array of arbitrary parameter values starting at the given time
|
156 | * for the given duration.
|
157 | *
|
158 | * @param values
|
159 | * @param startTime
|
160 | * @param duration
|
161 | * @param scaling If the values in the curve should be scaled by some value
|
162 | * @example
|
163 | * return Tone.Offline(() => {
|
164 | * const signal = new Tone.Signal(1).toDestination();
|
165 | * signal.setValueCurveAtTime([1, 0.2, 0.8, 0.1, 0], 0.2, 0.3);
|
166 | * }, 0.5, 1);
|
167 | */
|
168 | abstract setValueCurveAtTime(values: UnitMap[TypeName][], startTime: Time, duration: Time, scaling?: number): this;
|
169 | /**
|
170 | * Cancels all scheduled parameter changes with times greater than or
|
171 | * equal to startTime.
|
172 | * @example
|
173 | * return Tone.Offline(() => {
|
174 | * const signal = new Tone.Signal(0).toDestination();
|
175 | * signal.setValueAtTime(0.1, 0.1);
|
176 | * signal.setValueAtTime(0.2, 0.2);
|
177 | * signal.setValueAtTime(0.3, 0.3);
|
178 | * signal.setValueAtTime(0.4, 0.4);
|
179 | * // cancels the last two scheduled changes
|
180 | * signal.cancelScheduledValues(0.3);
|
181 | * }, 0.5, 1);
|
182 | */
|
183 | abstract cancelScheduledValues(time: Time): this;
|
184 | /**
|
185 | * This is similar to {@link cancelScheduledValues} except
|
186 | * it holds the automated value at time until the next automated event.
|
187 | * @example
|
188 | * return Tone.Offline(() => {
|
189 | * const signal = new Tone.Signal(0).toDestination();
|
190 | * signal.linearRampTo(1, 0.5, 0);
|
191 | * signal.cancelAndHoldAtTime(0.3);
|
192 | * }, 0.5, 1);
|
193 | */
|
194 | abstract cancelAndHoldAtTime(time: Time): this;
|
195 | /**
|
196 | * Ramps to the given value over the duration of the rampTime.
|
197 | * Automatically selects the best ramp type (exponential or linear)
|
198 | * depending on the `units` of the signal
|
199 | *
|
200 | * @param value
|
201 | * @param rampTime The time that it takes the value to ramp from it's current value
|
202 | * @param startTime When the ramp should start.
|
203 | * @example
|
204 | * const osc = new Tone.Oscillator().toDestination().start();
|
205 | * // schedule it to ramp either linearly or exponentially depending on the units
|
206 | * osc.frequency.rampTo("A2", 10);
|
207 | * @example
|
208 | * const osc = new Tone.Oscillator().toDestination().start();
|
209 | * // schedule it to ramp starting at a specific time
|
210 | * osc.frequency.rampTo("A2", 10, "+2");
|
211 | */
|
212 | abstract rampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;
|
213 | /**
|
214 | * The current value of the parameter. Setting this value
|
215 | * is equivalent to setValueAtTime(value, context.currentTime)
|
216 | */
|
217 | abstract value: UnitMap[TypeName];
|
218 | /**
|
219 | * If the value should be converted or not
|
220 | */
|
221 | abstract convert: boolean;
|
222 | /**
|
223 | * The unit type
|
224 | */
|
225 | abstract readonly units: UnitName;
|
226 | /**
|
227 | * True if the signal value is being overridden by
|
228 | * a connected signal. Internal use only.
|
229 | */
|
230 | abstract overridden: boolean;
|
231 | /**
|
232 | * The minimum value of the output given the units
|
233 | */
|
234 | abstract readonly minValue: number;
|
235 | /**
|
236 | * The maximum value of the output given the units
|
237 | */
|
238 | abstract readonly maxValue: number;
|
239 | }
|