making source's signal attributes readOnly

this helps avoid a common error which is overwriting a signal property
instead of setting the .value attribute
This commit is contained in:
Yotam Mann 2015-04-05 14:00:52 -04:00
parent f52c999abe
commit 3a93d52ee1
8 changed files with 20 additions and 44 deletions

View file

@ -124,7 +124,7 @@ define(["Tone/core/Tone"], function(Tone){
Tone.prototype.dispose.call(this);
Tone.Buffer._removeFromQueue(this);
this._buffer = null;
this.onload = null;
this.onload = Tone.Buffer.defaults.onload;
return this;
};

View file

@ -503,33 +503,15 @@ define(function(){
Tone.prototype.isFunction = isFunction;
/**
* interpolate the input value (0-1) to be between outputMin and outputMax
* @param {number} input
* @param {number} outputMin
* @param {number} outputMax
* @return {number}
* Make the property not writable. Internal use only.
* @private
* @param {string} property the property to make not writeable
*/
Tone.prototype.interpolate = function(input, outputMin, outputMax){
return input*(outputMax - outputMin) + outputMin;
};
/**
* normalize the input to 0-1 from between inputMin to inputMax
* @param {number} input
* @param {number} inputMin
* @param {number} inputMax
* @return {number}
*/
Tone.prototype.normalize = function(input, inputMin, inputMax){
//make sure that min < max
if (inputMin > inputMax){
var tmp = inputMax;
inputMax = inputMin;
inputMin = tmp;
} else if (inputMin == inputMax){
return 0;
}
return (input - inputMin) / (inputMax - inputMin);
Tone.prototype._readOnly = function(property){
Object.defineProperty(this, property, {
writable: false,
enumerable : true,
});
};
///////////////////////////////////////////////////////////////////////////

View file

@ -25,12 +25,14 @@ function(Tone){
* @type {Tone.Signal}
*/
this.frequency = new Tone.Signal(options.frequency, Tone.Signal.Units.Frequency);
this._readOnly("frequency");
/**
* the detune control
* @type {Tone.Signal}
*/
this.detune = new Tone.Signal(options.detune);
this._readOnly("detune");
/**
* the type of the oscillator source
@ -211,11 +213,8 @@ function(Tone){
Tone.OmniOscillator.prototype.dispose = function(){
Tone.Source.prototype.dispose.call(this);
this.detune.dispose();
this.detune = null;
this.frequency.dispose();
this.frequency = null;
this._oscillator.dispose();
this._oscillator = null;
this._sourceType = null;
return this;
};

View file

@ -30,12 +30,14 @@ function(Tone){
* @type {Tone.Signal}
*/
this.frequency = new Tone.Signal(options.frequency, Tone.Signal.Units.Frequency);
this._readOnly("frequency");
/**
* The detune control signal in cents.
* @type {Tone.Signal}
*/
this.detune = new Tone.Signal(options.detune);
this._readOnly("detune");
/**
* the periodic wave
@ -237,9 +239,7 @@ function(Tone){
this._oscillator = null;
}
this.frequency.dispose();
this.frequency = null;
this.detune.dispose();
this.detune = null;
this._wave = null;
return this;
};

View file

@ -48,18 +48,21 @@ function(Tone){
* @type {Tone.Signal}
*/
this.frequency = this._modulator.frequency;
this._readOnly("frequency");
/**
* the detune control
* @type {Tone.Signal}
*/
this.detune = this._modulator.detune;
this._readOnly("detune");
/**
* the modulation rate of the oscillator
* @type {Tone.Signal}
*/
this.modulationFrequency = this._pulse.frequency;
this._readOnly("modulationFrequency");
//connections
this._modulator.chain(this._scale, this._pulse.width);
@ -137,14 +140,8 @@ function(Tone){
Tone.PWMOscillator.prototype.dispose = function(){
Tone.Source.prototype.dispose.call(this);
this._pulse.dispose();
this._pulse = null;
this._scale.dispose();
this._scale = null;
this._modulator.dispose();
this._modulator = null;
this.frequency = null;
this.detune = null;
this.modulationFrequency = null;
return this;
};

View file

@ -304,7 +304,6 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source"], function(To
this._source = null;
}
this._buffer.dispose();
this._buffer = null;
return this;
};

View file

@ -23,6 +23,7 @@ function(Tone){
* @type {Tone.Signal}
*/
this.width = new Tone.Signal(options.width, Tone.Signal.Units.Normal);
this._readOnly("width");
/**
* gate the width amount
@ -48,12 +49,14 @@ function(Tone){
* @type {Tone.Signal}
*/
this.frequency = this._sawtooth.frequency;
this._readOnly("frequency");
/**
* The detune in cents.
* @type {Tone.Signal}
*/
this.detune = this._sawtooth.detune;
this._readOnly("detune");
/**
* Threshold the signal to turn it into a square
@ -147,15 +150,11 @@ function(Tone){
Tone.PulseOscillator.prototype.dispose = function(){
Tone.Source.prototype.dispose.call(this);
this._sawtooth.dispose();
this._sawtooth = null;
this.width.dispose();
this.width = null;
this._widthGate.disconnect();
this._widthGate = null;
this._thresh.disconnect();
this._thresh = null;
this.frequency = null;
this.detune = null;
return this;
};

View file

@ -47,6 +47,7 @@ define(["Tone/core/Tone", "Tone/core/Transport", "Tone/core/Master"], function(T
* source.volume.value = -6;
*/
this.volume = new Tone.Signal(this.output.gain, Tone.Signal.Units.Decibels);
this._readOnly("volume");
/**
* keeps track of the timeout for chaning the state
@ -197,7 +198,6 @@ define(["Tone/core/Tone", "Tone/core/Transport", "Tone/core/Master"], function(T
clearTimeout(this._timeout);
this.onended = function(){};
this.volume.dispose();
this.volume = null;
};
return Tone.Source;