Tone.js/Tone/core/Delay.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-10-21 14:04:55 +00:00
define(["Tone/core/Tone", "Tone/core/Param"], function (Tone) {
2015-08-15 23:30:33 +00:00
2015-10-21 16:11:19 +00:00
"use strict";
2015-08-15 23:30:33 +00:00
/**
* @class Wrapper around Web Audio's native [DelayNode](http://webaudio.github.io/web-audio-api/#the-delaynode-interface).
* @extends {Tone}
2015-11-02 14:31:12 +00:00
* @param {Time=} delayTime The delay applied to the incoming signal.
2015-10-21 14:04:55 +00:00
* @param {Time=} maxDelay The maximum delay time.
2015-08-15 23:30:33 +00:00
*/
Tone.Delay = function(){
2015-11-02 14:31:12 +00:00
var options = this.optionsObject(arguments, ["delayTime", "maxDelay"], Tone.Delay.defaults);
2015-08-15 23:30:33 +00:00
/**
* The native delay node
* @type {DelayNode}
* @private
*/
2015-11-02 14:31:12 +00:00
this._delayNode = this.input = this.output = this.context.createDelay(this.toSeconds(options.maxDelay));
2015-08-15 23:30:33 +00:00
/**
* The amount of time the incoming signal is
* delayed.
2015-11-02 14:31:12 +00:00
* @type {Tone.Param}
2015-08-15 23:30:33 +00:00
* @signal
*/
2015-11-02 14:31:12 +00:00
this.delayTime = new Tone.Param({
"param" : this._delayNode.delayTime,
"units" : Tone.Type.Time,
"value" : options.delayTime
});
2015-08-15 23:30:33 +00:00
this._readOnly("delayTime");
};
2015-11-02 14:31:12 +00:00
Tone.extend(Tone.Delay);
2015-08-15 23:30:33 +00:00
/**
* The defaults
* @const
* @type {Object}
*/
Tone.Delay.defaults = {
"maxDelay" : 1,
2015-11-02 14:31:12 +00:00
"delayTime" : 0
2015-08-15 23:30:33 +00:00
};
2015-10-21 14:04:55 +00:00
2015-08-15 23:30:33 +00:00
/**
* Clean up.
* @return {Tone.Delay} this
*/
Tone.Delay.prototype.dispose = function(){
2015-10-21 14:04:55 +00:00
Tone.Param.prototype.dispose.call(this);
2015-08-15 23:30:33 +00:00
this._delayNode.disconnect();
this._delayNode = null;
this._writable("delayTime");
this.delayTime = null;
return this;
};
return Tone.Delay;
});