mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 16:48:00 +00:00
option not to convert units
that would make the .units attribute only for labelling and non-functional.
This commit is contained in:
parent
2fdaa36d1f
commit
eec1c3135d
1 changed files with 45 additions and 25 deletions
|
@ -25,9 +25,18 @@ define(["Tone/core/Tone", "Tone/signal/WaveShaper"], function(Tone){
|
||||||
*/
|
*/
|
||||||
this.units = this.defaultArg(units, Tone.Signal.Units.Number);
|
this.units = this.defaultArg(units, Tone.Signal.Units.Number);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When true, converts the set value
|
||||||
|
* based on the units given. When false,
|
||||||
|
* applies no conversion and the units
|
||||||
|
* are merely used as a label.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.convert = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The node where the constant signal value is scaled.
|
* The node where the constant signal value is scaled.
|
||||||
* @type {AudioParam}
|
* @type {GainNode}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.output = this._scaler = this.context.createGain();
|
this.output = this._scaler = this.context.createGain();
|
||||||
|
@ -87,19 +96,23 @@ define(["Tone/core/Tone", "Tone/signal/WaveShaper"], function(Tone){
|
||||||
* @return {number} the number which the value should be set to
|
* @return {number} the number which the value should be set to
|
||||||
*/
|
*/
|
||||||
Tone.Signal.prototype._fromUnits = function(val){
|
Tone.Signal.prototype._fromUnits = function(val){
|
||||||
switch(this.units){
|
if (this.convert){
|
||||||
case Tone.Signal.Units.Time:
|
switch(this.units){
|
||||||
return this.toSeconds(val);
|
case Tone.Signal.Units.Time:
|
||||||
case Tone.Signal.Units.Frequency:
|
return this.toSeconds(val);
|
||||||
return this.toFrequency(val);
|
case Tone.Signal.Units.Frequency:
|
||||||
case Tone.Signal.Units.Decibels:
|
return this.toFrequency(val);
|
||||||
return this.dbToGain(val);
|
case Tone.Signal.Units.Decibels:
|
||||||
case Tone.Signal.Units.Normal:
|
return this.dbToGain(val);
|
||||||
return Math.min(Math.max(val, 0), 1);
|
case Tone.Signal.Units.Normal:
|
||||||
case Tone.Signal.Units.Audio:
|
return Math.min(Math.max(val, 0), 1);
|
||||||
return Math.min(Math.max(val, -1), 1);
|
case Tone.Signal.Units.Audio:
|
||||||
default:
|
return Math.min(Math.max(val, -1), 1);
|
||||||
return val;
|
default:
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -110,11 +123,15 @@ define(["Tone/core/Tone", "Tone/signal/WaveShaper"], function(Tone){
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
Tone.Signal.prototype._toUnits = function(val){
|
Tone.Signal.prototype._toUnits = function(val){
|
||||||
switch(this.units){
|
if (this.convert){
|
||||||
case Tone.Signal.Units.Decibels:
|
switch(this.units){
|
||||||
return this.gainToDb(val);
|
case Tone.Signal.Units.Decibels:
|
||||||
default:
|
return this.gainToDb(val);
|
||||||
return val;
|
default:
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -168,8 +185,6 @@ define(["Tone/core/Tone", "Tone/signal/WaveShaper"], function(Tone){
|
||||||
*/
|
*/
|
||||||
Tone.Signal.prototype.exponentialRampToValueAtTime = function(value, endTime){
|
Tone.Signal.prototype.exponentialRampToValueAtTime = function(value, endTime){
|
||||||
value = this._fromUnits(value);
|
value = this._fromUnits(value);
|
||||||
// exponentialRampToValueAt cannot ever ramp from 0, apparently.
|
|
||||||
// More info: https://bugzilla.mozilla.org/show_bug.cgi?id=1125600#c2
|
|
||||||
value = Math.max(0.00001, value);
|
value = Math.max(0.00001, value);
|
||||||
this._value.exponentialRampToValueAtTime(value, this.toSeconds(endTime));
|
this._value.exponentialRampToValueAtTime(value, this.toSeconds(endTime));
|
||||||
return this;
|
return this;
|
||||||
|
@ -187,10 +202,13 @@ define(["Tone/core/Tone", "Tone/signal/WaveShaper"], function(Tone){
|
||||||
* //exponentially ramp to the value 2 over 4 seconds.
|
* //exponentially ramp to the value 2 over 4 seconds.
|
||||||
* signal.exponentialRampToValueNow(2, 4);
|
* signal.exponentialRampToValueNow(2, 4);
|
||||||
*/
|
*/
|
||||||
Tone.Signal.prototype.exponentialRampToValueNow = function(value, rampTime ){
|
Tone.Signal.prototype.exponentialRampToValueNow = function(value, rampTime){
|
||||||
var now = this.now();
|
var now = this.now();
|
||||||
this.setCurrentValueNow(now);
|
// exponentialRampToValueAt cannot ever ramp from 0, apparently.
|
||||||
this.exponentialRampToValueAtTime(value, now + this.toSeconds(rampTime ));
|
// More info: https://bugzilla.mozilla.org/show_bug.cgi?id=1125600#c2
|
||||||
|
var currentVal = this.value;
|
||||||
|
this.setValueAtTime(Math.max(currentVal, 0.0001), now);
|
||||||
|
this.exponentialRampToValueAtTime(value, now + this.toSeconds(rampTime));
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -317,7 +335,9 @@ define(["Tone/core/Tone", "Tone/signal/WaveShaper"], function(Tone){
|
||||||
/** In half-step increments, i.e. 12 is an octave above the root. */
|
/** In half-step increments, i.e. 12 is an octave above the root. */
|
||||||
Interval : "interval",
|
Interval : "interval",
|
||||||
/** Beats per minute. */
|
/** Beats per minute. */
|
||||||
BPM : "bpm"
|
BPM : "bpm",
|
||||||
|
/** A value greater than 0 */
|
||||||
|
Positive : "positive"
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in a new issue