2015-02-23 05:30:53 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Add", "Tone/signal/Negate", "Tone/signal/Signal"], function(Tone){
|
2014-10-23 01:17:29 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class Subtract a signal and a number or two signals.
|
2014-11-04 06:21:42 +00:00
|
|
|
* input 0 : minuend.
|
|
|
|
* input 1 : subtrahend
|
2014-10-23 01:17:29 +00:00
|
|
|
*
|
2015-02-23 05:30:53 +00:00
|
|
|
* @extends {Tone.Signal}
|
2014-10-23 01:17:29 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {number=} value 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
|
|
|
|
* var sub = new Tone.Subtract(1);
|
|
|
|
* var sig = new Tone.Signal(4).connect(sub);
|
|
|
|
* //the output of sub is 3.
|
2014-10-23 01:17:29 +00:00
|
|
|
*/
|
|
|
|
Tone.Subtract = function(value){
|
|
|
|
|
2014-11-04 06:21:42 +00:00
|
|
|
Tone.call(this, 2, 0);
|
2014-10-23 01:17:29 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-23 05:30:53 +00:00
|
|
|
* the summing node
|
|
|
|
* @type {GainNode}
|
2014-10-23 01:17:29 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2015-02-23 05:30:53 +00:00
|
|
|
this._sum = this.input[0] = this.output = this.context.createGain();
|
2014-10-23 01:17:29 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-23 05:30:53 +00:00
|
|
|
* negate the input of the second input before connecting it
|
|
|
|
* to the summing node.
|
2014-10-23 01:17:29 +00:00
|
|
|
* @type {Tone.Negate}
|
|
|
|
* @private
|
|
|
|
*/
|
2015-02-23 05:30:53 +00:00
|
|
|
this._neg = new Tone.Negate();
|
2014-10-23 01:17:29 +00:00
|
|
|
|
2015-02-23 05:30:53 +00:00
|
|
|
/**
|
|
|
|
* the node where the value is set
|
|
|
|
* @private
|
|
|
|
* @type {Tone.Signal}
|
|
|
|
*/
|
|
|
|
this._value = this.input[1] = new Tone.Signal(value);
|
2014-10-23 01:17:29 +00:00
|
|
|
|
2015-02-23 05:30:53 +00:00
|
|
|
this._value.chain(this._neg, this._sum);
|
|
|
|
};
|
2014-10-23 01:17:29 +00:00
|
|
|
|
2015-02-23 05:30:53 +00:00
|
|
|
Tone.extend(Tone.Subtract, Tone.Signal);
|
2015-02-02 17:50:18 +00:00
|
|
|
|
2014-10-23 01:17:29 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.SignalBase} `this`
|
2014-10-23 01:17:29 +00:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
this._value.dispose();
|
|
|
|
this._value = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-10-23 01:17:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Subtract;
|
|
|
|
});
|