2019-08-03 20:37:30 +00:00
|
|
|
import { Gain } from "Tone/core";
|
|
|
|
import { connectSeries } from "Tone/core/Connect";
|
|
|
|
import { optionsFromArguments } from "Tone/core/util/Defaults";
|
2019-08-04 14:17:42 +00:00
|
|
|
import { Param } from "../core/context/Param";
|
2019-08-03 20:37:30 +00:00
|
|
|
import { Signal, SignalOptions } from "./Signal";
|
|
|
|
|
|
|
|
/**
|
2019-08-04 14:17:42 +00:00
|
|
|
* 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.
|
2019-08-03 20:37:30 +00:00
|
|
|
*
|
2019-08-04 14:17:42 +00:00
|
|
|
* @param value If no value is provided, Tone.Add will sum the first and second inputs.
|
|
|
|
* @example
|
2019-08-03 20:37:30 +00:00
|
|
|
* var signal = new Signal(2);
|
|
|
|
* var add = new Add(2);
|
|
|
|
* signal.connect(add);
|
|
|
|
* //the output of add equals 4
|
2019-08-04 14:17:42 +00:00
|
|
|
* @example
|
2019-08-03 20:37:30 +00:00
|
|
|
* //if constructed with no arguments
|
|
|
|
* //it will add the first and second inputs
|
|
|
|
* var add = new Add();
|
2019-08-04 14:17:42 +00:00
|
|
|
* var sig0 = new Signal(3).connect(add);
|
|
|
|
* var sig1 = new Signal(4).connect(add.addend);
|
2019-08-03 20:37:30 +00:00
|
|
|
* //the output of add equals 7.
|
|
|
|
*/
|
|
|
|
export class Add extends Signal {
|
|
|
|
|
|
|
|
override = false;
|
|
|
|
|
2019-08-04 14:17:42 +00:00
|
|
|
readonly name = "Add";
|
2019-08-03 20:37:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the summing node
|
|
|
|
*/
|
|
|
|
private _sum: Gain = new Gain({ context: this.context });
|
2019-08-04 14:17:42 +00:00
|
|
|
readonly input = this._sum;
|
|
|
|
readonly output = this._sum;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The value which is added to the input signal
|
|
|
|
*/
|
|
|
|
readonly addend: Param<number> = this._param;
|
2019-08-03 20:37:30 +00:00
|
|
|
|
|
|
|
constructor(options?: Partial<SignalOptions<number>>);
|
|
|
|
// tslint:disable-next-line: unified-signatures
|
|
|
|
constructor(value?: number);
|
|
|
|
constructor() {
|
|
|
|
super(Object.assign(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();
|
2019-08-04 14:17:42 +00:00
|
|
|
this._sum.dispose();
|
2019-08-03 20:37:30 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|