adding min/maxValue to Param

This commit is contained in:
Yotam Mann 2017-12-16 13:09:52 -05:00
parent 43c2e9b449
commit 41eeb9884f
2 changed files with 102 additions and 0 deletions

View file

@ -80,6 +80,45 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/shim/Au
} }
}); });
/**
* The minimum output value of the parameter
* @memberOf Tone.Param#
* @type {Number}
* @name value
*/
Object.defineProperty(Tone.Param.prototype, "minValue", {
get : function(){
if (this.units === Tone.Type.Time || this.units === Tone.Type.Frequency ||
this.units === Tone.Type.NormalRange || this.units === Tone.Type.Positive ||
this.units === Tone.Type.BPM){
return 0;
} else if (this.units === Tone.Type.AudioRange){
return -1;
} else if (this.units === Tone.Type.Decibels){
return -Infinity;
} else {
return this._param.minValue;
}
}
});
/**
* The maximum output value of the parameter
* @memberOf Tone.Param#
* @type {Number}
* @name value
*/
Object.defineProperty(Tone.Param.prototype, "maxValue", {
get : function(){
if (this.units === Tone.Type.NormalRange ||
this.units === Tone.Type.AudioRange){
return 1;
} else {
return this._param.maxValue;
}
}
});
/** /**
* Convert the given value from the type specified by Tone.Param.units * Convert the given value from the type specified by Tone.Param.units
* into the destination value (such as Gain or Frequency). * into the destination value (such as Gain or Frequency).

View file

@ -117,6 +117,69 @@ define(["helper/Basic", "Test", "Tone/core/Param", "Tone/type/Type", "Tone/signa
}); });
context("minValue/maxValue", function(){
it("default min/max values", function(){
var gain = Tone.context.createGain();
var param = new Param(gain.gain);
expect(param.minValue).to.lessThan(-3e32);
expect(param.maxValue).to.greaterThan(3e32);
param.dispose();
});
it("minValue for BPM is 0", function(){
var gain = Tone.context.createGain();
var param = new Param(gain.gain, Tone.Type.BPM);
expect(param.minValue).to.equal(0);
param.dispose();
});
it("minValue for Time is 0", function(){
var gain = Tone.context.createGain();
var param = new Param(gain.gain, Tone.Type.Time);
expect(param.minValue).to.equal(0);
param.dispose();
});
it("minValue for Frequency is 0", function(){
var gain = Tone.context.createGain();
var param = new Param(gain.gain, Tone.Type.Frequency);
expect(param.minValue).to.equal(0);
param.dispose();
});
it("minValue for Decibels is -Infinity", function(){
var gain = Tone.context.createGain();
var param = new Param(gain.gain, Tone.Type.Decibels);
expect(param.minValue).to.equal(-Infinity);
param.dispose();
});
it("minValue for Positive is 0", function(){
var gain = Tone.context.createGain();
var param = new Param(gain.gain, Tone.Type.Positive);
expect(param.minValue).to.equal(0);
param.dispose();
});
it("range for AudioRange is -1 to 1", function(){
var gain = Tone.context.createGain();
var param = new Param(gain.gain, Tone.Type.AudioRange);
expect(param.minValue).to.equal(-1);
expect(param.maxValue).to.equal(1);
param.dispose();
});
it("range for NormalRange is 0 to 1", function(){
var gain = Tone.context.createGain();
var param = new Param(gain.gain, Tone.Type.NormalRange);
expect(param.minValue).to.equal(0);
expect(param.maxValue).to.equal(1);
param.dispose();
});
});
context("Scheduling API", function(){ context("Scheduling API", function(){
it ("can be scheduled to set a value in the future", function(){ it ("can be scheduled to set a value in the future", function(){