Tone.js/Tone/effect/AutoPanner.ts

69 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-05-03 14:10:40 +00:00
import { Panner } from "../component/channel/Panner.js";
import { optionsFromArguments } from "../core/util/Defaults.js";
import { LFOEffect, LFOEffectOptions } from "./LFOEffect.js";
import { Frequency } from "../core/type/Units.js";
2019-10-28 21:50:31 +00:00
export interface AutoPannerOptions extends LFOEffectOptions {
channelCount: number;
}
2019-10-28 21:50:31 +00:00
/**
2024-05-03 15:09:28 +00:00
* AutoPanner is a {@link Panner} with an {@link 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> {
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
/**
2024-05-03 15:09:28 +00:00
* @param frequency Rate of left-right oscillation.
2019-10-28 21:50:31 +00:00
*/
constructor(frequency?: Frequency);
constructor(options?: Partial<AutoPannerOptions>);
constructor() {
2024-05-03 15:09:28 +00:00
super(
optionsFromArguments(AutoPanner.getDefaults(), arguments, [
"frequency",
])
);
const options = optionsFromArguments(
AutoPanner.getDefaults(),
arguments,
["frequency"]
);
2019-10-28 21:50:31 +00:00
this._panner = new Panner({
context: this.context,
2024-05-03 15:09:28 +00:00
channelCount: options.channelCount,
});
2019-10-28 21:50:31 +00:00
// connections
this.connectEffect(this._panner);
this._lfo.connect(this._panner.pan);
this._lfo.min = -1;
this._lfo.max = 1;
}
static getDefaults(): AutoPannerOptions {
return Object.assign(LFOEffect.getDefaults(), {
2024-05-03 15:09:28 +00:00
channelCount: 1,
});
}
dispose(): this {
2019-10-28 21:50:31 +00:00
super.dispose();
this._panner.dispose();
return this;
}
}