2
0
Fork 0
mirror of https://github.com/Tonejs/Tone.js synced 2025-02-15 20:18:24 +00:00
Tone.js/Tone/signal/Subtract.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/signal/Add", "Tone/signal/Negate", "Tone/signal/Signal", "Tone/core/Gain"], function(Tone){
"use strict";
/**
2015-06-20 15:50:57 -04:00
* @class Subtract the signal connected to <code>input[1]</code> from the signal connected
* to <code>input[0]</code>. If an argument is provided in the constructor, the
2015-06-19 00:52:04 -04:00
* signals <code>.value</code> will be subtracted from the incoming signal.
*
2015-02-23 00:30:53 -05:00
* @extends {Tone.Signal}
* @constructor
2015-06-19 00:52:04 -04:00
* @param {number=} value The value to subtract from the incoming signal. If the value
* is omitted, it will subtract the second signal from the first.
2015-02-27 13:40:35 -05:00
* @example
2015-06-14 01:17:09 -04:00
* var sub = new Tone.Subtract(1);
* var sig = new Tone.Signal(4).connect(sub);
* //the output of sub is 3.
2015-06-20 15:50:57 -04:00
* @example
* var sub = new Tone.Subtract();
* var sigA = new Tone.Signal(10);
* var sigB = new Tone.Signal(2.5);
* sigA.connect(sub, 0, 0);
* sigB.connect(sub, 0, 1);
* //output of sub is 7.5
*/
Tone.Subtract = function(value){
2016-09-19 23:02:42 -04:00
this.createInsOuts(2, 0);
/**
2015-02-23 00:30:53 -05:00
* the summing node
* @type {GainNode}
* @private
*/
this._sum = this.input[0] = this.output = new Tone.Gain();
/**
2015-02-23 00:30:53 -05:00
* negate the input of the second input before connecting it
* to the summing node.
* @type {Tone.Negate}
* @private
*/
2015-02-23 00:30:53 -05:00
this._neg = new Tone.Negate();
2015-02-23 00:30:53 -05:00
/**
* the node where the value is set
* @private
* @type {Tone.Signal}
*/
2015-10-21 10:34:37 -04:00
this._param = this.input[1] = new Tone.Signal(value);
2015-10-21 10:34:37 -04:00
this._param.chain(this._neg, this._sum);
2015-02-23 00:30:53 -05:00
};
2015-02-23 00:30:53 -05:00
Tone.extend(Tone.Subtract, Tone.Signal);
2015-02-02 12:50:18 -05:00
/**
2015-06-19 00:52:04 -04:00
* Clean up.
* @returns {Tone.SignalBase} this
*/
Tone.Subtract.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._neg.dispose();
this._neg = null;
2015-02-23 00:30:53 -05:00
this._sum.disconnect();
this._sum = null;
2015-10-21 10:34:37 -04:00
this._param.dispose();
this._param = null;
2015-02-01 22:56:33 -05:00
return this;
};
return Tone.Subtract;
});