renamed Tone.Selector to Tone.Select

This commit is contained in:
Yotam Mann 2014-09-07 21:42:31 -04:00
parent 71af6ca206
commit 253884d19e
7 changed files with 32 additions and 103 deletions

2
.gitignore vendored
View file

@ -20,3 +20,5 @@ utils/npm/Tone.Preset.js
utils/npm/README.md utils/npm/README.md
examples/deps/FileSaver.js examples/deps/FileSaver.js
examples/oscilloscope.html

View file

@ -189,7 +189,7 @@ Audio-rate logic operator output 1 when true and 0 when false.
Signal can also be routed and gated for maximum flexibility. Signal can also be routed and gated for maximum flexibility.
* [Tone.Route](http://tonenotone.github.io/Tone.js/doc/Tone.Route.html) * [Tone.Route](http://tonenotone.github.io/Tone.js/doc/Tone.Route.html)
* [Tone.Selector](http://tonenotone.github.io/Tone.js/doc/Tone.Selector.html) * [Tone.Select](http://tonenotone.github.io/Tone.js/doc/Tone.Select.html)
* [Tone.Switch](http://tonenotone.github.io/Tone.js/doc/Tone.Switch.html) * [Tone.Switch](http://tonenotone.github.io/Tone.js/doc/Tone.Switch.html)
# Instruments # Instruments

View file

@ -1,4 +1,4 @@
define(["Tone/core/Tone", "Tone/signal/Selector", "Tone/signal/Negate", "Tone/signal/LessThan", "Tone/signal/Signal"], define(["Tone/core/Tone", "Tone/signal/Select", "Tone/signal/Negate", "Tone/signal/LessThan", "Tone/signal/Signal"],
function(Tone){ function(Tone){
"use strict"; "use strict";
@ -19,10 +19,10 @@ function(Tone){
this._ltz = new Tone.LessThan(0); this._ltz = new Tone.LessThan(0);
/** /**
* @type {Tone.Selector} * @type {Tone.Select}
* @private * @private
*/ */
this._switch = new Tone.Selector(2); this._switch = new Tone.Select(2);
/** /**
* @type {Tone.Negate} * @type {Tone.Negate}

View file

@ -1,4 +1,4 @@
define(["Tone/core/Tone", "Tone/signal/GreaterThan", "Tone/signal/Selector", "Tone/signal/Signal"], function(Tone){ define(["Tone/core/Tone", "Tone/signal/GreaterThan", "Tone/signal/Select", "Tone/signal/Signal"], function(Tone){
"use strict"; "use strict";
@ -20,13 +20,13 @@ define(["Tone/core/Tone", "Tone/signal/GreaterThan", "Tone/signal/Selector", "To
this._maxSignal = new Tone.Signal(max); this._maxSignal = new Tone.Signal(max);
/** /**
* @type {Tone.Selector} * @type {Tone.Select}
* @private * @private
*/ */
this._switch = new Tone.Selector(2); this._switch = new Tone.Select(2);
/** /**
* @type {Tone.Selector} * @type {Tone.Select}
* @private * @private
*/ */
this._gt = new Tone.GreaterThan(max); this._gt = new Tone.GreaterThan(max);

View file

@ -1,73 +0,0 @@
define(["Tone/core/Tone", "Tone/signal/LessThan", "Tone/signal/Selector", "Tone/signal/Signal"], function(Tone){
"use strict";
/**
* @class the output signal is the lesser of the incoming signal and min
*
* @constructor
* @extends {Tone}
* @param {number} min the minimum to compare to the incoming signal
*/
Tone.Min = function(min){
Tone.call(this);
/**
* the min signal
* @type {Tone.Signal}
* @private
*/
this._minSignal = new Tone.Signal(min);
/**
* @type {Tone.Selector}
* @private
*/
this._switch = new Tone.Selector(2);
/**
* @type {Tone.Selector}
* @private
*/
this._lt = new Tone.LessThan(min);
//connections
this._minSignal.connect(this._switch, 0, 0);
this.input.connect(this._switch, 0, 1);
this.input.connect(this._lt);
this._lt.connect(this._switch.gate);
this._switch.connect(this.output);
};
Tone.extend(Tone.Min);
/**
* set the min value
* @param {number} min the minimum to compare to the incoming signal
*/
Tone.Min.prototype.setMin = function(min){
this._minSignal.setValue(min);
};
/**
* borrows the method from {@link Tone.Signal}
*
* @function
*/
Tone.Min.prototype.connect = Tone.Signal.prototype.connect;
/**
* clean up
*/
Tone.Min.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._minSignal.dispose();
this._switch.dispose();
this._lt.dispose();
this._minSignal = null;
this._switch = null;
this._lt = null;
};
return Tone.Min;
});

View file

@ -3,7 +3,7 @@ define(["Tone/core/Tone", "Tone/signal/Equal", "Tone/signal/Signal"], function(T
"use strict"; "use strict";
/** /**
* @class Selector between any number of inputs, sending the one * @class Select between any number of inputs, sending the one
* selected by the gate signal to the output * selected by the gate signal to the output
* *
* *
@ -11,13 +11,13 @@ define(["Tone/core/Tone", "Tone/signal/Equal", "Tone/signal/Signal"], function(T
* @extends {Tone} * @extends {Tone}
* @param {number=} [sourceCount=2] the number of inputs the switch accepts * @param {number=} [sourceCount=2] the number of inputs the switch accepts
*/ */
Tone.Selector = function(sourceCount){ Tone.Select = function(sourceCount){
sourceCount = this.defaultArg(sourceCount, 2); sourceCount = this.defaultArg(sourceCount, 2);
/** /**
* the array of inputs * the array of inputs
* @type {Array<SelectorGate>} * @type {Array<SelectGate>}
*/ */
this.input = new Array(sourceCount); this.input = new Array(sourceCount);
@ -35,21 +35,21 @@ define(["Tone/core/Tone", "Tone/signal/Equal", "Tone/signal/Signal"], function(T
//make all the inputs and connect them //make all the inputs and connect them
for (var i = 0; i < sourceCount; i++){ for (var i = 0; i < sourceCount; i++){
var switchGate = new SelectorGate(i); var switchGate = new SelectGate(i);
this.input[i] = switchGate; this.input[i] = switchGate;
this.gate.connect(switchGate.selecter); this.gate.connect(switchGate.selecter);
switchGate.connect(this.output); switchGate.connect(this.output);
} }
}; };
Tone.extend(Tone.Selector); Tone.extend(Tone.Select);
/** /**
* open one of the inputs and close the other * open one of the inputs and close the other
* @param {number=} [which=0] open one of the gates (closes the other) * @param {number=} [which=0] open one of the gates (closes the other)
* @param {Tone.Time} time the time when the switch will open * @param {Tone.Time} time the time when the switch will open
*/ */
Tone.Selector.prototype.select = function(which, time){ Tone.Select.prototype.select = function(which, time){
//make sure it's an integer //make sure it's an integer
which = Math.floor(which); which = Math.floor(which);
this.gate.setValueAtTime(which, this.toSeconds(time)); this.gate.setValueAtTime(which, this.toSeconds(time));
@ -60,12 +60,12 @@ define(["Tone/core/Tone", "Tone/signal/Equal", "Tone/signal/Signal"], function(T
* *
* @function * @function
*/ */
Tone.Selector.prototype.connect = Tone.Signal.prototype.connect; Tone.Select.prototype.connect = Tone.Signal.prototype.connect;
/** /**
* dispose method * dispose method
*/ */
Tone.Selector.prototype.dispose = function(){ Tone.Select.prototype.dispose = function(){
this.gate.dispose(); this.gate.dispose();
for (var i = 0; i < this.input.length; i++){ for (var i = 0; i < this.input.length; i++){
this.input[i].dispose(); this.input[i].dispose();
@ -78,12 +78,12 @@ define(["Tone/core/Tone", "Tone/signal/Equal", "Tone/signal/Signal"], function(T
////////////START HELPER//////////// ////////////START HELPER////////////
/** /**
* helper class for Tone.Selector representing a single gate * helper class for Tone.Select representing a single gate
* @constructor * @constructor
* @extends {Tone} * @extends {Tone}
* @internal only used by Tone.Selector * @internal only used by Tone.Select
*/ */
var SelectorGate = function(num){ var SelectGate = function(num){
/** /**
* the selector * the selector
@ -101,13 +101,13 @@ define(["Tone/core/Tone", "Tone/signal/Equal", "Tone/signal/Signal"], function(T
this.selecter.connect(this.gate.gain); this.selecter.connect(this.gate.gain);
}; };
Tone.extend(SelectorGate); Tone.extend(SelectGate);
/** /**
* clean up * clean up
* @private * @private
*/ */
SelectorGate.prototype.dispose = function(){ SelectGate.prototype.dispose = function(){
Tone.prototype.dispose.call(this); Tone.prototype.dispose.call(this);
this.selecter.dispose(); this.selecter.dispose();
this.gate.disconnect(); this.gate.disconnect();
@ -117,6 +117,6 @@ define(["Tone/core/Tone", "Tone/signal/Equal", "Tone/signal/Signal"], function(T
////////////END HELPER//////////// ////////////END HELPER////////////
//return Tone.Selector //return Tone.Select
return Tone.Selector; return Tone.Select;
}); });

View file

@ -1,8 +1,8 @@
/* global it, describe, recorderDelay, recorderDuration, maxTimeout */ /* global it, describe, recorderDelay, recorderDuration, maxTimeout */
define(["tests/Core", "chai", "Tone/component/Recorder", "Tone/signal/Signal", "Tone/source/Oscillator", define(["tests/Core", "chai", "Tone/component/Recorder", "Tone/signal/Signal", "Tone/source/Oscillator",
"Tone/core/Master", "Tone/signal/Threshold", "Tone/signal/Switch", "Tone/signal/Route", "Tone/signal/Selector"], "Tone/core/Master", "Tone/signal/Threshold", "Tone/signal/Switch", "Tone/signal/Route", "Tone/signal/Select"],
function(core, chai, Recorder, Signal, Oscillator, Master, Threshold, Switch, Route, Selector){ function(core, chai, Recorder, Signal, Oscillator, Master, Threshold, Switch, Route, Select){
var expect = chai.expect; var expect = chai.expect;
@ -314,12 +314,12 @@ function(core, chai, Recorder, Signal, Oscillator, Master, Threshold, Switch, Ro
}); });
}); });
//Selector //Select
describe("Tone.Selector", function(){ describe("Tone.Select", function(){
this.timeout(maxTimeout); this.timeout(maxTimeout);
it("can be created and disposed", function(){ it("can be created and disposed", function(){
var s = new Selector(); var s = new Select();
s.dispose(); s.dispose();
wasDisposed(s, expect); wasDisposed(s, expect);
}); });
@ -327,7 +327,7 @@ function(core, chai, Recorder, Signal, Oscillator, Master, Threshold, Switch, Ro
it("can select the first signal", function(done){ it("can select the first signal", function(done){
var signal0 = new Signal(10); var signal0 = new Signal(10);
var signal1 = new Signal(20); var signal1 = new Signal(20);
var sel = new Selector(); var sel = new Select();
signal0.connect(sel, 0, 0); signal0.connect(sel, 0, 0);
signal1.connect(sel, 0, 1); signal1.connect(sel, 0, 1);
sel.select(0); sel.select(0);
@ -349,7 +349,7 @@ function(core, chai, Recorder, Signal, Oscillator, Master, Threshold, Switch, Ro
it("can select the second signal", function(done){ it("can select the second signal", function(done){
var signal0 = new Signal(11); var signal0 = new Signal(11);
var signal1 = new Signal(21); var signal1 = new Signal(21);
var sel = new Selector(); var sel = new Select();
signal0.connect(sel, 0, 0); signal0.connect(sel, 0, 0);
signal1.connect(sel, 0, 1); signal1.connect(sel, 0, 1);
sel.select(1); sel.select(1);