Tone.js/Tone/signal/Scale.js

110 lines
2.1 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/signal/Add", "Tone/signal/Multiply", "Tone/signal/Signal"], function(Tone){
"use strict";
2014-06-17 17:01:06 +00:00
2014-06-16 23:57:55 +00:00
/**
2015-02-27 18:40:35 +00:00
* @class Performs a linear scaling on an input signal.
* Scales a normal gain input range [0,1] to between
* outputMin and outputMax
2014-06-16 23:57:55 +00:00
*
* @constructor
* @extends {Tone.SignalBase}
* @param {number} [outputMin=0]
* @param {number} [outputMax=1]
2015-02-27 18:40:35 +00:00
* @example
2015-06-14 05:17:09 +00:00
* var scale = new Tone.Scale(50, 100);
* var signal = new Tone.Signal(0.5).connect(scale);
* //the output of scale equals 75
2014-06-16 23:57:55 +00:00
*/
Tone.Scale = function(outputMin, outputMax){
2014-06-16 23:57:55 +00:00
/**
* @private
* @type {number}
*/
this._outputMin = this.defaultArg(outputMin, 0);
/**
* @private
* @type {number}
*/
this._outputMax = this.defaultArg(outputMax, 1);
2014-06-16 23:57:55 +00:00
/**
* @private
* @type {Tone.Multiply}
* @private
*/
this._scale = this.input = new Tone.Multiply(1);
/**
* @private
* @type {Tone.Add}
* @private
*/
this._add = this.output = new Tone.Add(0);
2014-06-16 23:57:55 +00:00
this._scale.connect(this._add);
this._setRange();
2014-06-16 23:57:55 +00:00
};
Tone.extend(Tone.Scale, Tone.SignalBase);
2014-06-16 23:57:55 +00:00
/**
* The minimum output value.
* @memberOf Tone.Scale#
* @type {number}
* @name min
2014-06-16 23:57:55 +00:00
*/
Object.defineProperty(Tone.Scale.prototype, "min", {
get : function(){
return this._outputMin;
},
set : function(min){
this._outputMin = min;
this._setRange();
}
});
2014-06-16 23:57:55 +00:00
2015-02-02 17:50:18 +00:00
/**
* The maximum output value.
* @memberOf Tone.Scale#
* @type {number}
* @name max
2015-02-02 17:50:18 +00:00
*/
Object.defineProperty(Tone.Scale.prototype, "max", {
get : function(){
return this._outputMax;
},
set : function(max){
this._outputMax = max;
this._setRange();
}
});
2015-02-02 17:50:18 +00:00
2014-06-16 23:57:55 +00:00
/**
* set the values
* @private
2014-06-16 23:57:55 +00:00
*/
Tone.Scale.prototype._setRange = function() {
this._add.value = this._outputMin;
this._scale.value = this._outputMax - this._outputMin;
2014-06-16 23:57:55 +00:00
};
2014-06-20 04:38:14 +00:00
/**
* clean up
* @returns {Tone.Scale} this
2014-06-20 04:38:14 +00:00
*/
Tone.Scale.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._add.dispose();
this._add = null;
2014-06-20 04:38:14 +00:00
this._scale.dispose();
this._scale = null;
2015-02-02 03:56:33 +00:00
return this;
2014-06-20 04:38:14 +00:00
};
return Tone.Scale;
});