2014-11-30 02:36:32 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/component/Envelope", "Tone/signal/Scale"],
|
2014-11-04 05:44:16 +00:00
|
|
|
function(Tone){
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class An envelope which can be scaled to any range.
|
|
|
|
* Useful for applying an envelope to a filter
|
|
|
|
*
|
|
|
|
* @extends {Tone.Envelope}
|
|
|
|
* @constructor
|
2014-12-02 06:42:08 +00:00
|
|
|
* @param {Tone.Time|Object} [attack=0.01] the attack time in seconds
|
|
|
|
* @param {Tone.Time} [decay=0.1] the decay time in seconds
|
|
|
|
* @param {number} [sustain=0.5] a percentage (0-1) of the full amplitude
|
|
|
|
* @param {Tone.Time} [release=1] the release time in seconds
|
2014-11-04 05:44:16 +00:00
|
|
|
*/
|
|
|
|
Tone.ScaledEnvelope = function(){
|
|
|
|
|
|
|
|
//get all of the defaults
|
|
|
|
var options = this.optionsObject(arguments, ["attack", "decay", "sustain", "release"], Tone.Envelope.defaults);
|
|
|
|
Tone.Envelope.call(this, options);
|
|
|
|
options = this.defaultArg(options, Tone.ScaledEnvelope.defaults);
|
|
|
|
|
2014-12-06 21:48:57 +00:00
|
|
|
/**
|
|
|
|
* scale the incoming signal by an exponent
|
|
|
|
* @type {Tone.Pow}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._exp = this.output = new Tone.Pow(options.exponent);
|
|
|
|
|
2014-11-04 05:44:16 +00:00
|
|
|
/**
|
2014-11-30 02:36:32 +00:00
|
|
|
* scale the signal to the desired range
|
2014-11-04 05:44:16 +00:00
|
|
|
* @type {Tone.Multiply}
|
|
|
|
* @private
|
|
|
|
*/
|
2014-11-30 02:36:32 +00:00
|
|
|
this._scale = this.output = new Tone.Scale(options.min, options.max);
|
2014-11-04 05:44:16 +00:00
|
|
|
|
2014-12-06 21:48:57 +00:00
|
|
|
this._sig.chain(this._exp, this._scale);
|
2014-11-04 05:44:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Tone.extend(Tone.ScaledEnvelope, Tone.Envelope);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the default parameters
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
Tone.ScaledEnvelope.defaults = {
|
|
|
|
"min" : 0,
|
|
|
|
"max" : 1,
|
2014-12-06 21:48:57 +00:00
|
|
|
"exponent" : 1
|
2014-11-04 05:44:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-02-06 22:49:04 +00:00
|
|
|
* The envelope's min output value.
|
|
|
|
* @memberOf Tone.ScaledEnvelope#
|
|
|
|
* @type {number}
|
|
|
|
* @name min
|
2015-02-02 17:49:13 +00:00
|
|
|
*/
|
2015-02-06 22:49:04 +00:00
|
|
|
Object.defineProperty(Tone.ScaledEnvelope.prototype, "min", {
|
|
|
|
get : function(){
|
|
|
|
return this._scale.min;
|
|
|
|
},
|
|
|
|
set : function(min){
|
|
|
|
this._scale.min = min;
|
|
|
|
}
|
|
|
|
});
|
2014-11-04 05:44:16 +00:00
|
|
|
|
2014-12-06 21:48:57 +00:00
|
|
|
/**
|
2015-02-06 22:49:04 +00:00
|
|
|
* The envelope's max output value.
|
|
|
|
* @memberOf Tone.ScaledEnvelope#
|
|
|
|
* @type {number}
|
|
|
|
* @name max
|
2014-12-06 21:48:57 +00:00
|
|
|
*/
|
2015-02-06 22:49:04 +00:00
|
|
|
Object.defineProperty(Tone.ScaledEnvelope.prototype, "max", {
|
|
|
|
get : function(){
|
|
|
|
return this._scale.max;
|
|
|
|
},
|
|
|
|
set : function(max){
|
|
|
|
this._scale.max = max;
|
|
|
|
}
|
|
|
|
});
|
2015-02-02 17:49:13 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-06 22:49:04 +00:00
|
|
|
* the envelope's exponent
|
|
|
|
* @memberOf Tone.ScaledEnvelope#
|
|
|
|
* @type {number}
|
|
|
|
* @name exponent
|
2015-02-02 17:49:13 +00:00
|
|
|
*/
|
2015-02-06 22:49:04 +00:00
|
|
|
Object.defineProperty(Tone.ScaledEnvelope.prototype, "exponent", {
|
|
|
|
get : function(){
|
|
|
|
return this._exp.value;
|
|
|
|
},
|
|
|
|
set : function(exp){
|
|
|
|
this._exp.value = exp;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-11-04 05:44:16 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
2015-02-02 17:49:13 +00:00
|
|
|
* @returns {Tone.ScaledEnvelope} `this`
|
2014-11-04 05:44:16 +00:00
|
|
|
*/
|
|
|
|
Tone.ScaledEnvelope.prototype.dispose = function(){
|
|
|
|
Tone.Envelope.prototype.dispose.call(this);
|
2014-11-30 02:36:32 +00:00
|
|
|
this._scale.dispose();
|
|
|
|
this._scale = null;
|
2014-12-06 21:48:57 +00:00
|
|
|
this._exp.dispose();
|
|
|
|
this._exp = null;
|
2015-02-02 17:49:13 +00:00
|
|
|
return this;
|
2014-11-04 05:44:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.ScaledEnvelope;
|
|
|
|
});
|