Tone.js/Tone/signal/AND.js

51 lines
1.2 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";
/**
2015-07-04 19:25:37 +00:00
* @class [AND](https://en.wikipedia.org/wiki/Logical_conjunction)
2015-06-20 19:50:57 +00:00
* returns 1 when all the inputs are equal to 1 and returns 0 otherwise.
2014-10-03 21:20:00 +00:00
*
* @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
2015-06-20 19:50:57 +00:00
* 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
* @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;
});