2014-10-03 21:20:35 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Select", "Tone/signal/Equal"], function(Tone){
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class IfThenElse has three inputs. When the first input (if) is true (i.e. === 1),
|
|
|
|
* then it will pass the second input (then) through to the output, otherwise,
|
2014-10-13 23:24:06 +00:00
|
|
|
* if it's not true (i.e. === 0) then it will pass the third input (else)
|
2014-10-03 21:20:35 +00:00
|
|
|
* through to the output.
|
|
|
|
*
|
2014-12-01 04:26:06 +00:00
|
|
|
* @extends {Tone.SignalBase}
|
2014-10-03 21:20:35 +00:00
|
|
|
* @constructor
|
2015-02-27 18:40:35 +00:00
|
|
|
* @example
|
2015-06-14 05:17:09 +00:00
|
|
|
* var ifThenElse = new Tone.IfThenElse();
|
2015-06-20 19:50:57 +00:00
|
|
|
* var ifSignal = new Tone.Signal(1).connect(ifThenElse.if);
|
|
|
|
* var pwmOsc = new Tone.PWMOscillator().connect(ifThenElse.then);
|
|
|
|
* var pulseOsc = new Tone.PulseOscillator().connect(ifThenElse.else);
|
|
|
|
* //ifThenElse outputs pwmOsc
|
2015-06-14 05:17:09 +00:00
|
|
|
* signal.value = 0;
|
2015-06-20 19:50:57 +00:00
|
|
|
* //now ifThenElse outputs pulseOsc
|
2014-10-03 21:20:35 +00:00
|
|
|
*/
|
|
|
|
Tone.IfThenElse = function(){
|
|
|
|
|
2014-11-04 06:21:42 +00:00
|
|
|
Tone.call(this, 3, 0);
|
2014-10-03 21:20:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the selector node which is responsible for the routing
|
|
|
|
* @type {Tone.Select}
|
|
|
|
* @private
|
|
|
|
*/
|
2014-11-04 06:21:42 +00:00
|
|
|
this._selector = this.output = new Tone.Select(2);
|
2014-10-03 21:20:35 +00:00
|
|
|
|
|
|
|
//the input mapping
|
2014-10-13 23:24:06 +00:00
|
|
|
this.if = this.input[0] = this._selector.gate;
|
2014-10-03 21:20:35 +00:00
|
|
|
this.then = this.input[1] = this._selector.input[1];
|
|
|
|
this.else = this.input[2] = this._selector.input[0];
|
|
|
|
};
|
|
|
|
|
2014-12-01 04:26:06 +00:00
|
|
|
Tone.extend(Tone.IfThenElse, Tone.SignalBase);
|
2014-10-03 21:20:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clean up
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.IfThenElse} this
|
2014-10-03 21:20:35 +00:00
|
|
|
*/
|
|
|
|
Tone.IfThenElse.prototype.dispose = function(){
|
|
|
|
Tone.prototype.dispose.call(this);
|
|
|
|
this._selector.dispose();
|
|
|
|
this._selector = null;
|
|
|
|
this.if = null;
|
|
|
|
this.then = null;
|
|
|
|
this.else = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-10-03 21:20:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.IfThenElse;
|
|
|
|
});
|