2014-09-01 17:09:33 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/effect/StereoXFeedbackEffect", "Tone/signal/Signal", "Tone/signal/Multiply"],
|
|
|
|
function(Tone){
|
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-06-19 03:45:23 +00:00
|
|
|
/**
|
2014-09-01 17:09:33 +00:00
|
|
|
* @class PingPongDelay is a dual delay effect where the echo is heard
|
|
|
|
* first in one channel and next in the opposite channel
|
2014-06-21 21:34:31 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2014-09-01 17:09:33 +00:00
|
|
|
* @extends {Tone.StereoXFeedbackEffect}
|
2014-08-25 14:23:37 +00:00
|
|
|
* @param {Tone.Time|Object=} delayTime is the interval between consecutive echos
|
2014-06-19 03:45:23 +00:00
|
|
|
*/
|
2014-08-25 14:23:37 +00:00
|
|
|
Tone.PingPongDelay = function(){
|
2014-08-23 17:51:02 +00:00
|
|
|
|
2014-08-25 14:23:37 +00:00
|
|
|
var options = this.optionsObject(arguments, ["delayTime"], Tone.PingPongDelay.defaults);
|
2014-09-01 17:09:33 +00:00
|
|
|
Tone.StereoXFeedbackEffect.call(this, options);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the delay node on the left side
|
|
|
|
* @type {DelayNode}
|
|
|
|
* @private
|
|
|
|
*/
|
2014-10-01 23:45:30 +00:00
|
|
|
this._leftDelay = this.context.createDelay(options.maxDelayTime);
|
2014-04-06 04:12:18 +00:00
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
2014-09-01 17:09:33 +00:00
|
|
|
* the delay node on the right side
|
|
|
|
* @type {DelayNode}
|
2014-08-23 18:25:20 +00:00
|
|
|
* @private
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2014-10-01 23:45:30 +00:00
|
|
|
this._rightDelay = this.context.createDelay(options.maxDelayTime);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the predelay on the left side
|
|
|
|
* @private
|
|
|
|
* @type {DelayNode}
|
|
|
|
*/
|
|
|
|
this._leftPreDelay = this.context.createDelay(options.maxDelayTime);
|
2014-08-23 17:51:02 +00:00
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
2014-09-01 17:09:33 +00:00
|
|
|
* the delay time signal
|
|
|
|
* @type {Tone.Signal}
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2014-09-01 17:09:33 +00:00
|
|
|
this.delayTime = new Tone.Signal(0);
|
2014-08-23 17:51:02 +00:00
|
|
|
|
2014-04-06 04:12:18 +00:00
|
|
|
//connect it up
|
2014-11-30 22:37:29 +00:00
|
|
|
this.connectSeries(this.effectSendL, this._leftPreDelay, this._leftDelay, this.effectReturnL);
|
|
|
|
this.connectSeries(this.effectSendR, this._rightDelay, this.effectReturnR);
|
|
|
|
this.connectParallel(this.delayTime, this._leftDelay.delayTime, this._rightDelay.delayTime, this._leftPreDelay.delayTime);
|
2014-10-01 23:45:30 +00:00
|
|
|
//rearranged the feedback to be after the leftPreDelay
|
|
|
|
this._feedbackRL.disconnect();
|
|
|
|
this._feedbackRL.connect(this._leftDelay);
|
2014-09-01 17:09:33 +00:00
|
|
|
|
2014-08-25 14:23:37 +00:00
|
|
|
this.setDelayTime(options.delayTime);
|
2014-06-19 03:45:23 +00:00
|
|
|
};
|
2014-04-06 04:12:18 +00:00
|
|
|
|
2014-09-01 17:09:33 +00:00
|
|
|
Tone.extend(Tone.PingPongDelay, Tone.StereoXFeedbackEffect);
|
2014-04-06 04:12:18 +00:00
|
|
|
|
2014-08-25 14:23:37 +00:00
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
Tone.PingPongDelay.defaults = {
|
|
|
|
"delayTime" : 0.25,
|
2014-10-01 23:45:30 +00:00
|
|
|
"maxDelayTime" : 1
|
2014-08-25 14:23:37 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 03:45:23 +00:00
|
|
|
/**
|
|
|
|
* setDelayTime
|
|
|
|
*
|
|
|
|
* @param {Tone.Time} delayTime
|
|
|
|
*/
|
2014-04-06 04:12:18 +00:00
|
|
|
Tone.PingPongDelay.prototype.setDelayTime = function(delayTime){
|
2014-09-01 17:09:33 +00:00
|
|
|
this.delayTime.setValue(this.toSeconds(delayTime));
|
2014-06-19 03:45:23 +00:00
|
|
|
};
|
2014-04-06 04:12:18 +00:00
|
|
|
|
2014-08-25 14:23:37 +00:00
|
|
|
/**
|
|
|
|
* set all of the parameters with an object
|
|
|
|
* @param {Object} params
|
|
|
|
*/
|
|
|
|
Tone.PingPongDelay.prototype.set = function(params){
|
|
|
|
if (!this.isUndef(params.delayTime)) this.setDelayTime(params.delayTime);
|
2014-09-01 17:09:33 +00:00
|
|
|
Tone.StereoXFeedbackEffect.prototype.set.call(this, params);
|
2014-08-25 14:23:37 +00:00
|
|
|
};
|
|
|
|
|
2014-08-20 21:10:12 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
|
|
|
*/
|
|
|
|
Tone.PingPongDelay.prototype.dispose = function(){
|
2014-09-01 17:09:33 +00:00
|
|
|
Tone.StereoXFeedbackEffect.prototype.dispose.call(this);
|
|
|
|
this._leftDelay.disconnect();
|
|
|
|
this._rightDelay.disconnect();
|
2014-10-02 17:15:38 +00:00
|
|
|
this._leftPreDelay.disconnect();
|
2014-09-01 17:09:33 +00:00
|
|
|
this.delayTime.dispose();
|
|
|
|
this._leftDelay = null;
|
|
|
|
this._rightDelay = null;
|
2014-10-02 17:15:38 +00:00
|
|
|
this._leftPreDelay = null;
|
2014-09-01 17:09:33 +00:00
|
|
|
this.delayTime = null;
|
2014-08-20 21:10:12 +00:00
|
|
|
};
|
|
|
|
|
2014-04-06 04:12:18 +00:00
|
|
|
return Tone.PingPongDelay;
|
|
|
|
});
|