Tone.js/Tone/signal/GreaterThan.js

70 lines
1.5 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.SignalBase}
2014-12-02 06:42:08 +00:00
* @param {number} [value=0] the value to compare to the incoming signal
2014-07-04 02:59:16 +00:00
*/
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, Tone.SignalBase);
2014-07-04 02:59:16 +00:00
/**
* set the value to compare to
*
* @param {number} value
2015-02-02 03:56:33 +00:00
* @returns {Tone.GreaterThan} `this`
2014-07-04 02:59:16 +00:00
*/
Tone.GreaterThan.prototype.setValue = function(value){
2014-10-23 01:24:40 +00:00
this._sub.setValue(value);
2015-02-02 03:56:33 +00:00
return this;
2014-07-04 02:59:16 +00:00
};
2015-02-02 17:50:18 +00:00
/**
* @returns {number} the value that is set
*/
Tone.GreaterThan.prototype.getValue = function(){
return this._sub.getValue();
};
2014-07-04 02:59:16 +00:00
/**
* dispose method
2015-02-02 03:56:33 +00:00
* @returns {Tone.GreaterThan} `this`
2014-07-04 02:59:16 +00:00
*/
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;
2015-02-02 03:56:33 +00:00
return this;
2014-07-04 02:59:16 +00:00
};
return Tone.GreaterThan;
});