2015-02-02 17:48:04 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/component/CrossFade"], 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}
|
2015-02-02 17:48:04 +00:00
|
|
|
* @param {number} [initialWet=0] the starting wet 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
|
2015-02-02 17:48:04 +00:00
|
|
|
var options = this.optionsObject(arguments, ["wet"], 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
|
2015-02-02 17:48:04 +00:00
|
|
|
* @type {Tone.CrossFade}
|
2015-02-25 05:57:00 +00:00
|
|
|
* @private
|
2015-02-02 17:48:04 +00:00
|
|
|
*/
|
2015-02-25 05:57:00 +00:00
|
|
|
this._dryWet = new Tone.CrossFade(options.wet);
|
2015-02-02 17:48:04 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-10 16:40:27 +00:00
|
|
|
* The wet control, i.e. how much of the effected
|
|
|
|
* will pass through to the output.
|
2015-02-02 17:48:04 +00:00
|
|
|
* @type {Tone.Signal}
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2015-02-25 05:57:00 +00:00
|
|
|
this.wet = this._dryWet.fade;
|
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}
|
2015-02-27 21:53:10 +00:00
|
|
|
* @private
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
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}
|
2015-02-27 21:53:10 +00:00
|
|
|
* @private
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
this.effectReturn = this.context.createGain();
|
|
|
|
|
|
|
|
//connections
|
2015-02-25 05:57:00 +00:00
|
|
|
this.input.connect(this._dryWet.a);
|
2014-06-21 21:34:31 +00:00
|
|
|
this.input.connect(this.effectSend);
|
2015-02-25 05:57:00 +00:00
|
|
|
this.effectReturn.connect(this._dryWet.b);
|
|
|
|
this._dryWet.connect(this.output);
|
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 = {
|
2015-02-02 17:48:04 +00:00
|
|
|
"wet" : 1
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bypass the effect
|
2015-02-02 17:48:04 +00:00
|
|
|
* @returns {Tone.Effect} `this`
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
Tone.Effect.prototype.bypass = function(){
|
2015-02-23 05:32:33 +00:00
|
|
|
this.wet.value = 0;
|
2015-02-02 17:48:04 +00:00
|
|
|
return this;
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* chains the effect in between the effectSend and effectReturn
|
|
|
|
* @param {Tone} effect
|
2015-02-25 21:19:43 +00:00
|
|
|
* @private
|
2015-02-02 17:48:04 +00:00
|
|
|
* @returns {Tone.Effect} `this`
|
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);
|
2015-02-02 17:48:04 +00:00
|
|
|
return this;
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tear down
|
2015-02-02 17:48:04 +00:00
|
|
|
* @returns {Tone.Effect} `this`
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
Tone.Effect.prototype.dispose = function(){
|
2014-08-23 19:51:21 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2015-02-25 05:57:00 +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;
|
2015-02-02 17:48:04 +00:00
|
|
|
this.wet = null;
|
|
|
|
return this;
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Effect;
|
|
|
|
});
|