-
Notifications
You must be signed in to change notification settings - Fork 975
/
Add.ts
62 lines (54 loc) · 1.63 KB
/
Add.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { connectSeries } from "../core/context/ToneAudioNode.js";
import { Gain } from "../core/context/Gain.js";
import { Param } from "../core/context/Param.js";
import { optionsFromArguments } from "../core/util/Defaults.js";
import { Signal, SignalOptions } from "./Signal.js";
/**
* Add a signal and a number or two signals. When no value is
* passed into the constructor, Tone.Add will sum input and `addend`
* If a value is passed into the constructor, the it will be added to the input.
*
* @example
* return Tone.Offline(() => {
* const add = new Tone.Add(2).toDestination();
* add.addend.setValueAtTime(1, 0.2);
* const signal = new Tone.Signal(2);
* // add a signal and a scalar
* signal.connect(add);
* signal.setValueAtTime(1, 0.1);
* }, 0.5, 1);
* @category Signal
*/
export class Add extends Signal {
override = false;
readonly name: string = "Add";
/**
* the summing node
*/
private _sum: Gain = new Gain({ context: this.context });
readonly input = this._sum;
readonly output = this._sum;
/**
* The value which is added to the input signal
*/
readonly addend: Param<"number"> = this._param;
/**
* @param value If no value is provided, will sum the input and {@link addend}.
*/
constructor(value?: number);
constructor(options?: Partial<SignalOptions<"number">>);
constructor() {
super(optionsFromArguments(Add.getDefaults(), arguments, ["value"]));
connectSeries(this._constantSource, this._sum);
}
static getDefaults(): SignalOptions<"number"> {
return Object.assign(Signal.getDefaults(), {
value: 0,
});
}
dispose(): this {
super.dispose();
this._sum.dispose();
return this;
}
}