Tone.js/Tone/signal/GreaterThan.js

66 lines
1.4 KiB
JavaScript
Raw Normal View History

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
"use strict";
2014-07-04 02:59:16 +00:00
/**
2014-10-23 01:25:28 +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
Tone.call(this, 2, 0);
2014-07-04 02:59:16 +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
/**
* 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
};
/**
* 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(){
Tone.prototype.dispose.call(this);
2014-10-23 01:24:40 +00:00
this._sub.dispose();
this._gtz.dispose();
2014-10-23 01:24:40 +00:00
this._sub = null;
this._gtz = null;
2014-07-04 02:59:16 +00:00
};
return Tone.GreaterThan;
});