2014-08-24 13:19:49 -04:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Add", "Tone/signal/Multiply", "Tone/signal/Signal"], function(Tone){
|
2014-09-04 00:41:40 -04:00
|
|
|
|
|
|
|
"use strict";
|
2014-06-17 13:01:06 -04:00
|
|
|
|
2014-06-16 19:57:55 -04:00
|
|
|
/**
|
2015-02-27 13:40:35 -05:00
|
|
|
* @class Performs a linear scaling on an input signal.
|
2015-06-19 00:52:04 -04:00
|
|
|
* Scales a NormalRange input to between
|
|
|
|
* outputMin and outputMax.
|
2014-06-16 19:57:55 -04:00
|
|
|
*
|
|
|
|
* @constructor
|
2014-11-30 23:26:06 -05:00
|
|
|
* @extends {Tone.SignalBase}
|
2015-06-19 00:52:04 -04:00
|
|
|
* @param {number} [outputMin=0] The output value when the input is 0.
|
|
|
|
* @param {number} [outputMax=1] The output value when the input is 1.
|
2015-02-27 13:40:35 -05:00
|
|
|
* @example
|
2015-06-14 01:17:09 -04: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 19:57:55 -04:00
|
|
|
*/
|
2014-11-29 21:18:04 -05:00
|
|
|
Tone.Scale = function(outputMin, outputMax){
|
2014-06-16 19:57:55 -04:00
|
|
|
|
2014-11-04 01:21:42 -05:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2014-11-29 21:18:04 -05:00
|
|
|
this._outputMin = this.defaultArg(outputMin, 0);
|
2014-11-04 01:21:42 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2014-11-29 21:18:04 -05:00
|
|
|
this._outputMax = this.defaultArg(outputMax, 1);
|
2014-06-16 19:57:55 -04:00
|
|
|
|
|
|
|
|
2014-11-04 01:21:42 -05:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @type {Tone.Multiply}
|
2014-11-29 21:18:04 -05:00
|
|
|
* @private
|
2014-11-04 01:21:42 -05:00
|
|
|
*/
|
2014-11-29 21:18:04 -05:00
|
|
|
this._scale = this.input = new Tone.Multiply(1);
|
2014-11-04 01:21:42 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @type {Tone.Add}
|
2014-11-29 21:18:04 -05:00
|
|
|
* @private
|
2014-11-04 01:21:42 -05:00
|
|
|
*/
|
2014-11-29 21:18:04 -05:00
|
|
|
this._add = this.output = new Tone.Add(0);
|
2014-06-16 19:57:55 -04:00
|
|
|
|
2014-11-29 21:18:04 -05:00
|
|
|
this._scale.connect(this._add);
|
|
|
|
this._setRange();
|
2014-06-16 19:57:55 -04:00
|
|
|
};
|
2014-04-05 18:05:42 -04:00
|
|
|
|
2014-11-30 23:26:06 -05:00
|
|
|
Tone.extend(Tone.Scale, Tone.SignalBase);
|
2014-04-05 18:05:42 -04:00
|
|
|
|
2014-06-16 19:57:55 -04:00
|
|
|
/**
|
2015-06-19 00:52:04 -04:00
|
|
|
* The minimum output value. This number is output when
|
|
|
|
* the value input value is 0.
|
2015-06-22 01:21:25 -04:00
|
|
|
* @memberOf Tone.Scale#
|
2015-02-06 17:47:26 -05:00
|
|
|
* @type {number}
|
|
|
|
* @name min
|
2014-06-16 19:57:55 -04:00
|
|
|
*/
|
2015-02-06 17:47:26 -05:00
|
|
|
Object.defineProperty(Tone.Scale.prototype, "min", {
|
|
|
|
get : function(){
|
|
|
|
return this._outputMin;
|
|
|
|
},
|
|
|
|
set : function(min){
|
|
|
|
this._outputMin = min;
|
|
|
|
this._setRange();
|
|
|
|
}
|
|
|
|
});
|
2014-06-16 19:57:55 -04:00
|
|
|
|
2015-02-02 12:50:18 -05:00
|
|
|
/**
|
2015-06-19 00:52:04 -04:00
|
|
|
* The maximum output value. This number is output when
|
|
|
|
* the value input value is 1.
|
2015-06-22 01:21:25 -04:00
|
|
|
* @memberOf Tone.Scale#
|
2015-02-06 17:47:26 -05:00
|
|
|
* @type {number}
|
|
|
|
* @name max
|
2015-02-02 12:50:18 -05:00
|
|
|
*/
|
2015-02-06 17:47:26 -05:00
|
|
|
Object.defineProperty(Tone.Scale.prototype, "max", {
|
|
|
|
get : function(){
|
|
|
|
return this._outputMax;
|
|
|
|
},
|
|
|
|
set : function(max){
|
|
|
|
this._outputMax = max;
|
|
|
|
this._setRange();
|
|
|
|
}
|
|
|
|
});
|
2015-02-02 12:50:18 -05:00
|
|
|
|
2014-06-16 19:57:55 -04:00
|
|
|
/**
|
2014-11-29 21:18:04 -05:00
|
|
|
* set the values
|
|
|
|
* @private
|
2014-06-16 19:57:55 -04:00
|
|
|
*/
|
2014-11-29 21:18:04 -05:00
|
|
|
Tone.Scale.prototype._setRange = function() {
|
2015-02-06 17:47:26 -05:00
|
|
|
this._add.value = this._outputMin;
|
|
|
|
this._scale.value = this._outputMax - this._outputMin;
|
2014-06-16 19:57:55 -04:00
|
|
|
};
|
2014-04-05 18:05:42 -04:00
|
|
|
|
2014-06-20 00:38:14 -04:00
|
|
|
/**
|
2015-06-19 00:52:04 -04:00
|
|
|
* Clean up.
|
2015-06-13 20:54:29 -04:00
|
|
|
* @returns {Tone.Scale} this
|
2014-06-20 00:38:14 -04:00
|
|
|
*/
|
|
|
|
Tone.Scale.prototype.dispose = function(){
|
2014-09-06 18:55:11 -04:00
|
|
|
Tone.prototype.dispose.call(this);
|
2014-11-29 21:18:04 -05:00
|
|
|
this._add.dispose();
|
|
|
|
this._add = null;
|
2014-06-20 00:38:14 -04:00
|
|
|
this._scale.dispose();
|
|
|
|
this._scale = null;
|
2015-02-01 22:56:33 -05:00
|
|
|
return this;
|
2014-06-20 00:38:14 -04:00
|
|
|
};
|
|
|
|
|
2014-04-05 18:05:42 -04:00
|
|
|
return Tone.Scale;
|
|
|
|
});
|