A chorus you can plug in: its state, a panel that draws the sweep of its delay and an engine that plays it. Play a loop through it and turn the rate and the depth
@audio-ui
block-chorus.tsx
"use client";
import { useState } from "react";
import { PlayToggle } from "@/components/audio-ui/play-toggle";
import { ChorusPanel } from "@/components/audio-ui/devices/chorus/panel";
import { useDeviceLoop } from "@/hooks/use-device-loop";
import { useMasterBus } from "@/hooks/use-master-bus";
import {
type ChorusState,
chorusDevice,
} from "@/components/audio-ui/devices/chorus/device";
import { createChorusEngine } from "@/components/audio-ui/devices/chorus/engine";
import { DEMO_TEMPO } from "@/lib/demo-loop";
const MASTER_VOLUME = 0.7;
/** The loop's own tempo, so a synced rate moves with its beat. */
const CONTEXT = { tempo: DEMO_TEMPO };
/**
* A chorus you can plug in: its state, a panel that draws the sweep of its
* delay and an engine that plays it, each its own file and none knowing the
* others. Play the loop and turn the rate and the depth.
*/
export function BlockChorus() {
const [state, setState] = useState<ChorusState>(() =>
chorusDevice.defaults()
);
const master = useMasterBus(MASTER_VOLUME);
const { playing, toggle } = useDeviceLoop({
context: CONTEXT,
create: createChorusEngine,
destination: master,
state,
});
return (
<div className="rounded-xl h-full w-full min-w-0">
<ChorusPanel onValueChange={setState} tempo={DEMO_TEMPO} value={state}>
<PlayToggle
label="Play a loop through it"
onToggle={toggle}
playing={playing}
/>
</ChorusPanel>
</div>
);
}



























