Tone.js/Tone/signal/Equal.js

63 lines
1.3 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}
* @param {number} value the number to compare the incoming signal to
*/
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);
/**
* @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
};
/**
* 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(){
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;
});