simplified internals of IfElseThen

changes API slightly because false is 0 and not != 1
This commit is contained in:
Yotam Mann 2014-10-13 19:24:06 -04:00
parent 7277a7eb68
commit eb07e84a6e
2 changed files with 3 additions and 12 deletions

View file

@ -5,7 +5,7 @@ define(["Tone/core/Tone", "Tone/signal/Select", "Tone/signal/Equal"], function(T
/**
* @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,
* if it's not true (i.e. !== 1) then it will pass the third input (else)
* if it's not true (i.e. === 0) then it will pass the third input (else)
* through to the output.
*
* @extends {Tone}
@ -19,12 +19,6 @@ define(["Tone/core/Tone", "Tone/signal/Select", "Tone/signal/Equal"], function(T
*/
this.input = new Array(3);
/**
* evaluates to 1 if the input is 1
* @type {Tone.Equal}
*/
this._isTrue = new Tone.Equal(1);
/**
* the selector node which is responsible for the routing
* @type {Tone.Select}
@ -39,10 +33,9 @@ define(["Tone/core/Tone", "Tone/signal/Select", "Tone/signal/Equal"], function(T
this.output = this._selector;
//the input mapping
this.if = this.input[0] = this._isTrue;
this.if = this.input[0] = this._selector.gate;
this.then = this.input[1] = this._selector.input[1];
this.else = this.input[2] = this._selector.input[0];
this._isTrue.connect(this._selector.gate);
};
Tone.extend(Tone.IfThenElse);
@ -53,8 +46,6 @@ define(["Tone/core/Tone", "Tone/signal/Select", "Tone/signal/Equal"], function(T
Tone.IfThenElse.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._selector.dispose();
this._isTrue.dispose();
this._isTrue = null;
this._selector = null;
this.if = null;
this.then = null;

View file

@ -298,7 +298,7 @@ function(core, chai, Signal, Oscillator, Switch, Route, Select, Test, NOT, AND,
it("selects the third input (else) when input 0 (if) is not 1", function(done){
var signal0, signal1, signal2, ite;
Test.offlineTest(0.2, function(dest){
signal0 = new Signal(0.3);
signal0 = new Signal(0);
signal1 = new Signal(11);
signal2 = new Signal(21);
ite = new IfThenElse();