2014-10-23 01:24:40 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/GreaterThanZero", "Tone/signal/Subtract"], function(Tone){
|
2014-07-04 02:59:16 +00:00
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-07-04 02:59:16 +00:00
|
|
|
/**
|
2014-07-04 17:47:56 +00:00
|
|
|
* @class Output 1 if the signal is greater than the value, otherwise outputs 0
|
2014-10-23 01:24:40 +00:00
|
|
|
* can compare two signals or a signal and a number.
|
2014-07-04 02:59:16 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
|
|
|
* @param {number=} [value=0] the value to compare to the incoming signal
|
|
|
|
*/
|
|
|
|
Tone.GreaterThan = function(value){
|
2014-10-23 01:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* inputs. first input is the signal to compare to
|
|
|
|
* second input is the signal to compare to.
|
|
|
|
* @type {Array}
|
|
|
|
*/
|
|
|
|
this.input = new Array(2);
|
2014-10-03 17:07:26 +00:00
|
|
|
|
2014-07-04 02:59:16 +00:00
|
|
|
/**
|
2014-10-03 17:07:26 +00:00
|
|
|
* subtract the amount from the incoming signal
|
2014-10-23 01:24:40 +00:00
|
|
|
* @type {Tone.Subtract}
|
2014-07-04 02:59:16 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-10-23 01:24:40 +00:00
|
|
|
this._sub = this.input[0] = new Tone.Subtract(value);
|
|
|
|
this.input[1] = this._sub.input[1];
|
2014-07-04 02:59:16 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-03 17:07:26 +00:00
|
|
|
* compare that amount to zero
|
|
|
|
* @type {Tone.GreaterThanZero}
|
2014-07-04 02:59:16 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-10-23 01:24:40 +00:00
|
|
|
this._gtz = this.output = new Tone.GreaterThanZero();
|
2014-07-04 02:59:16 +00:00
|
|
|
|
|
|
|
//connect
|
2014-10-23 01:24:40 +00:00
|
|
|
this._sub.connect(this._gtz);
|
2014-07-04 02:59:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Tone.extend(Tone.GreaterThan);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the value to compare to
|
|
|
|
*
|
|
|
|
* @param {number} value
|
|
|
|
*/
|
|
|
|
Tone.GreaterThan.prototype.setValue = function(value){
|
2014-10-23 01:24:40 +00:00
|
|
|
this._sub.setValue(value);
|
2014-07-04 02:59:16 +00:00
|
|
|
};
|
|
|
|
|
2014-08-24 17:19:49 +00:00
|
|
|
/**
|
|
|
|
* borrows the method from {@link Tone.Signal}
|
|
|
|
*
|
|
|
|
* @function
|
|
|
|
*/
|
|
|
|
Tone.GreaterThan.prototype.connect = Tone.Signal.prototype.connect;
|
|
|
|
|
2014-07-04 02:59:16 +00:00
|
|
|
/**
|
|
|
|
* dispose method
|
|
|
|
*/
|
|
|
|
Tone.GreaterThan.prototype.dispose = function(){
|
2014-09-06 22:55:11 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2014-10-23 01:24:40 +00:00
|
|
|
this._sub.dispose();
|
2014-10-03 17:07:26 +00:00
|
|
|
this._gtz.dispose();
|
2014-10-23 01:24:40 +00:00
|
|
|
this._sub = null;
|
2014-10-03 17:07:26 +00:00
|
|
|
this._gtz = null;
|
2014-07-04 02:59:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.GreaterThan;
|
|
|
|
});
|