2015-03-02 00:49:01 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/effect/StereoXFeedbackEffect", "Tone/signal/Signal"],
|
2014-09-01 17:09:33 +00:00
|
|
|
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}
|
2015-06-14 00:20:36 +00:00
|
|
|
* @param {Time|Object} [delayTime=0.25] is the interval between consecutive echos
|
2015-02-27 21:53:10 +00:00
|
|
|
* @param {number=} feedback The amount of the effected signal which
|
|
|
|
* is fed back through the delay.
|
|
|
|
* @example
|
|
|
|
* var pingPong = new Tone.PingPongDelay("4n", 0.2);
|
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
|
|
|
|
2015-02-27 21:53:10 +00:00
|
|
|
var options = this.optionsObject(arguments, ["delayTime", "feedback"], 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);
|
|
|
|
|
2015-03-02 00:49:01 +00:00
|
|
|
/**
|
|
|
|
* the predelay on the right side
|
|
|
|
* @type {DelayNode}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._rightPreDelay = this.context.createDelay(options.maxDelayTime);
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
2014-09-01 17:09:33 +00:00
|
|
|
* the delay time signal
|
2015-06-13 23:50:39 +00:00
|
|
|
* @type {Time}
|
|
|
|
* @signal
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2015-05-23 22:57:05 +00:00
|
|
|
this.delayTime = new Tone.Signal(options.delayTime, Tone.Type.Time);
|
2014-08-23 17:51:02 +00:00
|
|
|
|
2014-04-06 04:12:18 +00:00
|
|
|
//connect it up
|
2015-02-13 21:10:45 +00:00
|
|
|
this.effectSendL.chain(this._leftDelay, this.effectReturnL);
|
2015-03-02 00:49:01 +00:00
|
|
|
this.effectSendR.chain(this._rightPreDelay, this._rightDelay, this.effectReturnR);
|
|
|
|
this.delayTime.fan(this._leftDelay.delayTime, this._rightDelay.delayTime, this._rightPreDelay.delayTime);
|
|
|
|
//rearranged the feedback to be after the rightPreDelay
|
|
|
|
this._feedbackLR.disconnect();
|
|
|
|
this._feedbackLR.connect(this._rightDelay);
|
2015-04-18 14:54:08 +00:00
|
|
|
this._readOnly(["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-08-20 21:10:12 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
2015-02-02 18:22:16 +00:00
|
|
|
* @returns {Tone.PingPongDelay} `this`
|
2014-08-20 21:10:12 +00:00
|
|
|
*/
|
|
|
|
Tone.PingPongDelay.prototype.dispose = function(){
|
2014-09-01 17:09:33 +00:00
|
|
|
Tone.StereoXFeedbackEffect.prototype.dispose.call(this);
|
|
|
|
this._leftDelay.disconnect();
|
|
|
|
this._leftDelay = null;
|
2015-02-13 21:10:45 +00:00
|
|
|
this._rightDelay.disconnect();
|
2014-09-01 17:09:33 +00:00
|
|
|
this._rightDelay = null;
|
2015-03-02 00:49:01 +00:00
|
|
|
this._rightPreDelay.disconnect();
|
|
|
|
this._rightPreDelay = null;
|
2015-04-18 14:54:08 +00:00
|
|
|
this._writable(["delayTime"]);
|
2015-02-13 21:10:45 +00:00
|
|
|
this.delayTime.dispose();
|
2014-09-01 17:09:33 +00:00
|
|
|
this.delayTime = null;
|
2015-02-02 18:22:16 +00:00
|
|
|
return this;
|
2014-08-20 21:10:12 +00:00
|
|
|
};
|
|
|
|
|
2014-04-06 04:12:18 +00:00
|
|
|
return Tone.PingPongDelay;
|
|
|
|
});
|