2014-10-23 01:26:10 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/EqualZero", "Tone/signal/Subtract", "Tone/signal/Signal"], function(Tone){
|
2014-07-03 03:37:19 +00:00
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-07-03 03:37:19 +00:00
|
|
|
/**
|
2014-10-23 01:26:10 +00:00
|
|
|
* @class Output 1 if the signal is equal to the value, otherwise outputs 0.
|
2014-11-04 06:21:42 +00:00
|
|
|
* Can accept two signals if connected to inputs 0 and 1.
|
2014-07-03 03:37:19 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2014-12-01 04:26:06 +00:00
|
|
|
* @extends {Tone.SignalBase}
|
2015-06-20 19:50:57 +00:00
|
|
|
* @param {number=} value The number to compare the incoming signal to
|
2015-02-27 18:40:35 +00:00
|
|
|
* @example
|
2015-06-14 05:17:09 +00:00
|
|
|
* var eq = new Tone.Equal(3);
|
|
|
|
* var sig = new Tone.Signal(3).connect(eq);
|
|
|
|
* //the output of eq is 1.
|
2014-07-03 03:37:19 +00:00
|
|
|
*/
|
|
|
|
Tone.Equal = function(value){
|
|
|
|
|
2014-11-04 06:21:42 +00:00
|
|
|
Tone.call(this, 2, 0);
|
2014-07-03 03:37:19 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-23 01:26:10 +00:00
|
|
|
* subtract the value from the incoming signal
|
|
|
|
*
|
2014-07-03 03:37:19 +00:00
|
|
|
* @type {Tone.Add}
|
2014-10-23 01:26:10 +00:00
|
|
|
* @private
|
2014-07-03 03:37:19 +00:00
|
|
|
*/
|
2014-10-23 01:26:10 +00:00
|
|
|
this._sub = this.input[0] = new Tone.Subtract(value);
|
2014-07-03 03:37:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Tone.EqualZero}
|
2014-10-23 01:26:10 +00:00
|
|
|
* @private
|
2014-07-03 03:37:19 +00:00
|
|
|
*/
|
2014-10-23 01:26:10 +00:00
|
|
|
this._equals = this.output = new Tone.EqualZero();
|
2014-07-03 03:37:19 +00:00
|
|
|
|
2014-10-23 01:26:10 +00:00
|
|
|
this._sub.connect(this._equals);
|
|
|
|
this.input[1] = this._sub.input[1];
|
2014-07-03 03:37:19 +00:00
|
|
|
};
|
|
|
|
|
2014-12-01 04:26:06 +00:00
|
|
|
Tone.extend(Tone.Equal, Tone.SignalBase);
|
2014-07-03 03:37:19 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-06 22:47:26 +00:00
|
|
|
* The value to compare to the incoming signal.
|
|
|
|
* @memberOf Tone.Equal#
|
|
|
|
* @type {number}
|
|
|
|
* @name value
|
2014-07-03 03:37:19 +00:00
|
|
|
*/
|
2015-02-06 22:47:26 +00:00
|
|
|
Object.defineProperty(Tone.Equal.prototype, "value", {
|
|
|
|
get : function(){
|
|
|
|
return this._sub.value;
|
|
|
|
},
|
|
|
|
set : function(value){
|
|
|
|
this._sub.value = value;
|
|
|
|
}
|
|
|
|
});
|
2014-07-03 03:37:19 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-19 04:52:04 +00:00
|
|
|
* Clean up.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Equal} this
|
2014-07-03 03:37:19 +00:00
|
|
|
*/
|
|
|
|
Tone.Equal.prototype.dispose = function(){
|
2014-09-06 22:55:11 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2015-04-05 18:25:01 +00:00
|
|
|
this._equals.dispose();
|
2014-07-03 03:37:19 +00:00
|
|
|
this._equals = null;
|
2014-10-23 01:26:10 +00:00
|
|
|
this._sub.dispose();
|
|
|
|
this._sub = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-07-03 03:37:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Equal;
|
|
|
|
});
|