Tone.js/Tone/effect/AutoPanner.js

147 lines
3.2 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/effect/Effect", "Tone/component/LFO", "Tone/component/Panner"], function(Tone){
"use strict";
/**
2014-09-05 15:32:33 +00:00
* @class AutoPanner is a Tone.Panner with an LFO connected to the pan amount
*
* @constructor
* @extends {Tone.Effect}
2014-12-08 16:02:55 +00:00
* @param {number} [frequency=1] (optional) rate in HZ of the left-right pan
2015-02-27 21:53:10 +00:00
* @example
* var autoPanner = new Tone.AutoPanner("4n");
*/
Tone.AutoPanner = function(){
var options = this.optionsObject(arguments, ["frequency"], Tone.AutoPanner.defaults);
Tone.Effect.call(this, options);
/**
* the lfo which drives the panning
* @type {Tone.LFO}
2014-08-23 21:04:01 +00:00
* @private
*/
2015-06-07 16:12:03 +00:00
this._lfo = new Tone.LFO({
"frequency" : options.frequency,
"amplitude" : options.depth,
"min" : 0,
"max" : 1,
//start at the middle of the cycle
"phase" : 90
});
2015-02-11 19:37:48 +00:00
/**
* The amount of panning between left and right.
* 0 = always center. 1 = full range between left and right.
* @type {Tone.Signal}
*/
2015-04-24 17:13:00 +00:00
this.depth = this._lfo.amplitude;
2015-02-11 19:37:48 +00:00
/**
* the panner node which does the panning
* @type {Tone.Panner}
2014-08-23 18:24:20 +00:00
* @private
*/
2014-08-23 18:24:20 +00:00
this._panner = new Tone.Panner();
2015-02-10 16:40:27 +00:00
/**
* How fast the panner modulates
* @type {Tone.Signal}
*/
this.frequency = this._lfo.frequency;
//connections
2014-08-23 18:24:20 +00:00
this.connectEffect(this._panner);
2014-08-23 21:04:01 +00:00
this._lfo.connect(this._panner.pan);
2015-02-10 16:40:27 +00:00
this.type = options.type;
2015-04-24 17:13:00 +00:00
this._readOnly(["depth", "frequency"]);
};
//extend Effect
Tone.extend(Tone.AutoPanner, Tone.Effect);
/**
* defaults
* @static
* @type {Object}
*/
Tone.AutoPanner.defaults = {
"frequency" : 1,
2015-02-11 19:37:48 +00:00
"type" : "sine",
2015-04-24 17:13:00 +00:00
"depth" : 1
};
/**
2015-02-27 21:53:10 +00:00
* Start the panner.
2015-05-23 23:01:05 +00:00
* @param {Tone.Type.Time} [time=now] the panner begins.
2015-02-02 18:22:16 +00:00
* @returns {Tone.AutoPanner} `this`
*/
Tone.AutoPanner.prototype.start = function(time){
2014-08-23 21:04:01 +00:00
this._lfo.start(time);
2015-02-02 18:22:16 +00:00
return this;
};
/**
2015-02-27 21:53:10 +00:00
* Stop the panner.
2015-05-23 23:01:05 +00:00
* @param {Tone.Type.Time} [time=now] the panner stops.
2015-02-02 18:22:16 +00:00
* @returns {Tone.AutoPanner} `this`
*/
Tone.AutoPanner.prototype.stop = function(time){
2014-08-23 21:04:01 +00:00
this._lfo.stop(time);
2015-02-02 18:22:16 +00:00
return this;
};
2014-12-08 16:02:55 +00:00
/**
2015-02-27 21:53:10 +00:00
* Sync the panner to the transport.
2015-05-23 23:01:05 +00:00
* @param {Tone.Type.Time} [delay=0] Delay time before starting the effect after the
2015-04-24 17:13:00 +00:00
* Transport has started.
* @returns {Tone.AutoFilter} `this`
2014-12-08 16:02:55 +00:00
*/
2015-04-24 17:13:00 +00:00
Tone.AutoPanner.prototype.sync = function(delay){
this._lfo.sync(delay);
2015-02-02 18:22:16 +00:00
return this;
2014-12-08 16:02:55 +00:00
};
/**
2015-02-27 21:53:10 +00:00
* Unsync the panner from the transport
2015-02-02 18:22:16 +00:00
* @returns {Tone.AutoPanner} `this`
2014-12-08 16:02:55 +00:00
*/
Tone.AutoPanner.prototype.unsync = function(){
this._lfo.unsync();
2015-02-02 18:22:16 +00:00
return this;
2014-12-08 16:02:55 +00:00
};
/**
2015-02-10 16:40:27 +00:00
* Type of oscillator attached to the AutoPanner.
* @memberOf Tone.AutoPanner#
* @type {string}
* @name type
2014-08-25 13:57:36 +00:00
*/
2015-02-10 16:40:27 +00:00
Object.defineProperty(Tone.AutoPanner.prototype, "type", {
get : function(){
return this._lfo.type;
},
set : function(type){
this._lfo.type = type;
}
});
2014-08-25 13:57:36 +00:00
/**
* clean up
2015-02-02 18:22:16 +00:00
* @returns {Tone.AutoPanner} `this`
*/
Tone.AutoPanner.prototype.dispose = function(){
Tone.Effect.prototype.dispose.call(this);
2014-08-23 21:04:01 +00:00
this._lfo.dispose();
this._lfo = null;
2015-02-10 16:40:27 +00:00
this._panner.dispose();
2014-08-23 18:24:20 +00:00
this._panner = null;
2015-04-24 17:13:00 +00:00
this._writable(["depth", "frequency"]);
2015-02-10 16:40:27 +00:00
this.frequency = null;
2015-04-24 17:13:00 +00:00
this.depth = null;
2015-02-02 18:22:16 +00:00
return this;
};
return Tone.AutoPanner;
});