2014-06-21 21:34:31 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/effect/Effect", "Tone/component/LFO", "Tone/component/Panner"], function(Tone){
|
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
2014-09-05 15:32:33 +00:00
|
|
|
* @class AutoPanner is a Tone.Panner with an LFO connected to the pan amount
|
2014-06-21 21:34:31 +00:00
|
|
|
*
|
|
|
|
* @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");
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2014-08-24 23:28:42 +00:00
|
|
|
Tone.AutoPanner = function(){
|
|
|
|
|
2014-08-25 14:23:37 +00:00
|
|
|
var options = this.optionsObject(arguments, ["frequency"], Tone.AutoPanner.defaults);
|
2014-08-24 23:28:42 +00:00
|
|
|
Tone.Effect.call(this, options);
|
2014-06-21 21:34:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the lfo which drives the panning
|
|
|
|
* @type {Tone.LFO}
|
2014-08-23 21:04:01 +00:00
|
|
|
* @private
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2014-08-25 14:23:37 +00:00
|
|
|
this._lfo = new Tone.LFO(options.frequency, 0, 1);
|
2014-06-21 21:34:31 +00:00
|
|
|
|
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
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* the panner node which does the panning
|
|
|
|
* @type {Tone.Panner}
|
2014-08-23 18:24:20 +00:00
|
|
|
* @private
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2014-08-23 18:24:20 +00:00
|
|
|
this._panner = new Tone.Panner();
|
2014-06-21 21:34:31 +00:00
|
|
|
|
2015-02-10 16:40:27 +00:00
|
|
|
/**
|
|
|
|
* How fast the panner modulates
|
|
|
|
* @type {Tone.Signal}
|
|
|
|
*/
|
|
|
|
this.frequency = this._lfo.frequency;
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
//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"]);
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//extend Effect
|
|
|
|
Tone.extend(Tone.AutoPanner, Tone.Effect);
|
2014-08-24 23:28:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* defaults
|
|
|
|
* @static
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2014-08-25 14:23:37 +00:00
|
|
|
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
|
2014-08-24 23:28:42 +00:00
|
|
|
};
|
2014-06-21 21:34:31 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-27 21:53:10 +00:00
|
|
|
* Start the panner.
|
2014-12-02 06:42:08 +00:00
|
|
|
* @param {Tone.Time} [time=now] the panner begins.
|
2015-02-02 18:22:16 +00:00
|
|
|
* @returns {Tone.AutoPanner} `this`
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
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;
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-02-27 21:53:10 +00:00
|
|
|
* Stop the panner.
|
2014-12-02 06:42:08 +00:00
|
|
|
* @param {Tone.Time} [time=now] the panner stops.
|
2015-02-02 18:22:16 +00:00
|
|
|
* @returns {Tone.AutoPanner} `this`
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
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-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
2014-12-08 16:02:55 +00:00
|
|
|
/**
|
2015-02-27 21:53:10 +00:00
|
|
|
* Sync the panner to the transport.
|
2015-04-24 17:13:00 +00:00
|
|
|
* @param {Tone.Time} [delay=0] Delay time before starting the effect after the
|
|
|
|
* 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
|
|
|
};
|
|
|
|
|
2014-06-21 21:34:31 +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
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
2015-02-02 18:22:16 +00:00
|
|
|
* @returns {Tone.AutoPanner} `this`
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
Tone.AutoPanner.prototype.dispose = function(){
|
2014-08-23 19:51:21 +00:00
|
|
|
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;
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.AutoPanner;
|
|
|
|
});
|