Tone.js/Tone/signal/Add.ts

64 lines
1.6 KiB
TypeScript
Raw Normal View History

import { connectSeries } from "../core/context/ToneAudioNode";
2019-08-04 17:21:07 +00:00
import { Gain } from "../core/context/Gain";
import { Param } from "../core/context/Param";
2019-08-04 17:21:07 +00:00
import { optionsFromArguments } from "../core/util/Defaults";
2019-08-03 20:37:30 +00:00
import { Signal, SignalOptions } from "./Signal";
/**
* 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
*
* @example
2020-07-26 20:55:06 +00:00
* 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);
2019-09-16 14:15:23 +00:00
* @category Signal
2019-08-03 20:37:30 +00:00
*/
export class Add extends Signal {
override = false;
2019-09-04 23:18:44 +00:00
readonly name: string = "Add";
2019-08-03 20:37:30 +00:00
/**
2019-09-14 20:39:18 +00:00
* the summing node
2019-08-03 20:37:30 +00:00
*/
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;
2019-08-03 20:37:30 +00:00
2019-08-27 15:53:14 +00:00
/**
2019-11-17 16:09:42 +00:00
* @param value If no value is provided, will sum the input and [[addend]].
2019-08-27 15:53:14 +00:00
*/
2019-08-03 20:37:30 +00:00
constructor(value?: number);
constructor(options?: Partial<SignalOptions<"number">>);
2019-08-03 20:37:30 +00:00
constructor() {
super(Object.assign(optionsFromArguments(Add.getDefaults(), arguments, ["value"])));
connectSeries(this._constantSource, this._sum);
}
static getDefaults(): SignalOptions<"number"> {
2019-08-03 20:37:30 +00:00
return Object.assign(Signal.getDefaults(), {
value: 0,
});
}
dispose(): this {
super.dispose();
this._sum.dispose();
2019-08-03 20:37:30 +00:00
return this;
}
}