Tone.js/Tone/signal/Equal.js

70 lines
1.5 KiB
JavaScript
Raw Normal View History

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
"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.
* Can accept two signals if connected to inputs 0 and 1.
2014-07-03 03:37:19 +00:00
*
* @constructor
* @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){
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
};
Tone.extend(Tone.Equal, Tone.SignalBase);
2014-07-03 03:37:19 +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
*/
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.
* @returns {Tone.Equal} this
2014-07-03 03:37:19 +00:00
*/
Tone.Equal.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
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;
});