2014-06-21 21:34:31 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/component/DryWet"], function(Tone){
|
2014-09-04 04:41:40 +00:00
|
|
|
|
|
|
|
"use strict";
|
2014-06-21 21:34:31 +00:00
|
|
|
|
|
|
|
/**
|
2014-08-23 17:50:13 +00:00
|
|
|
* @class Effect is the base class for effects. connect the effect between
|
2014-09-05 15:32:33 +00:00
|
|
|
* the effectSend and effectReturn GainNodes. then control the amount of
|
|
|
|
* effect which goes to the output using the dry/wet control.
|
2014-06-21 21:34:31 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
2014-08-23 18:22:51 +00:00
|
|
|
* @param {number=} [initalDry=0] the starting dry value
|
|
|
|
* defaults to 100% wet
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2014-08-24 23:28:42 +00:00
|
|
|
Tone.Effect = function(){
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
Tone.call(this);
|
|
|
|
|
2014-08-24 23:28:42 +00:00
|
|
|
//get all of the defaults
|
2014-08-25 14:23:37 +00:00
|
|
|
var options = this.optionsObject(arguments, ["dry"], Tone.Effect.defaults);
|
2014-08-24 23:28:42 +00:00
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* the drywet knob to control the amount of effect
|
|
|
|
*
|
|
|
|
* @type {Tone.DryWet}
|
|
|
|
*/
|
|
|
|
this.dryWet = new Tone.DryWet();
|
2014-08-21 00:46:57 +00:00
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* connect the effectSend to the input of hte effect
|
|
|
|
*
|
|
|
|
* @type {GainNode}
|
|
|
|
*/
|
|
|
|
this.effectSend = this.context.createGain();
|
2014-08-21 00:46:57 +00:00
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* connect the output of the effect to the effectReturn
|
|
|
|
*
|
|
|
|
* @type {GainNode}
|
|
|
|
*/
|
|
|
|
this.effectReturn = this.context.createGain();
|
|
|
|
|
|
|
|
//connections
|
|
|
|
this.input.connect(this.dryWet.dry);
|
|
|
|
this.input.connect(this.effectSend);
|
|
|
|
this.effectReturn.connect(this.dryWet.wet);
|
|
|
|
this.dryWet.connect(this.output);
|
2014-08-21 00:46:57 +00:00
|
|
|
//setup values
|
2014-08-24 23:28:42 +00:00
|
|
|
this.setDry(options.dry);
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Tone.extend(Tone.Effect);
|
|
|
|
|
2014-08-24 23:28:42 +00:00
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2014-08-25 14:23:37 +00:00
|
|
|
Tone.Effect.defaults = {
|
2014-08-24 23:28:42 +00:00
|
|
|
"dry" : 0
|
|
|
|
};
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* setDry adjusts the dry / wet balance
|
|
|
|
* dryness is 0 (100% wet) to 1 (100% dry)
|
|
|
|
*
|
|
|
|
* @param {number} dryness
|
|
|
|
* @param {Tone.Time=} rampTime
|
|
|
|
*/
|
|
|
|
Tone.Effect.prototype.setDry = function(dryness, rampTime){
|
|
|
|
this.dryWet.setDry(dryness, rampTime);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* setWet also adjusts the dry / wet balance
|
|
|
|
* wetVal is 0 (100% dry) to 1 (100% wet)
|
|
|
|
*
|
|
|
|
* @param {number} wetness
|
|
|
|
* @param {Tone.Time=} rampTime
|
|
|
|
*/
|
|
|
|
Tone.Effect.prototype.setWet = function(wetVal, rampTime){
|
|
|
|
this.dryWet.setWet(wetVal, rampTime);
|
|
|
|
};
|
|
|
|
|
2014-08-24 23:28:42 +00:00
|
|
|
/**
|
|
|
|
* set in bulk
|
|
|
|
* @param {Object} param
|
|
|
|
*/
|
2014-08-25 13:57:36 +00:00
|
|
|
Tone.Effect.prototype.set = function(params){
|
|
|
|
if (!this.isUndef(params.dry)) this.setDry(params.dry);
|
|
|
|
if (!this.isUndef(params.wet)) this.setWet(params.wet);
|
2014-08-24 23:28:42 +00:00
|
|
|
};
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* bypass the effect
|
|
|
|
*/
|
|
|
|
Tone.Effect.prototype.bypass = function(){
|
|
|
|
this.setDry(1);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* chains the effect in between the effectSend and effectReturn
|
|
|
|
* @param {Tone} effect
|
2014-10-19 21:56:41 +00:00
|
|
|
* @internal
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
Tone.Effect.prototype.connectEffect = function(effect){
|
2014-12-01 02:32:09 +00:00
|
|
|
this.effectSend.chain(effect, this.effectReturn);
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
2014-09-04 18:04:58 +00:00
|
|
|
/**
|
|
|
|
* set the preset if it exists
|
|
|
|
* @param {string} presetName the name of the preset
|
|
|
|
*/
|
|
|
|
Tone.Effect.prototype.setPreset = function(presetName){
|
|
|
|
if (!this.isUndef(this.preset) && this.preset.hasOwnProperty(presetName)){
|
|
|
|
this.set(this.preset[presetName]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* tear down
|
|
|
|
*/
|
|
|
|
Tone.Effect.prototype.dispose = function(){
|
2014-08-23 19:51:21 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2014-06-21 21:34:31 +00:00
|
|
|
this.dryWet.dispose();
|
|
|
|
this.dryWet = null;
|
2014-10-23 15:41:38 +00:00
|
|
|
this.effectSend.disconnect();
|
2014-06-21 21:34:31 +00:00
|
|
|
this.effectSend = null;
|
2014-10-23 15:41:38 +00:00
|
|
|
this.effectReturn.disconnect();
|
2014-06-21 21:34:31 +00:00
|
|
|
this.effectReturn = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Effect;
|
|
|
|
});
|