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";
|
|
|
|
|
|
|
|
/**
|
2015-07-02 00:19:58 +00:00
|
|
|
* @class Tone.ScaledEnvelop is an envelope which can be scaled
|
|
|
|
* to any range. It's useful for applying an envelope
|
|
|
|
* to a frequency or any other non-NormalRange signal
|
|
|
|
* parameter.
|
2014-11-04 05:44:16 +00:00
|
|
|
*
|
|
|
|
* @extends {Tone.Envelope}
|
|
|
|
* @constructor
|
2015-06-20 23:25:49 +00:00
|
|
|
* @param {Time|Object} [attack] the attack time in seconds
|
|
|
|
* @param {Time} [decay] the decay time in seconds
|
|
|
|
* @param {number} [sustain] a percentage (0-1) of the full amplitude
|
|
|
|
* @param {Time} [release] the release time in seconds
|
2015-02-27 21:53:10 +00:00
|
|
|
* @example
|
|
|
|
* var scaledEnv = new Tone.ScaledEnvelope({
|
|
|
|
* "attack" : 0.2,
|
|
|
|
* "min" : 200,
|
|
|
|
* "max" : 2000
|
|
|
|
* });
|
|
|
|
* scaledEnv.connect(oscillator.frequency);
|
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-27 21:53:10 +00:00
|
|
|
* The envelope's min output value. This is the value which it
|
|
|
|
* starts at.
|
2015-02-06 22:49:04 +00:00
|
|
|
* @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-27 21:53:10 +00:00
|
|
|
* The envelope's max output value. In other words, the value
|
|
|
|
* at the peak of the attack portion of the envelope.
|
2015-02-06 22:49:04 +00:00
|
|
|
* @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-27 21:53:10 +00:00
|
|
|
* The envelope's exponent value.
|
2015-02-06 22:49:04 +00:00
|
|
|
* @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-06-14 00:54:29 +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;
|
|
|
|
});
|