2014-04-06 20:51:30 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Signal", "Tone/signal/Scale"], function(Tone){
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-06-15 23:08:32 +00:00
|
|
|
/**
|
|
|
|
* DRY/WET KNOB
|
|
|
|
*
|
|
|
|
* equal power fading control values:
|
2014-06-20 04:57:56 +00:00
|
|
|
* 0 = 100% dry - 0% wet
|
|
|
|
* 1 = 0% dry - 100% wet
|
2014-06-15 23:08:32 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2014-06-20 15:16:09 +00:00
|
|
|
* @param {number=} initialDry
|
2014-06-15 23:08:32 +00:00
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.DryWet = function(initialDry){
|
|
|
|
Tone.call(this);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-06-20 05:12:15 +00:00
|
|
|
/**
|
|
|
|
* connect this input to the dry signal
|
|
|
|
* the dry signal is also the default input
|
|
|
|
*
|
|
|
|
* @type {GainNode}
|
|
|
|
*/
|
|
|
|
this.dry = this.input;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* connect this input to the wet signal
|
|
|
|
*
|
|
|
|
* @type {GainNode}
|
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
this.wet = this.context.createGain();
|
2014-06-20 05:12:15 +00:00
|
|
|
/**
|
|
|
|
* controls the amount of wet signal
|
|
|
|
* which is mixed into the dry signal
|
|
|
|
*
|
2014-06-20 15:16:09 +00:00
|
|
|
* @type {Tone.Signal}
|
2014-06-20 05:12:15 +00:00
|
|
|
*/
|
2014-06-20 15:16:09 +00:00
|
|
|
this.wetness = new Tone.Signal();
|
2014-06-20 05:12:15 +00:00
|
|
|
/**
|
|
|
|
* invert the incoming signal
|
|
|
|
* @private
|
|
|
|
* @type {Tone}
|
|
|
|
*/
|
|
|
|
this._invert = new Tone.Scale(0, 1, 1, 0);
|
2014-04-04 18:36:01 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
//connections
|
|
|
|
this.dry.connect(this.output);
|
|
|
|
this.wet.connect(this.output);
|
2014-04-06 00:47:59 +00:00
|
|
|
//wet control
|
2014-06-21 17:05:41 +00:00
|
|
|
this.chain(this.wetness, this.wet.gain);
|
|
|
|
//dry control is the inverse of the wet
|
|
|
|
this.chain(this.wetness, this._invert, this.dry.gain);
|
2014-06-20 05:46:10 +00:00
|
|
|
|
|
|
|
this.dry.gain.value = 0;
|
|
|
|
this.wet.gain.value = 0;
|
2014-06-20 15:16:09 +00:00
|
|
|
|
|
|
|
this.setDry(this.defaultArg(initialDry, 0));
|
2014-06-15 23:08:32 +00:00
|
|
|
};
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.extend(Tone.DryWet);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-06-15 23:08:32 +00:00
|
|
|
/**
|
2014-06-20 05:12:15 +00:00
|
|
|
* Set the dry value
|
2014-06-15 23:08:32 +00:00
|
|
|
*
|
|
|
|
* @param {number} val
|
2014-06-20 15:16:09 +00:00
|
|
|
* @param {Tone.Time=} rampTime
|
2014-06-15 23:08:32 +00:00
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.DryWet.prototype.setDry = function(val, rampTime){
|
2014-06-21 17:05:41 +00:00
|
|
|
this.setWet(1-val, rampTime);
|
2014-06-15 23:08:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-06-20 05:12:15 +00:00
|
|
|
* Set the wet value
|
2014-06-15 23:08:32 +00:00
|
|
|
*
|
|
|
|
* @param {number} val
|
2014-06-20 15:16:09 +00:00
|
|
|
* @param {Tone.Time=} rampTime
|
2014-06-15 23:08:32 +00:00
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.DryWet.prototype.setWet = function(val, rampTime){
|
2014-06-21 17:05:41 +00:00
|
|
|
if (rampTime){
|
|
|
|
this.wetness.linearRampToValueNow(val, rampTime);
|
|
|
|
} else {
|
|
|
|
this.wetness.setValue(val);
|
|
|
|
}
|
2014-06-15 23:08:32 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2014-06-20 05:12:15 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
|
|
|
*/
|
|
|
|
Tone.DryWet.prototype.dispose = function(){
|
|
|
|
this.dry.disconnect();
|
|
|
|
this.wet.disconnect();
|
|
|
|
this.wetness.dispose();
|
|
|
|
this._invert.dispose();
|
|
|
|
this.output.disconnect();
|
|
|
|
this.dry = null;
|
|
|
|
this.wet = null;
|
|
|
|
this.wetness = null;
|
|
|
|
this._invert = null;
|
|
|
|
this.output = null;
|
|
|
|
};
|
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
return Tone.DryWet;
|
|
|
|
});
|