Tone.js/Tone/effect/PingPongDelay.js

91 lines
2.5 KiB
JavaScript
Raw Normal View History

2015-03-02 00:49:01 +00:00
define(["Tone/core/Tone", "Tone/effect/StereoXFeedbackEffect", "Tone/signal/Signal"],
function(Tone){
"use strict";
/**
* @class PingPongDelay is a dual delay effect where the echo is heard
* first in one channel and next in the opposite channel
*
* @constructor
* @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);
*/
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);
Tone.StereoXFeedbackEffect.call(this, options);
/**
* the delay node on the left side
* @type {DelayNode}
* @private
*/
this._leftDelay = this.context.createDelay(options.maxDelayTime);
/**
* the delay node on the right side
* @type {DelayNode}
2014-08-23 18:25:20 +00:00
* @private
*/
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);
/**
* the delay time signal
2015-06-13 23:50:39 +00:00
* @type {Time}
* @signal
*/
this.delayTime = new Tone.Signal(options.delayTime, Tone.Type.Time);
2014-08-23 17:51:02 +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"]);
};
Tone.extend(Tone.PingPongDelay, Tone.StereoXFeedbackEffect);
/**
* @static
* @type {Object}
*/
Tone.PingPongDelay.defaults = {
"delayTime" : 0.25,
"maxDelayTime" : 1
};
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(){
Tone.StereoXFeedbackEffect.prototype.dispose.call(this);
this._leftDelay.disconnect();
this._leftDelay = null;
2015-02-13 21:10:45 +00:00
this._rightDelay.disconnect();
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();
this.delayTime = null;
2015-02-02 18:22:16 +00:00
return this;
2014-08-20 21:10:12 +00:00
};
return Tone.PingPongDelay;
});