2014-12-01 04:26:06 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Add", "Tone/signal/Negate", "Tone/signal/SignalBase"], 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
|
|
|
*
|
2014-12-01 04:26:06 +00:00
|
|
|
* @extends {Tone.SignalBase}
|
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
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* the adder node
|
|
|
|
* @type {Tone.Add}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._adder = this.input[0] = this.output = new Tone.Add(-value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the negate node
|
|
|
|
* @type {Tone.Negate}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._neg = this.input[1] = new Tone.Negate();
|
|
|
|
|
|
|
|
//connect it up
|
|
|
|
this._neg.connect(this._adder, 0, 1);
|
|
|
|
};
|
|
|
|
|
2014-12-01 04:26:06 +00:00
|
|
|
Tone.extend(Tone.Subtract, Tone.SignalBase);
|
2014-10-23 01:17:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* set the constant
|
|
|
|
*
|
|
|
|
* @param {number} value
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.SignalBase} `this`
|
2014-10-23 01:17:29 +00:00
|
|
|
*/
|
|
|
|
Tone.Subtract.prototype.setValue = function(value){
|
|
|
|
this._adder.setValue(-value);
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
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;
|
|
|
|
this._adder.dispose();
|
|
|
|
this._adder = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-10-23 01:17:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Subtract;
|
|
|
|
});
|