# Utility

> A utility device: a gain, a pan, a width, a mono switch and a phase invert, a panel without a display, a Web Audio engine and tools for agents.

```tsx
import { useState } from "react";
import {
  type UtilityState,
  utilityDevice,
} from "@/components/audio-ui/devices/utility/device";
import { createUtilityEngine } from "@/components/audio-ui/devices/utility/engine";
import { UtilityPanel } from "@/components/audio-ui/devices/utility/panel";
import { useDeviceLoop } from "@/hooks/use-device-loop";
import { useDeviceSignal } from "@/hooks/use-device-signal";
import { useMasterBus } from "@/hooks/use-master-bus";
import { useDemoSound } from "@/hooks/use-demo-source";

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 sound = useDemoSound("groove");
  const { engine } = useDeviceLoop({
    create: createUtilityEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, utilityDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <UtilityPanel onValueChange={setState} signal={signal} value={state} />
    </div>
  );
}
```

Sets the level and the stereo image of a signal. It has no display, so its panel is only as tall as its controls. It is a [device](/docs/devices): a state, a panel, an engine and tools, each its own file.

## Installation

**CLI**

```bash
npx shadcn@latest add @audio-ui/utility
```

It installs the device's state, its engine and its panel to `components/audio-ui/devices/utility/`. The demo above, which wires them to a loop, is `@audio-ui/block-utility`.

**Manual**

**1. Install the packages:**

```bash
npm install @ui-sdk/core@0.1.0-beta.14 @ui-sdk/react@0.1.0-beta.14
```

**2. Add the pieces you want. All of them, or only the state and the panel if your engine is elsewhere:**

```bash
npx shadcn@latest add @audio-ui/utility-device @audio-ui/utility-panel @audio-ui/utility-engine
```

**3. Copy and paste the demo that wires them, if you want it.**

```tsx title="components/examples/block-utility.tsx"
import { useState } from "react";
import {
  type UtilityState,
  utilityDevice,
} from "@/components/audio-ui/devices/utility/device";
import { createUtilityEngine } from "@/components/audio-ui/devices/utility/engine";
import { UtilityPanel } from "@/components/audio-ui/devices/utility/panel";
import { useDeviceLoop } from "@/hooks/use-device-loop";
import { useDeviceSignal } from "@/hooks/use-device-signal";
import { useMasterBus } from "@/hooks/use-master-bus";
import { useDemoSound } from "@/hooks/use-demo-source";

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 sound = useDemoSound("groove");
  const { engine } = useDeviceLoop({
    create: createUtilityEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, utilityDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <UtilityPanel onValueChange={setState} signal={signal} value={state} />
    </div>
  );
}
```

**Agent**

Paste this prompt to your agent. It does the rest: it installs the skill, adds the component and wires it to your audio.

```text
Install the audio/ui skill with `npx skills add ouestlabs/audio-ui`, then follow it to add the utility from audio/ui to my project and wire it to my audio code. Read the docs at https://www.audio-ui.dev/llms.txt first.
```

To let the agent read the docs live, connect the [MCP server](/docs/mcp). More in [Agent Skill](/docs/agents).

## Controls

| Control | Range | Default | What it does |
| --- | --- | --- | --- |
| On | On or off | On | Turns the device on. Off, the signal passes through unchanged. |
| Gain | -35 dB to 35 dB | 0 dB | The level of the signal. |
| Pan | L100 to R100 | C | Moves the signal between the left and the right. |
| Width | 0 % to 200 % | 100 % | The width of the stereo image. 0 is mono, 100 % is the input as it is and 200 % is twice as wide. |
| Mono | On or off | Off | Sums the two channels to one. |
| Invert | On or off | Off | Flips the phase of the signal. |

## Panel

The panel is the controls and nothing else. `utilitySettings(state)` gives the numbers that go on the nodes.

```tsx
import { UtilityPanel } from "@/components/audio-ui/devices/utility/panel";
import { utilityDevice } from "@/components/audio-ui/devices/utility/device";

const [state, setState] = useState(() => utilityDevice.defaults());

<UtilityPanel onValueChange={setState} value={state} />;
```

## Engine

Create it, connect it and update it as for any device: see [The engine](/docs/devices#the-engine).

The signal is split into mid and side, and the width scales the side. A mono input is spread to both sides first. Off, the signal passes unchanged.
