Tone.js/Tone/effect/AutoPanner.ts

52 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-10-28 21:53:51 +00:00
import { Panner } from "../component/channel/Panner";
import { optionsFromArguments } from "../core/util/Defaults";
2019-10-28 21:50:31 +00:00
import { LFOEffect, LFOEffectOptions } from "./LFOEffect";
2019-10-28 21:53:51 +00:00
import { Frequency } from "../core/type/Units";
2019-10-28 21:50:31 +00:00
export type AutoPannerOptions = LFOEffectOptions;
/**
2019-10-28 21:53:51 +00:00
* AutoPanner is a [[Panner]] with an [[LFO]] connected to the pan amount.
2019-10-28 21:50:31 +00:00
* [Related Reading](https://www.ableton.com/en/blog/autopan-chopper-effect-and-more-liveschool/).
*
* @example
2019-10-29 01:28:53 +00:00
* // create an autopanner and start it
* const autoPanner = new Tone.AutoPanner("4n").toDestination().start();
2019-10-28 21:50:31 +00:00
* // route an oscillator through the panner and start it
* const oscillator = new Tone.Oscillator().connect(autoPanner).start();
2019-10-30 03:12:51 +00:00
* @category Effect
2019-10-28 21:50:31 +00:00
*/
export class AutoPanner extends LFOEffect<AutoPannerOptions> {
2019-10-28 21:50:31 +00:00
readonly name: string = "AutoPanner";
2019-10-28 21:50:31 +00:00
/**
* The filter node
*/
readonly _panner: Panner;
2019-10-28 21:50:31 +00:00
/**
* @param frequency Rate of left-right oscillation.
*/
constructor(frequency?: Frequency);
constructor(options?: Partial<AutoPannerOptions>);
constructor() {
super(optionsFromArguments(AutoPanner.getDefaults(), arguments, ["frequency"]));
this._panner = new Panner({ context: this.context });
// connections
this.connectEffect(this._panner);
this._lfo.connect(this._panner.pan);
this._lfo.min = -1;
this._lfo.max = 1;
}
dispose(): this {
2019-10-28 21:50:31 +00:00
super.dispose();
this._panner.dispose();
return this;
}
}