JSHint + JSDoc

This commit is contained in:
Yotam Mann 2014-06-16 19:57:55 -04:00
parent 4c3d60f6a4
commit 20a592bd1c

View file

@ -1,38 +1,110 @@
///////////////////////////////////////////////////////////////////////////////
//
// SCALE
//
// performs linear scaling on an input signal between inputMin and inputMax
// to output the range outputMin outputMax
///////////////////////////////////////////////////////////////////////////////
define(["Tone/core/Tone", "Tone/signal/Add", "Tone/signal/Multiply"], function(Tone){
//@param {number} inputMin
//@param {number} inputMax
//@param {number=} outputMin
//@param {number=} outputMax
/**
* performs a linear scaling on an input signal
*
* scales from the input range of inputMin to inputMax
* to the output range of outputMin to outputMax
*
* if only two arguments are provided, the inputMin and inputMax are set to -1 and 1
*
* @constructor
* @extends {Tone}
* @param {number} inputMin
* @param {number} inputMax
* @param {number=} outputMin
* @param {number=} outputMax
*/
Tone.Scale = function(inputMin, inputMax, outputMin, outputMax){
Tone.call(this);
//if there are only two args
if (arguments.length == 2){
outputMin = inputMin;
outputMax = inputMax;
inputMin = -1;
inputMax = 1;
}
//components
this.plusInput = new Tone.Add(-inputMin);
this.scale = new Tone.Multiply((outputMax - outputMin)/(inputMax - inputMin));
this.plusOutput = new Tone.Add(outputMin);
/** @private
@type {number} */
this._inputMin = inputMin;
/** @private
@type {number} */
this._inputMax = inputMax;
/** @private
@type {number} */
this._outputMin = outputMin;
/** @private
@type {number} */
this._outputMax = outputMax;
/** @private
@type {Tone.Add} */
this._plusInput = new Tone.Add(0);
/** @private
@type {Tone.Multiply} */
this._scale = new Tone.Multiply(1);
/** @private
@type {Tone.Add} */
this._plusOutput = new Tone.Add(0);
//connections
this.chain(this.input, this.plusInput, this.scale, this.plusOutput, this.output);
}
this.chain(this.input, this._plusInput, this._scale, this._plusOutput, this.output);
//set the scaling values
this._setScalingParameters();
};
//extend StereoSplit
Tone.extend(Tone.Scale);
/**
* set the scaling parameters
*
* @private
*/
Tone.Scale.prototype._setScalingParameters = function(){
//components
this._plusInput.setValue(-this._inputMin);
this._scale.setValue((this._outputMax - this._outputMin)/(this._inputMax - this._inputMin));
this._plusOutput.setValue(this._outputMin);
};
/**
* set the input min value
* @param {number} val
*/
Tone.Scale.prototype.setInputMin = function(val){
this._inputMin = val;
this._setScalingParameters();
};
/**
* set the input max value
* @param {number} val
*/
Tone.Scale.prototype.setInputMax = function(val){
this._inputMax = val;
this._setScalingParameters();
};
/**
* set the output min value
* @param {number} val
*/
Tone.Scale.prototype.setOutputMin = function(val){
this._outputMin = val;
this._setScalingParameters();
};
/**
* set the output max value
* @param {number} val
*/
Tone.Scale.prototype.setOutputMax = function(val){
this._outputMax = val;
this._setScalingParameters();
};
return Tone.Scale;
});