A utility you can plug in: its state, a panel and an engine that plays it. Play a loop through it and move the pan and the width
@audio-ui
block-utility.tsx
"use client";
import { useState } from "react";
import { PlayToggle } from "@/components/audio-ui/play-toggle";
import { UtilityPanel } from "@/components/audio-ui/devices/utility/panel";
import { useDeviceLoop } from "@/hooks/use-device-loop";
import { useMasterBus } from "@/hooks/use-master-bus";
import {
type UtilityState,
utilityDevice,
} from "@/components/audio-ui/devices/utility/device";
import { createUtilityEngine } from "@/components/audio-ui/devices/utility/engine";
const MASTER_VOLUME = 0.7;
/**
* A utility you can plug in: its state, a panel and an engine that plays it, each its own file and none knowing the others. Play the loop and move the pan and the width.
*/
export function BlockUtility() {
const [state, setState] = useState<UtilityState>(() =>
utilityDevice.defaults()
);
const master = useMasterBus(MASTER_VOLUME);
const { playing, toggle } = useDeviceLoop({
create: createUtilityEngine,
destination: master,
state,
});
return (
<div className="rounded-xl h-full w-full min-w-0">
<UtilityPanel onValueChange={setState} value={state}>
<PlayToggle
label="Play a loop through it"
onToggle={toggle}
playing={playing}
/>
</UtilityPanel>
</div>
);
}





























