# Auto pan

> An auto pan device: a pan or tremolo mode, a wave shape, a rate or a note value and a depth, a panel that draws the movement, a Web Audio engine and tools for agents.

```tsx
import { useState } from "react";
import {
  type AutoPanState,
  autoPanDevice,
} from "@/components/audio-ui/devices/auto-pan/device";
import { createAutoPanEngine } from "@/components/audio-ui/devices/auto-pan/engine";
import { AutoPanPanel } from "@/components/audio-ui/devices/auto-pan/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;
/** Sways on the half note: one cycle every two beats of the loop. */
const START = { division: "1/2", sync: true };

/**
 * An auto pan you can plug in: its state, a panel that draws the movement and an engine that plays it, each its own file. Play the loop, pick a waveform and switch to tremolo.
 */
export function BlockAutoPan() {
  const [state, setState] = useState<AutoPanState>(
    () => autoPanDevice.apply(autoPanDevice.defaults(), START).state
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine, tempo } = useDeviceLoop({
    create: createAutoPanEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, autoPanDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <AutoPanPanel
        onValueChange={setState}
        signal={signal}
        tempo={tempo}
        value={state}
      />
    </div>
  );
}
```

Moves the sound with a slow oscillator. In Pan mode it moves from one speaker to the other. In Tremolo mode its level goes up and down. 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/auto-pan
```

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

**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/auto-pan-device @audio-ui/auto-pan-panel @audio-ui/auto-pan-engine
```

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

```tsx title="components/examples/block-auto-pan.tsx"
import { useState } from "react";
import {
  type AutoPanState,
  autoPanDevice,
} from "@/components/audio-ui/devices/auto-pan/device";
import { createAutoPanEngine } from "@/components/audio-ui/devices/auto-pan/engine";
import { AutoPanPanel } from "@/components/audio-ui/devices/auto-pan/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;
/** Sways on the half note: one cycle every two beats of the loop. */
const START = { division: "1/2", sync: true };

/**
 * An auto pan you can plug in: its state, a panel that draws the movement and an engine that plays it, each its own file. Play the loop, pick a waveform and switch to tremolo.
 */
export function BlockAutoPan() {
  const [state, setState] = useState<AutoPanState>(
    () => autoPanDevice.apply(autoPanDevice.defaults(), START).state
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine, tempo } = useDeviceLoop({
    create: createAutoPanEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, autoPanDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <AutoPanPanel
        onValueChange={setState}
        signal={signal}
        tempo={tempo}
        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 auto pan 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. |
| Mode | Pan, Tremolo | Pan | Pan moves the sound between the speakers, Tremolo moves its level. |
| Shape | Sine, Triangle, Saw, Square | Sine | The wave of the oscillator: sine, triangle, saw or square. |
| Rate | 0.05 Hz to 20.00 Hz | 1.00 Hz | How fast the oscillator moves. |
| Sync | On or off | Off | Takes the rate from a note value and the tempo of the host. See [Tempo sync](/docs/devices#tempo-sync). |
| Note | 1/32 triplet, 1/32, 1/32 dotted, 1/16 triplet, 1/16, 1/16 dotted, 1/8 triplet, 1/8, 1/8 dotted, 1/4 triplet, 1/4, 1/4 dotted, 1/2 triplet, 1/2, 1/2 dotted, 1/1 triplet, 1/1, 1/1 dotted | 1/4 | The note value of one cycle of the oscillator. |
| Depth | 0 % to 100 % | 60 % | How far the oscillator moves the pan or the level. |

## Panel

The panel draws the movement over two seconds. `autoPanWave(shape, phase)` is the wave and `autoPanSweep(state)` is what the panel draws.

```tsx
import { AutoPanPanel } from "@/components/audio-ui/devices/auto-pan/panel";
import { autoPanDevice } from "@/components/audio-ui/devices/auto-pan/device";

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

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

## Engine

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

One oscillator feeds both a stereo panner and a gain, and the mode sets which of the two depths is on. In Tremolo mode the level swings around the middle of its range, so a depth of 100 % goes from silence to full level.
