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.
|
|
|
|
* Can accept two signals or a signal and a number.
|
2014-07-03 03:37:19 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
|
|
|
* @param {number} value the number to compare the incoming signal to
|
|
|
|
*/
|
|
|
|
Tone.Equal = function(value){
|
|
|
|
|
|
|
|
/**
|
2014-10-23 01:26:10 +00:00
|
|
|
* input 0: the left side operand
|
|
|
|
* input 1: the right side operand
|
|
|
|
* @type {Array}
|
2014-07-03 03:37:19 +00:00
|
|
|
*/
|
2014-10-23 01:26:10 +00:00
|
|
|
this.input = new Array(2);
|
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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} value set the comparison value
|
|
|
|
*/
|
|
|
|
Tone.Equal.prototype.setValue = function(value){
|
2014-10-23 01:26:10 +00:00
|
|
|
this._sub.setValue(value);
|
2014-07-03 03:37:19 +00:00
|
|
|
};
|
|
|
|
|
2014-08-24 17:19:49 +00:00
|
|
|
/**
|
|
|
|
* borrows the method from {@link Tone.Signal}
|
|
|
|
*
|
|
|
|
* @function
|
|
|
|
*/
|
|
|
|
Tone.Equal.prototype.connect = Tone.Signal.prototype.connect;
|
|
|
|
|
2014-07-03 03:37:19 +00:00
|
|
|
/**
|
|
|
|
* dispose method
|
|
|
|
*/
|
|
|
|
Tone.Equal.prototype.dispose = function(){
|
2014-09-06 22:55:11 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2014-07-03 03:37:19 +00:00
|
|
|
this._equals.disconnect();
|
|
|
|
this._equals = null;
|
2014-10-23 01:26:10 +00:00
|
|
|
this._sub.dispose();
|
|
|
|
this._sub = null;
|
2014-07-03 03:37:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Equal;
|
|
|
|
});
|