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
|
|
|
/**
|
2015-02-27 18:40:35 +00:00
|
|
|
* @class Performs a linear scaling on an input signal.
|
2015-06-19 04:52:04 +00:00
|
|
|
* Scales a NormalRange input 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}
|
2015-06-19 04:52:04 +00: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 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
|
|
|
*/
|
2014-11-30 02:18:04 +00:00
|
|
|
Tone.Scale = function(outputMin, outputMax){
|
2014-06-16 23:57:55 +00:00
|
|
|
|
2017-04-26 03:45:37 +00:00
|
|
|
Tone.SignalBase.call(this);
|
|
|
|
|
2014-11-04 06:21:42 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2017-04-30 19:03:49 +00:00
|
|
|
this._outputMin = Tone.defaultArg(outputMin, 0);
|
2014-11-04 06:21:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2017-04-30 19:03:49 +00:00
|
|
|
this._outputMax = Tone.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
|
|
|
/**
|
2015-06-19 04:52:04 +00:00
|
|
|
* The minimum output value. This number is output when
|
|
|
|
* the value input value is 0.
|
2015-06-22 05:21:25 +00:00
|
|
|
* @memberOf Tone.Scale#
|
2015-02-06 22:47:26 +00:00
|
|
|
* @type {number}
|
|
|
|
* @name min
|
2014-06-16 23:57:55 +00:00
|
|
|
*/
|
2015-02-06 22:47:26 +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
|
|
|
/**
|
2015-06-19 04:52:04 +00:00
|
|
|
* The maximum output value. This number is output when
|
|
|
|
* the value input value is 1.
|
2015-06-22 05:21:25 +00:00
|
|
|
* @memberOf Tone.Scale#
|
2015-02-06 22:47:26 +00:00
|
|
|
* @type {number}
|
|
|
|
* @name max
|
2015-02-02 17:50:18 +00:00
|
|
|
*/
|
2015-02-06 22:47:26 +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
|
|
|
/**
|
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() {
|
2015-02-06 22:47:26 +00:00
|
|
|
this._add.value = this._outputMin;
|
|
|
|
this._scale.value = 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
|
|
|
/**
|
2015-06-19 04:52:04 +00:00
|
|
|
* Clean up.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Scale} this
|
2014-06-20 04:38:14 +00:00
|
|
|
*/
|
|
|
|
Tone.Scale.prototype.dispose = function(){
|
2017-04-26 03:45:37 +00:00
|
|
|
Tone.SignalBase.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;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-20 04:38:14 +00:00
|
|
|
};
|
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
return Tone.Scale;
|
|
|
|
});
|