UNPKG

1.69 kBPlain TextView Raw
1import { Panner } from "../component/channel/Panner.js";
2import { optionsFromArguments } from "../core/util/Defaults.js";
3import { LFOEffect, LFOEffectOptions } from "./LFOEffect.js";
4import { Frequency } from "../core/type/Units.js";
5
6export interface AutoPannerOptions extends LFOEffectOptions {
7 channelCount: number;
8}
9
10/**
11 * AutoPanner is a {@link Panner} with an {@link LFO} connected to the pan amount.
12 * [Related Reading](https://www.ableton.com/en/blog/autopan-chopper-effect-and-more-liveschool/).
13 *
14 * @example
15 * // create an autopanner and start it
16 * const autoPanner = new Tone.AutoPanner("4n").toDestination().start();
17 * // route an oscillator through the panner and start it
18 * const oscillator = new Tone.Oscillator().connect(autoPanner).start();
19 * @category Effect
20 */
21export class AutoPanner extends LFOEffect<AutoPannerOptions> {
22 readonly name: string = "AutoPanner";
23
24 /**
25 * The filter node
26 */
27 readonly _panner: Panner;
28
29 /**
30 * @param frequency Rate of left-right oscillation.
31 */
32 constructor(frequency?: Frequency);
33 constructor(options?: Partial<AutoPannerOptions>);
34 constructor() {
35 const options = optionsFromArguments(
36 AutoPanner.getDefaults(),
37 arguments,
38 ["frequency"]
39 );
40 super(options);
41
42 this._panner = new Panner({
43 context: this.context,
44 channelCount: options.channelCount,
45 });
46 // connections
47 this.connectEffect(this._panner);
48 this._lfo.connect(this._panner.pan);
49 this._lfo.min = -1;
50 this._lfo.max = 1;
51 }
52
53 static getDefaults(): AutoPannerOptions {
54 return Object.assign(LFOEffect.getDefaults(), {
55 channelCount: 1,
56 });
57 }
58
59 dispose(): this {
60 super.dispose();
61 this._panner.dispose();
62 return this;
63 }
64}