2
0
Fork 0
mirror of https://github.com/Tonejs/Tone.js synced 2025-02-15 20:18:24 +00:00
Tone.js/Tone/signal/OR.js

60 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-10-03 17:20:00 -04:00
define(["Tone/core/Tone", "Tone/signal/GreaterThanZero"], function(Tone){
"use strict";
/**
2015-07-04 15:25:37 -04:00
* @class [OR](https://en.wikipedia.org/wiki/OR_gate)
2015-06-19 00:52:04 -04:00
* the inputs together. True if at least one of the inputs is true.
2014-10-03 17:20:00 -04:00
*
* @extends {Tone.SignalBase}
2014-10-03 17:20:00 -04:00
* @constructor
2015-06-19 00:52:04 -04:00
* @param {number} [inputCount=2] the input count
2015-02-27 13:40:35 -05:00
* @example
2015-06-14 01:17:09 -04:00
* var or = new Tone.OR(2);
* var sigA = new Tone.Signal(0)connect(or, 0, 0);
* var sigB = new Tone.Signal(1)connect(or, 0, 1);
* //output of or is 1 because at least
* //one of the inputs is equal to 1.
2014-10-03 17:20:00 -04:00
*/
2014-10-30 01:05:17 -04:00
Tone.OR = function(inputCount){
inputCount = this.defaultArg(inputCount, 2);
Tone.call(this, inputCount, 0);
2014-10-30 01:05:17 -04:00
/**
* a private summing node
* @type {GainNode}
* @private
*/
this._sum = this.context.createGain();
/**
* @type {Tone.Equal}
* @private
*/
2015-04-05 14:01:05 -04:00
this._gtz = this.output = new Tone.GreaterThanZero();
2014-10-30 01:05:17 -04:00
//make each of the inputs an alias
for (var i = 0; i < inputCount; i++){
this.input[i] = this._sum;
}
this._sum.connect(this._gtz);
};
Tone.extend(Tone.OR, Tone.SignalBase);
2014-10-30 01:05:17 -04:00
/**
* clean up
* @returns {Tone.OR} this
2014-10-30 01:05:17 -04:00
*/
Tone.OR.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._gtz.dispose();
this._gtz = null;
this._sum.disconnect();
this._sum = null;
2015-02-01 22:56:33 -05:00
return this;
2014-10-30 01:05:17 -04:00
};
2014-10-03 17:20:00 -04:00
return Tone.OR;
});