Tone.js/Tone/signal/Subtract.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-02-23 05:30:53 +00:00
define(["Tone/core/Tone", "Tone/signal/Add", "Tone/signal/Negate", "Tone/signal/Signal"], function(Tone){
"use strict";
/**
2015-06-20 19:50:57 +00: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 04:52:04 +00:00
* signals <code>.value</code> will be subtracted from the incoming signal.
*
2015-02-23 05:30:53 +00:00
* @extends {Tone.Signal}
* @constructor
2015-06-19 04:52:04 +00: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 18:40:35 +00:00
* @example
2015-06-14 05:17:09 +00:00
* var sub = new Tone.Subtract(1);
* var sig = new Tone.Signal(4).connect(sub);
* //the output of sub is 3.
2015-06-20 19:50:57 +00: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-20 03:02:42 +00:00
this.createInsOuts(2, 0);
/**
2015-02-23 05:30:53 +00:00
* the summing node
* @type {GainNode}
* @private
*/
2015-02-23 05:30:53 +00:00
this._sum = this.input[0] = this.output = this.context.createGain();
/**
2015-02-23 05:30:53 +00:00
* negate the input of the second input before connecting it
* to the summing node.
* @type {Tone.Negate}
* @private
*/
2015-02-23 05:30:53 +00:00
this._neg = new Tone.Negate();
2015-02-23 05:30:53 +00:00
/**
* the node where the value is set
* @private
* @type {Tone.Signal}
*/
2015-10-21 14:34:37 +00:00
this._param = this.input[1] = new Tone.Signal(value);
2015-10-21 14:34:37 +00:00
this._param.chain(this._neg, this._sum);
2015-02-23 05:30:53 +00:00
};
2015-02-23 05:30:53 +00:00
Tone.extend(Tone.Subtract, Tone.Signal);
2015-02-02 17:50:18 +00:00
/**
2015-06-19 04:52:04 +00: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 05:30:53 +00:00
this._sum.disconnect();
this._sum = null;
2015-10-21 14:34:37 +00:00
this._param.dispose();
this._param = null;
2015-02-02 03:56:33 +00:00
return this;
};
return Tone.Subtract;
});