Tone.js/Tone/signal/LessThan.js

77 lines
1.7 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/signal/GreaterThan", "Tone/signal/Negate"], 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 less than the value, otherwise outputs 0.
* can compare two signals or a signal and a number.
* input 0: left hand side of comparison.
* input 1: right hand side of comparison.
2014-07-04 02:59:16 +00:00
*
* @constructor
* @extends {Tone}
* @param {number=} [value=0] the value to compare to the incoming signal
2014-07-04 02:59:16 +00:00
*/
Tone.LessThan = function(value){
Tone.call(this, 2, 0);
2014-10-23 01:25:28 +00:00
2014-07-04 02:59:16 +00:00
/**
* negate the incoming signal
* @type {Tone.Negate}
* @private
*/
2014-10-23 01:25:28 +00:00
this._neg = this.input[0] = new Tone.Negate();
/**
* input < value === -input > -value
* @type {Tone.GreaterThan}
* @private
*/
2014-10-23 01:25:28 +00:00
this._gt = this.output = new Tone.GreaterThan(-value);
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
* @type {Tone.Negate}
2014-07-04 02:59:16 +00:00
*/
2014-10-23 01:25:28 +00:00
this._lhNeg = this.input[1] = new Tone.Negate();
//connect
this._neg.connect(this._gt);
2014-10-23 01:25:28 +00:00
this._lhNeg.connect(this._gt, 0, 1);
2014-07-04 02:59:16 +00:00
};
Tone.extend(Tone.LessThan);
/**
* set the value to compare to
*
2014-07-04 02:59:16 +00:00
* @param {number} value
*/
Tone.LessThan.prototype.setValue = function(value){
this._gt.setValue(-value);
2014-07-04 02:59:16 +00:00
};
/**
* borrows the method from {@link Tone.Signal}
*
* @function
*/
Tone.LessThan.prototype.connect = Tone.Signal.prototype.connect;
2014-07-04 02:59:16 +00:00
/**
* dispose method
*/
Tone.LessThan.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._neg.dispose();
this._neg = null;
2014-10-23 01:25:28 +00:00
this._gt.dispose();
this._gt = null;
2014-10-23 01:25:28 +00:00
this._lhNeg.dispose();
this._lhNeg = null;
2014-07-04 02:59:16 +00:00
};
return Tone.LessThan;
2014-07-04 02:59:16 +00:00
});