Tone.js/src/effects/Effect.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-03-11 04:54:40 +00:00
///////////////////////////////////////////////////////////////////////////////
//
// EFFECTS UNIT
//
// connect the effect to the effectSend and to the effectReturn
///////////////////////////////////////////////////////////////////////////////
2014-03-16 17:33:56 +00:00
Tone.Effect = function(){
2014-03-11 04:54:40 +00:00
//extends Unit
2014-03-16 17:33:56 +00:00
Tone.call(this);
2014-03-11 23:27:46 +00:00
//components
this.dry = this.context.createGain();
this.effectSend = this.context.createGain();
this.effectReturn = this.context.createGain();
2014-03-11 23:27:46 +00:00
2014-03-11 04:54:40 +00:00
//connections
this.input.connect(this.dry);
this.dry.connect(this.output);
this.input.connect(this.effectSend);
this.effectReturn.connect(this.output);
2014-03-15 05:02:33 +00:00
2014-03-11 23:27:46 +00:00
//some initial values
this.setDry(.5);
2014-03-11 04:54:40 +00:00
}
2014-03-16 17:33:56 +00:00
Tone.extend(Tone.Effect, Tone);
2014-03-11 04:54:40 +00:00
//adjust the dry/wet balance
//dryness 0-1
2014-03-16 17:33:56 +00:00
Tone.Effect.prototype.setDry = function(dryness, duration){
duration = this.defaultArg(duration, this.fadeTime);
2014-03-11 23:27:46 +00:00
var dryGain = this.equalPowerGain(dryness);
var wetGain = this.equalPowerGain(1 - dryness);
this.rampToValue(this.dry.gain, dryGain, duration);
this.rampToValue(this.effectSend.gain, wetGain, duration);
2014-03-11 04:54:40 +00:00
}
//adjust the wet/dry balance
2014-03-16 17:33:56 +00:00
Tone.Effect.prototype.setWet = function(wetness, duration){
2014-03-11 04:54:40 +00:00
this.setDry(1 - wetness);
}
2014-03-16 17:33:56 +00:00
Tone.Effect.prototype.bypass = function(){
2014-03-11 04:54:40 +00:00
this.setDry(1);
}
2014-03-16 17:33:56 +00:00
Tone.Effect.prototype.connectEffect = function(effect){
this.chain(this.effectSend, effect, this.effectReturn);
2014-03-11 04:54:40 +00:00
}