Tone.js/Tone/signal/AND.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-10-03 21:20:00 +00:00
define(["Tone/core/Tone", "Tone/signal/Equal"], function(Tone){
"use strict";
/**
* @class and returns 1 when all the inputs are equal to 1
*
* @extends {Tone.SignalBase}
2014-10-03 21:20:00 +00:00
* @constructor
* @param {number} [inputCount=2] the number of inputs. NOTE: all inputs are
* connected to the single AND input node
2015-02-27 18:40:35 +00:00
* @example
* var and = new Tone.AND(2);
* var sigA = new Tone.Signal(0).connect(and, 0, 0);
* var sigB = new Tone.Signal(1).connect(and, 0, 1);
* //the output of and is 0.
2014-10-03 21:20:00 +00:00
*/
Tone.AND = function(inputCount){
2014-10-30 05:05:17 +00:00
inputCount = this.defaultArg(inputCount, 2);
Tone.call(this, inputCount, 0);
2014-10-30 05:05:17 +00:00
2014-10-03 21:20:00 +00:00
/**
* @type {Tone.Equal}
* @private
*/
this._equals = this.output = new Tone.Equal(inputCount);
2014-10-30 05:05:17 +00:00
//make each of the inputs an alias
for (var i = 0; i < inputCount; i++){
this.input[i] = this._equals;
}
2014-10-03 21:20:00 +00:00
};
Tone.extend(Tone.AND, Tone.SignalBase);
2014-10-03 21:20:00 +00:00
/**
* clean up
2015-02-02 03:56:33 +00:00
* @returns {Tone.AND} `this`
2014-10-03 21:20:00 +00:00
*/
Tone.AND.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._equals.dispose();
this._equals = null;
2015-02-02 03:56:33 +00:00
return this;
2014-10-03 21:20:00 +00:00
};
return Tone.AND;
});