Tone.js/Tone/signal/GreaterThan.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-10-21 23:02:46 +00:00
define(["Tone/core/Tone", "Tone/signal/GreaterThanZero", "Tone/signal/Subtract", "Tone/signal/Signal"], 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.
2017-10-21 23:02:46 +00:00
* can compare two signals or a signal and a number.
*
2014-07-04 02:59:16 +00:00
* @constructor
2015-02-23 05:30:53 +00:00
* @extends {Tone.Signal}
2014-12-02 06:42:08 +00:00
* @param {number} [value=0] the value to compare to the incoming signal
2015-02-27 18:40:35 +00:00
* @example
2015-06-14 05:17:09 +00:00
* var gt = new Tone.GreaterThan(2);
* var sig = new Tone.Signal(4).connect(gt);
2017-10-21 23:02:46 +00:00
* //output of gt is equal 1.
2014-07-04 02:59:16 +00:00
*/
Tone.GreaterThan = function(value){
2014-10-23 01:24:40 +00:00
Tone.Signal.call(this);
2016-09-20 03:02:42 +00:00
this.createInsOuts(2, 0);
2017-10-21 23:02:46 +00:00
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
*/
2015-10-21 14:34:37 +00:00
this._param = this.input[0] = new Tone.Subtract(value);
this.input[1] = this._param.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
2015-10-21 14:34:37 +00:00
this._param.connect(this._gtz);
2014-07-04 02:59:16 +00:00
};
2015-02-23 05:30:53 +00:00
Tone.extend(Tone.GreaterThan, Tone.Signal);
2015-02-02 17:50:18 +00:00
2014-07-04 02:59:16 +00:00
/**
* dispose method
* @returns {Tone.GreaterThan} this
2014-07-04 02:59:16 +00:00
*/
Tone.GreaterThan.prototype.dispose = function(){
Tone.Signal.prototype.dispose.call(this);
this._gtz.dispose();
this._gtz = null;
2015-02-02 03:56:33 +00:00
return this;
2014-07-04 02:59:16 +00:00
};
return Tone.GreaterThan;
2017-10-21 23:02:46 +00:00
});