2014-08-24 17:19:49 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Add", "Tone/signal/Multiply", "Tone/signal/Signal"], function(Tone){
|
2014-09-04 04:41:40 +00:00
|
|
|
|
|
|
|
"use strict";
|
2014-06-17 17:01:06 +00:00
|
|
|
|
2014-06-16 23:57:55 +00:00
|
|
|
/**
|
2014-07-04 17:47:56 +00:00
|
|
|
* @class performs a linear scaling on an input signal.
|
2014-11-30 02:18:04 +00:00
|
|
|
* Scales a normal gain input range [0,1] to between
|
|
|
|
* outputMin and outputMax
|
2014-06-16 23:57:55 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2014-12-01 04:26:06 +00:00
|
|
|
* @extends {Tone.SignalBase}
|
2014-11-30 02:18:04 +00:00
|
|
|
* @param {number} [outputMin=0]
|
|
|
|
* @param {number} [outputMax=1]
|
2014-06-16 23:57:55 +00:00
|
|
|
*/
|
2014-11-30 02:18:04 +00:00
|
|
|
Tone.Scale = function(outputMin, outputMax){
|
2014-06-16 23:57:55 +00:00
|
|
|
|
2014-11-04 06:21:42 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2014-11-30 02:18:04 +00:00
|
|
|
this._outputMin = this.defaultArg(outputMin, 0);
|
2014-11-04 06:21:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2014-11-30 02:18:04 +00:00
|
|
|
this._outputMax = this.defaultArg(outputMax, 1);
|
2014-06-16 23:57:55 +00:00
|
|
|
|
|
|
|
|
2014-11-04 06:21:42 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @type {Tone.Multiply}
|
2014-11-30 02:18:04 +00:00
|
|
|
* @private
|
2014-11-04 06:21:42 +00:00
|
|
|
*/
|
2014-11-30 02:18:04 +00:00
|
|
|
this._scale = this.input = new Tone.Multiply(1);
|
2014-11-04 06:21:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @type {Tone.Add}
|
2014-11-30 02:18:04 +00:00
|
|
|
* @private
|
2014-11-04 06:21:42 +00:00
|
|
|
*/
|
2014-11-30 02:18:04 +00:00
|
|
|
this._add = this.output = new Tone.Add(0);
|
2014-06-16 23:57:55 +00:00
|
|
|
|
2014-11-30 02:18:04 +00:00
|
|
|
this._scale.connect(this._add);
|
|
|
|
this._setRange();
|
2014-06-16 23:57:55 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2014-12-01 04:26:06 +00:00
|
|
|
Tone.extend(Tone.Scale, Tone.SignalBase);
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2014-06-16 23:57:55 +00:00
|
|
|
/**
|
2014-11-30 02:18:04 +00:00
|
|
|
* set the minimum output value
|
|
|
|
* @param {number} min the minimum output value
|
2014-06-16 23:57:55 +00:00
|
|
|
*/
|
2014-11-30 02:18:04 +00:00
|
|
|
Tone.Scale.prototype.setMin = function(min){
|
|
|
|
this._outputMin = min;
|
|
|
|
this._setRange();
|
2014-06-16 23:57:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-11-30 02:18:04 +00:00
|
|
|
* set the minimum output value
|
|
|
|
* @param {number} min the minimum output value
|
2014-06-16 23:57:55 +00:00
|
|
|
*/
|
2014-11-30 02:18:04 +00:00
|
|
|
Tone.Scale.prototype.setMax = function(max){
|
|
|
|
this._outputMax = max;
|
|
|
|
this._setRange();
|
2014-06-16 23:57:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-11-30 02:18:04 +00:00
|
|
|
* set the values
|
|
|
|
* @private
|
2014-06-16 23:57:55 +00:00
|
|
|
*/
|
2014-11-30 02:18:04 +00:00
|
|
|
Tone.Scale.prototype._setRange = function() {
|
|
|
|
this._add.setValue(this._outputMin);
|
|
|
|
this._scale.setValue(this._outputMax - this._outputMin);
|
2014-06-16 23:57:55 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2014-06-20 04:38:14 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
|
|
|
*/
|
|
|
|
Tone.Scale.prototype.dispose = function(){
|
2014-09-06 22:55:11 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2014-11-30 02:18:04 +00:00
|
|
|
this._add.dispose();
|
|
|
|
this._add = null;
|
2014-06-20 04:38:14 +00:00
|
|
|
this._scale.dispose();
|
|
|
|
this._scale = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
return Tone.Scale;
|
|
|
|
});
|