2015-02-23 05:30:53 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/GreaterThan", "Tone/signal/Negate", "Tone/signal/Signal"],
|
|
|
|
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-10-23 01:25:28 +00:00
|
|
|
* @class Output 1 if the signal is less than the value, otherwise outputs 0.
|
2015-06-20 19:50:57 +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}
|
2015-06-19 04:52:04 +00:00
|
|
|
* @param {number=} value The value to compare to the incoming signal.
|
|
|
|
* If no value is provided, it will compare
|
2015-06-20 19:50:57 +00:00
|
|
|
* <code>input[0]</code> and <code>input[1]</code>
|
2015-02-27 18:40:35 +00:00
|
|
|
* @example
|
2015-06-14 05:17:09 +00:00
|
|
|
* var lt = new Tone.LessThan(2);
|
|
|
|
* var sig = new Tone.Signal(-1).connect(lt);
|
2015-06-20 19:50:57 +00:00
|
|
|
* //if (sig < 2) lt outputs 1
|
2014-07-04 02:59:16 +00:00
|
|
|
*/
|
|
|
|
Tone.LessThan = function(value){
|
2014-09-08 02:16:19 +00:00
|
|
|
|
2014-11-04 06:21:42 +00:00
|
|
|
Tone.call(this, 2, 0);
|
2014-10-23 01:25:28 +00:00
|
|
|
|
2014-07-04 02:59:16 +00:00
|
|
|
/**
|
2014-10-03 17:07:26 +00:00
|
|
|
* negate the incoming signal
|
|
|
|
* @type {Tone.Negate}
|
2014-07-20 22:17:01 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-10-23 01:25:28 +00:00
|
|
|
this._neg = this.input[0] = new Tone.Negate();
|
2014-07-20 22:17:01 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-03 17:07:26 +00:00
|
|
|
* input < value === -input > -value
|
|
|
|
* @type {Tone.GreaterThan}
|
2014-07-20 22:17:01 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2015-02-23 05:30:53 +00:00
|
|
|
this._gt = this.output = new Tone.GreaterThan();
|
2014-07-04 02:59:16 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-23 01:25:28 +00:00
|
|
|
* negate the signal coming from the second input
|
|
|
|
* @private
|
2014-10-03 17:07:26 +00:00
|
|
|
* @type {Tone.Negate}
|
2014-07-04 02:59:16 +00:00
|
|
|
*/
|
2015-02-23 05:30:53 +00:00
|
|
|
this._rhNeg = new Tone.Negate();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the node where the value is set
|
|
|
|
* @private
|
|
|
|
* @type {Tone.Signal}
|
|
|
|
*/
|
|
|
|
this._value = this.input[1] = new Tone.Signal(value);
|
2014-07-20 22:17:01 +00:00
|
|
|
|
|
|
|
//connect
|
2014-10-03 17:07:26 +00:00
|
|
|
this._neg.connect(this._gt);
|
2015-02-23 05:30:53 +00:00
|
|
|
this._value.connect(this._rhNeg);
|
|
|
|
this._rhNeg.connect(this._gt, 0, 1);
|
2014-07-04 02:59:16 +00:00
|
|
|
};
|
|
|
|
|
2015-02-23 05:30:53 +00:00
|
|
|
Tone.extend(Tone.LessThan, Tone.Signal);
|
2014-07-04 02:59:16 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-19 04:52:04 +00:00
|
|
|
* Clean up.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.LessThan} this
|
2014-07-04 02:59:16 +00:00
|
|
|
*/
|
|
|
|
Tone.LessThan.prototype.dispose = function(){
|
2014-09-06 22:55:11 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2014-10-03 17:07:26 +00:00
|
|
|
this._neg.dispose();
|
|
|
|
this._neg = null;
|
2014-10-23 01:25:28 +00:00
|
|
|
this._gt.dispose();
|
2014-10-03 17:07:26 +00:00
|
|
|
this._gt = null;
|
2015-02-23 05:30:53 +00:00
|
|
|
this._rhNeg.dispose();
|
|
|
|
this._rhNeg = null;
|
|
|
|
this._value.dispose();
|
|
|
|
this._value = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-07-04 02:59:16 +00:00
|
|
|
};
|
|
|
|
|
2014-07-20 22:17:01 +00:00
|
|
|
return Tone.LessThan;
|
2014-07-04 02:59:16 +00:00
|
|
|
});
|