Tone.js/Tone/signal/GreaterThan.js

74 lines
1.4 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/signal/GreaterThanZero", "Tone/signal/Add"], function(Tone){
2014-07-04 02:59:16 +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-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-07-04 02:59:16 +00:00
/**
* subtract the amount from the incoming signal
* @type {Tone.Add}
2014-07-04 02:59:16 +00:00
* @private
*/
this._adder = new Tone.Add(-value);
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
*/
this._gtz = new Tone.GreaterThanZero();
2014-07-04 02:59:16 +00:00
/**
* alias for the negate
* @type {Tone.Negate}
2014-07-04 02:59:16 +00:00
*/
this.input = this._adder;
2014-07-04 02:59:16 +00:00
/**
* alias for the less than
* @type {Tone.LessThan}
2014-07-04 02:59:16 +00:00
*/
this.output = this._gtz;
2014-07-04 02:59:16 +00:00
//connect
this._adder.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){
this._adder.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);
this._adder.dispose();
this._gtz.dispose();
this._adder = null;
this._gtz = null;
2014-07-04 02:59:16 +00:00
};
return Tone.GreaterThan;
});