UNPKG

1.56 kBJavaScriptView Raw
1import { optionsFromArguments } from "../core/util/Defaults.js";
2import { Subtract } from "./Subtract.js";
3import { Signal } from "./Signal.js";
4import { GreaterThanZero } from "./GreaterThanZero.js";
5import { readOnly } from "../core/util/Interface.js";
6/**
7 * Output 1 if the signal is greater than the value, otherwise outputs 0.
8 * can compare two signals or a signal and a number.
9 *
10 * @example
11 * return Tone.Offline(() => {
12 * const gt = new Tone.GreaterThan(2).toDestination();
13 * const sig = new Tone.Signal(4).connect(gt);
14 * }, 0.1, 1);
15 * @category Signal
16 */
17export class GreaterThan extends Signal {
18 constructor() {
19 const options = optionsFromArguments(GreaterThan.getDefaults(), arguments, ["value"]);
20 super(options);
21 this.name = "GreaterThan";
22 this.override = false;
23 this._subtract = this.input = new Subtract({
24 context: this.context,
25 value: options.value,
26 });
27 this._gtz = this.output = new GreaterThanZero({
28 context: this.context,
29 });
30 this.comparator = this._param = this._subtract.subtrahend;
31 readOnly(this, "comparator");
32 // connect
33 this._subtract.connect(this._gtz);
34 }
35 static getDefaults() {
36 return Object.assign(Signal.getDefaults(), {
37 value: 0,
38 });
39 }
40 dispose() {
41 super.dispose();
42 this._gtz.dispose();
43 this._subtract.dispose();
44 this.comparator.dispose();
45 return this;
46 }
47}
48//# sourceMappingURL=GreaterThan.js.map
\No newline at end of file