# Fader

> A linear slider for gain and other continuous parameters.

**In Vue**

```tsx
<script lang="ts" setup>
import Fader from "@/components/audio-ui/fader/Fader.vue";

const marks = [
  { label: "0", value: 0 },
  25,
  50,
  75,
  { label: "100", value: 100 },
];
</script>

<template>
  <Fader
    aria-label="Volume"
    :default-value="50"
    :marks="marks"
    :max="100"
    :min="0"
    :step="1"
  />
</template>
```

**In Svelte**

```tsx
<script lang="ts">
import Fader from "$lib/components/audio-ui/fader/Fader.svelte";

const marks = [
  { label: "0", value: 0 },
  25,
  50,
  75,
  { label: "100", value: 100 },
];
</script>

<Fader
  aria-label="Volume"
  defaultValue={50}
  {marks}
  max={100}
  min={0}
  step={1}
/>
```

**In Web**

```tsx
import "@/components/audio-ui/fader/web";

/** A graduation beside the track, with its label when it has one. */
const mark = (value, label) => `
          <audio-ui-fader-mark value="${value}">
            <span data-slot="fader-mark-tick"></span>${label === undefined ? "" : `<span data-slot="fader-mark-label">${label}</span>`}
          </audio-ui-fader-mark>`;

const GRIP = `<div data-orientation="vertical" data-slot="fader-thumb-mark"></div>`;

/** Draws the demo into `element`, and returns what takes it away. Its look is the fader's sheet, on its parts and attributes. */
export function faderWebDemo(element) {
  element.innerHTML = `
    <audio-ui-fader data-marks="labels" data-readout="auto" data-size="default" default-value="50" max="100" min="0" orientation="vertical" step="1">
      <audio-ui-fader-control>
        <audio-ui-fader-track>
          <audio-ui-fader-indicator></audio-ui-fader-indicator>
        </audio-ui-fader-track>
        <div aria-hidden="true" data-slot="fader-scale">${mark(0, "0")}${mark(25)}${mark(50)}${mark(75)}${mark(100, "100")}
        </div>
        <audio-ui-fader-thumb aria-label="Volume">
          <div data-orientation="vertical" data-slot="fader-thumb-inner">${GRIP}${GRIP}${GRIP}</div>
          <audio-ui-fader-value></audio-ui-fader-value>
        </audio-ui-fader-thumb>
      </audio-ui-fader-control>
    </audio-ui-fader>`;
  return () => {
    element.innerHTML = "";
  };
}
```

**In React**

```tsx
import { Fader } from "@/components/audio-ui/fader";

const MARKS = [
  { label: "0", value: 0 },
  25,
  50,
  75,
  { label: "100", value: 100 },
];

export function FaderVerticalDemo() {
  return (
    <Fader
      aria-label="Volume"
      defaultValue={50}
      editableValue
      marks={MARKS}
      max={100}
      min={0}
      step={1}
    />
  );
}
```

A linear control for continuous parameters such as volume, gain or a send level. The registry component is written on the fader primitive, which installs with it, and adds size variants and thumb marks.

**In Vue, Svelte and Web**

The fader's behavior is one file, the primitive, written on the UI SDK kernel and copied into your project. Each framework renders it with a thin adapter that you also own. A press on the track, the drag of the thumb, the wheel, the keys, the grid and the reset are the same in all four, and one suite of tests runs against each adapter.

## Overview

- **Input:** drag the thumb or press the track, or use the mouse wheel or the keyboard. `onValueCommitted` fires when the interaction ends.
- **Layout:** vertical by default, or horizontal, in `sm`, `default` and `lg` sizes.
- **Display:** a filled range and a thumb, with optional marks inside the thumb (`thumbMarks`).
- **Accessibility:** the thumb holds a native `<input type="range">` that carries the accessible name (`aria-label` or `aria-labelledby`), the value text (formatted with `format`) and the form value (`name`).

## Installation

The primitives are built on the [UI SDK](https://ui-sdk.dev) kernel, in beta. Nothing of ours comes from npm: the primitive and its adapter are files you copy into your project and own, and the only packages are the kernel's. The commands name its version, `@ui-sdk/*@0.1.0-beta.14`.

**In React**

**CLI**

The styled component, with size variants and theme styles:

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

Or the primitive alone, to style yourself:

```bash
npx shadcn@latest add @audio-ui/fader-react
```

It writes the primitive, its adapter and `primitive.ts` into `components/audio-ui/` and installs the kernel's packages and what each file imports. The optional styles are one more command:

```bash
npx shadcn@latest add @audio-ui/primitives-css
```

**In Vue, Svelte and Web**

**CLI**

The [CLI](/docs/cli) finds your framework in `package.json` and writes the styled component with what draws it: the primitive, its adapter, `primitive.ts` and the sheet of your style, with an index to import once. It installs the kernel's packages:

```bash
npx @audio-ui/cli add fader
```

Or the primitive alone, to style yourself:

```bash
npx @audio-ui/cli add fader --headless
```

**manual**

### 1. The kernel

**React**

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

**Vue**

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

**Svelte**

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

**JavaScript**

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

### 2. The primitive

The same two files for every framework: `fader.ts`, the fader's behavior written on the kernel's helpers, and `primitive.ts`, the little every primitive shares. Copy them into `components/audio-ui/` (`src/lib/components/audio-ui/` in Svelte).

<ItemFiles name="fader-react" to={2} />

### 3. The adapter

Your framework's few parts, over the primitive. They import it by a relative path, from the same folder, so keep the files as shown, or update the path.

**React**

<ItemFiles name="fader-react" from={2} />

**Vue**

<ItemFiles name="fader-vue" from={2} />

**Svelte**

A component per part, and an `index.ts` that gathers them. Svelte keeps its files under `src/lib`, so the primitive goes in `src/lib/components/audio-ui/` too.

<ItemFiles name="fader-svelte" from={2} />

**JavaScript**

Import it once, and it registers the `audio-ui-fader` tags.

<ItemFiles name="fader-web" from={2} />

### 4. The styles

Optional, and the same for every framework: the anatomy of the primitives, drawn flat and square, in the look of the UI SDK docs. It reads the tokens of the UI SDK stylesheet (`--ui-*`) when the page has it, and falls back to its own. Every rule is in the `ui-sdk` layer, so a rule of yours outside the layer wins.

<ItemFiles name="primitives-css" />

Import it once.

**In React**

### 5. The styled component

Optional: size variants and theme styles over the primitive.

```bash
npm install class-variance-authority
```

<ItemFiles name="fader" />

**In Vue, Svelte and Web**

### 5. The styled component

Optional: the fader as the registry draws it in React, with no classes and no Tailwind. Its look is one sheet of plain CSS on its parts, a sheet for each style (`nova`, `vega`, `maia`, `lyra`, `mira`, `luma`, `rhea`, `sera`). Copy the sheet of your style into your project, with the theme's tokens when the page has no shadcn theme.

The [CLI](/docs/cli) writes the component, its adapter, the sheet and an index to import once:

```bash
npx @audio-ui/cli add fader
```

By hand:

```html
<link rel="stylesheet" href="/css/theme.css" />
<link rel="stylesheet" href="/css/nova/fader.css" />
```

Both are served at `https://www.audio-ui.dev/css/`.

**Vue**

One component over the adapter, with the props of the React fader, `editableValue` included.

<ItemFiles name="fader-element-vue" />

**Svelte**

One component over the adapter, with the props of the React fader, `editableValue` included.

<ItemFiles name="fader-element-svelte" />

**JavaScript**

The custom elements take the same sheet. Write the parts the example above writes, and set `data-size`, `data-marks` (`ticks` or `labels`) and `data-readout` (`auto` or `always`) on `audio-ui-fader`, as the styled component does.

**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 fader 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).

## Usage

**In React**

```tsx
import { Fader } from "@/components/audio-ui/fader";
```

**Uncontrolled:** set only the initial value.

```tsx
<Fader defaultValue={0} max={6} min={-60} step={1} />
```

**Controlled:** drive the value from state.

```tsx
const [gain, setGain] = useState(0);

<Fader
  max={6}
  min={-60}
  onValueChange={setGain}
  onValueCommitted={(value, details) => console.log("Committed:", value, details.reason)}
  step={1}
  value={gain}
/>
```

**In React**

The primitive alone, part by part:

The parts are the same everywhere: a Root that owns the value, a Control that takes the pointer and the wheel, a Track and an Indicator that draw the travel and the fill, a Thumb that holds the focusable input, optional Marks along the track, and a Value for the text. A part takes the classes and attributes of its element, and the state attributes `data-disabled`, `data-dragging` and `data-orientation` to style from.

The Track, the Indicator, the Thumb and the Marks are positioned for you, from the bottom of a vertical fader and from the start edge of a horizontal one. Give the Track its length and the Control its size.

**React**

```tsx
import { useState } from "react";
import { Fader } from "@/components/audio-ui/fader/react";

export function Level() {
  const [level, setLevel] = useState(-12);
  return (
    <Fader.Root max={6} min={-60} onValueChange={setLevel} value={level}>
      <Fader.Control className="relative h-40 w-8">
        <Fader.Track className="absolute inset-y-0 left-1/2 w-1 bg-muted">
          <Fader.Indicator className="absolute bg-primary" />
          <Fader.Mark value={0} />
        </Fader.Track>
        <Fader.Thumb aria-label="Level" className="size-4 rounded-full bg-card" />
      </Fader.Control>
      <Fader.Value />
    </Fader.Root>
  );
}
```

**Vue**

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Fader } from "@/components/audio-ui/fader/vue";

const level = ref(-12);
</script>

<template>
  <Fader.Root :max="6" :min="-60" :value="level" @value-change="(next: number) => (level = next)">
    <Fader.Control class="relative h-40 w-8">
      <Fader.Track class="absolute inset-y-0 left-1/2 w-1 bg-muted">
        <Fader.Indicator class="absolute bg-primary" />
        <Fader.Mark :value="0" />
      </Fader.Track>
      <Fader.Thumb aria-label="Level" class="size-4 rounded-full bg-card" />
    </Fader.Control>
    <Fader.Value />
  </Fader.Root>
</template>
```

**Svelte**

```svelte
<script lang="ts">
  import { Fader } from "$lib/components/audio-ui/fader/svelte";

  let level = $state(-12);
</script>

<Fader.Root max={6} min={-60} value={level} onValueChange={(next: number) => (level = next)}>
  <Fader.Control class="relative h-40 w-8">
    <Fader.Track class="absolute inset-y-0 left-1/2 w-1 bg-muted">
      <Fader.Indicator class="absolute bg-primary" />
      <Fader.Mark value={0} />
    </Fader.Track>
    <Fader.Thumb aria-label="Level" class="size-4 rounded-full bg-card" />
  </Fader.Control>
  <Fader.Value />
</Fader.Root>
```

With the latest SvelteKit, import through `#lib` in place of `$lib`: `#lib/components/audio-ui/fader/svelte`.

**JavaScript**

```html
<audio-ui-fader min="-60" max="6" value="-12">
  <audio-ui-fader-control>
    <audio-ui-fader-track>
      <audio-ui-fader-indicator></audio-ui-fader-indicator>
      <audio-ui-fader-mark value="0"></audio-ui-fader-mark>
    </audio-ui-fader-track>
    <audio-ui-fader-thumb aria-label="Level"></audio-ui-fader-thumb>
  </audio-ui-fader-control>
  <audio-ui-fader-value></audio-ui-fader-value>
</audio-ui-fader>

<script type="module">
  import "./audio-ui/fader/web.ts";

  document.querySelector("audio-ui-fader").addEventListener("input", (event) => {
    console.log(event.detail.value, event.detail.reason, event.detail.source);
  });
</script>
```

Each part binds a microtask after it connects, all together. Read the element's state after that, not in the line that wrote the markup.

## Interaction

### Pointer

**Behavior**

| Gesture | Effect |
| --- | --- |
| Track click / drag | Click or drag on the track to set the value from the pointer position. |
| Thumb drag | Dragging the thumb changes the value continuously, within `min…max`. |
| Commit event | `onValueCommitted` fires when an interaction ends with a new value. |
| Lagging value | While dragging, the thumb follows the pointer even if a controlled `value` updates late; it returns to `value` on release. Reject a value with `eventDetails.cancel()`. |

### Keyboard

On the focused thumb:

**Keys**

| Key | Effect |
| --- | --- |
| `ArrowUp` / `ArrowRight` | Increase by `step` |
| `ArrowDown` / `ArrowLeft` | Decrease by `step` |
| `PageUp` / `Shift` + `ArrowUp` | Increase by `largeStep` (default `10`) |
| `PageDown` / `Shift` + `ArrowDown` | Decrease by `largeStep` (default `10`) |
| `Home` | Set to `min` |
| `End` | Set to `max` |

On an editable readout, given `editable` on `Value` (the `editable` attribute on `audio-ui-fader-value` in plain HTML, `editableValue` on the styled fader), in every framework:

**Editable readout**

| Gesture | Effect |
| --- | --- |
| Double click / `Enter` / `F2` | Lays a text field over the readout, its text selected |
| `Enter` / leaving the field | Sets the number typed, as a change of the fader |
| `Escape` | Keeps the value |

The readout carries `data-editable`, and `data-editing` while the field is open.

### Wheel

The mouse wheel over the fader moves the value by `step` and reports `eventDetails.reason === "wheel"`.

## API reference

**In React**

### Registry component

`Fader` accepts style props (`size`, `thumbMarks`, `className`) plus the props of the `Fader` primitive's Root (`name`, `form`, `format`, `locale`, `largeStep`, `render`, …). The primitive's `Fader.Mark` places a graduation at a `value` along the track, with `data-active` once the value has reached it, to build your own ruler. `aria-label`, `aria-labelledby`, and `aria-describedby` are forwarded to the thumb's input.

#### Value and state

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `number` |  | Where the mark sits, between `min` and `max`. |
| `defaultValue` | `number` | `midpoint` | Uncontrolled starting value, and what a double click, an Alt + click or the Delete key return to; defaults to the midpoint of `min…max`. |
| `min` | `number` | `-60` | Minimum value. |
| `max` | `number` | `6` | Maximum value. |
| `step` | `number` | `1` | Granularity of every change. |
| `marks` | `(number \| { value, label? })[]` |  | Graduations drawn beside the track: a ruler for the value. Those the value has reached from `anchor` light up. |
| `valueLabel` | `"auto" \| "always" \| "hidden"` | `"auto"` | When the value shows beside the thumb: `auto` while hovered, dragged or focused from the keyboard. |
| `formatValue` | `(value: number) => string` | `format` | How the value prints in that readout and in what screen readers announce, e.g. `"-6.0 dB"`. |
| `editableValue` | `boolean` | `false` | Lets you type the value in the readout: a double click, or Enter while it has focus. Enter commits it, Escape drops it (`reason: "input-change"`). |
| `anchor` | `number` | `min` | Value the `Indicator` fills from, such as `0` on a -1…1 pan. Defaults to `min`. |
| `disabled` | `boolean` | `false` | Disables interaction. |
| `onValueChange` | `(value: number, eventDetails) => void` |  | Fires on drag, track press, keyboard, wheel and form input changes. |
| `onValueCommitted` | `(value: number, eventDetails) => void` |  | Fires when an interaction ends with a new value. |
| `aria-label` | `string` |  | Accessible name for the slider. |
| `aria-labelledby` | `string` |  | ID of a labeling element. |

#### Layout and visuals

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `orientation` | `"horizontal" \| "vertical"` | `"vertical"` | Direction of travel. |
| `size` | `"sm" \| "default" \| "lg"` | `"default"` | Track and thumb size preset. |
| `thumbMarks` | `number \| false` | `3` | Number of marks in the thumb or `false` to hide them. |
| `className` | `string` |  | Root wrapper class name. |

Additional valid HTML attributes passed to `Fader.Root` are forwarded.

A vertical fader takes the height it is given, and never less than `--fader-min-height` (10rem by default). Set it lower where room is short, such as a mixer on a small screen: `[--fader-min-height:5rem]` on a parent.

### Options

Set on the Root, as props (an attribute in kebab case in the web adapter).

| Option | Type | Default | |
| --- | --- | --- | --- |
| `value`, `defaultValue` | `number` | the midpoint | The controlled value, or the starting one. `defaultValue` is also where a reset returns. |
| `min`, `max`, `step` | `number` | `-60`, `6`, `1` | The range, in dB for an audio fader, and the grid the value snaps to. |
| `largeStep` | `number` | `10` | What Page Up, Page Down and Shift with an arrow move by. |
| `anchor` | `number` | `min` | Where the Indicator's fill starts, like `0` on a pan from -1 to 1. |
| `orientation` | `"vertical"` or `"horizontal"` | `"vertical"` | Which way the travel runs. |
| `format`, `locale` | `Intl.NumberFormat` options, a locale | | The Value's text and the input's `aria-valuetext`. |
| `disabled` | `boolean` | `false` | Takes no key, wheel or press. |
| `name` | `string` | | The form field's name, carried by the input. |
| `onValueChange` | `(value, details) => void` | | Every change, which `details.cancel()` refuses. |
| `onValueCommitted` | `(value, details) => void` | | The end of a gesture. |

The Mark takes a `value` and carries `data-active` while the value has reached it from the anchor. The Thumb takes `getAriaValueText(formatted, value, index)` to announce the value in your own words, like `"-6 dB"`.

### What a change reports

`details` carries what moved the value and how:

- `reason`: `"drag"`, `"track-press"`, `"keyboard"`, `"wheel"`, `"input-change"` (a typed value) or `"reset"`.
- `source`: `"mouse"`, `"touch"`, `"pen"`, `"keyboard"`, `"programmatic"` or `"agent"`, for analytics and for telling a person from an agent. It is never a reason to behave differently.
- `event`: the DOM event behind it, when there is one.
- `cancel()`: refuses the change. A controlled fader keeps the value you give it.

While a pointer drags the thumb, it follows the pointer even if a controlled `value` lags behind, as with a seek bar driven by playback time.

In the web adapter, `onValueChange` is an `input` event and `onValueCommitted` a `change` event, both with `detail: { value, reason, source }`, and `event.preventDefault()` refuses a change.

### Parts

**In React, Vue and Svelte**

| Part | Element | Props |
| --- | --- | --- |
| `Fader.Control` | `div` |  |
| `Fader.Indicator` | `div` |  |
| `Fader.Label` | `div` |  |
| `Fader.Mark` | `div` | `value: number` |
| `Fader.Root` | `div` |  |
| `Fader.Thumb` | `div` |  |
| `Fader.Track` | `div` |  |
| `Fader.Value` | `output` |  |

**In Web**

The tags the web adapter registers: the inputs inside a part are made for you.

`audio-ui-fader`, `audio-ui-fader-control`, `audio-ui-fader-indicator`, `audio-ui-fader-input`, `audio-ui-fader-label`, `audio-ui-fader-mark`, `audio-ui-fader-thumb`, `audio-ui-fader-track`, `audio-ui-fader-value`

### Events

| React and Svelte | Vue | Web |
| --- | --- | --- |
| `onValueChange` | `@value-change` | `input` |
| `onValueCommitted` | `@value-committed` | `change` |

**In React**

## Examples

### Pan, filled from the center

`anchor={0}` makes the fill grow from the center of a -1…1 range, left or right of it.

```tsx
import { useState } from "react";
import { Fader } from "@/components/audio-ui/fader";

const formatPan = (pan: number) => {
  const amount = Math.round(Math.abs(pan) * 100);
  if (amount === 0) {
    return "C";
  }
  return `${pan < 0 ? "L" : "R"}${amount}`;
};

export function FaderPanDemo() {
  const [pan, setPan] = useState(-0.3);

  return (
    <div className="flex w-full max-w-xs flex-col items-center gap-2">
      <Fader
        anchor={0}
        aria-label="Pan"
        max={1}
        min={-1}
        onValueChange={setPan}
        orientation="horizontal"
        step={0.01}
        value={pan}
        valueLabel="hidden"
      />
      <output className="font-mono text-sm tabular-nums">
        {formatPan(pan)}
      </output>
    </div>
  );
}
```

### Mixing console

A fader per channel in dB, from silent at the bottom to +6 dB, beside the meter of what it lets through.

```tsx
import { useEffect, useState } from "react";
import { MixerView } from "@/components/audio-ui/mixer-view";
import { useArrangement } from "@/hooks/use-arrangement";
import { useArrangementEngine } from "@/hooks/use-arrangement-engine";
import { useTrackAutomation } from "@/hooks/use-track-automation";
import { usePlaySwitch } from "@/hooks/use-play-switch";
import {
  type Arranged,
  type ArrangementTrack,
  UNITY_MIX,
} from "@/lib/arrangement";
import type { RecordingSource } from "@/lib/clip-player";
import {
  DEMO_TEMPO,
  type DemoSourceName,
  renderDemoSource,
} from "@/lib/demo-sound";
import { libraryDevice } from "@/lib/device-library";
import { webAudio } from "@/lib/web-audio";

/** The tracks, each playing one of the demo's sounds round and round, at a level that leaves the main track under 0 dB. */
const SOUNDS: {
  gain: number;
  id: string;
  name: string;
  pan: number;
  send: number;
  source: DemoSourceName;
}[] = [
  { gain: 0.4, id: "kick", name: "Kick", pan: 0, send: 0, source: "kick" },
  {
    gain: 0.4,
    id: "groove",
    name: "Groove",
    pan: -0.25,
    send: 0.35,
    source: "groove",
  },
  {
    gain: 0.25,
    id: "drone",
    name: "Drone",
    pan: 0.3,
    send: 0.5,
    source: "chord",
  },
];

const REVERB = "return-1";

const reverb = libraryDevice("audioui.reverb");

const TRACKS: ArrangementTrack[] = SOUNDS.map(
  ({ gain, id, name, pan, send }, index) => ({
    color: index,
    id,
    mix: { ...UNITY_MIX, color: index, gain, pan },
    name,
    // A share of the groove and of the drone goes to the reverb.
    sends: send > 0 ? { [REVERB]: send } : undefined,
  })
);

const RETURNS: ArrangementTrack[] = [
  {
    color: 0,
    devices: reverb
      ? [
          {
            device: "audioui.reverb",
            id: "reverb",
            state: reverb.device.defaults(),
          },
        ]
      : [],
    id: REVERB,
    name: "A Reverb",
  },
];

/** The metronome stays off: the loops are the only thing that plays. */
const NO_METRONOME = { on: false, rhythm: "auto" } as const;

/** The clip of a track: its sound, round and round for the whole length. */
function loopClip(
  id: string,
  name: string,
  own: number,
  length: number
): Arranged {
  return {
    id: `clip-${id}`,
    loop: [0, own],
    name,
    recording: id,
    sourceLength: own,
    track: id,
    value: { fadeIn: 0, fadeOut: 0, length, offset: 0, start: 0 },
  };
}

/**
 * A mixing console over an arrangement: a channel for each track with its
 * pan, its sends, its fader, its meter and its peak, Solo and Mute, then a
 * return track, and the main track, which stays in sight at the right while
 * the channels scroll. Play the loops: every meter reads the real signal of
 * its channel. It is the same view a workstation shows under its tracks.
 */
export function BlockMixer() {
  const arrangement = useArrangement({
    duration: 1,
    initialReturns: RETURNS,
    initialTracks: TRACKS,
    tempo: DEMO_TEMPO,
  });
  const { dispatch, doc } = arrangement;
  const automation = useTrackAutomation({ dispatch, tracks: doc.tracks });
  const { playing } = usePlaySwitch();
  const [selected, setSelected] = useState<string | null>(null);

  // The sounds, as the tracks' recordings, and a clip on each that loops it.
  const [sources, setSources] = useState<ReadonlyMap<string, RecordingSource>>(
    () => new Map()
  );
  useEffect(() => {
    const context = webAudio.getContext();
    if (!context) {
      return;
    }
    let cancelled = false;
    Promise.all(
      SOUNDS.map(({ source }) => renderDemoSource(source, context.sampleRate))
    ).then((buffers) => {
      if (cancelled) {
        return;
      }
      const length = Math.max(...buffers.map((buffer) => buffer.duration));
      setSources(
        new Map(
          SOUNDS.map(({ id }, index) => {
            const buffer = buffers[index];
            return [
              id,
              {
                channels: Array.from(
                  { length: buffer?.numberOfChannels ?? 0 },
                  (_, channel) =>
                    buffer?.getChannelData(channel) ?? new Float32Array()
                ),
                sampleRate: buffer?.sampleRate ?? context.sampleRate,
              },
            ];
          })
        )
      );
      dispatch({
        commands: [
          { duration: length, type: "set-duration" },
          { loop: { on: true, range: [0, length] }, type: "set-loop" },
          ...SOUNDS.flatMap(({ id, name }, index) => [
            { id: `clip-${id}`, type: "remove-clip" } as const,
            {
              clip: loopClip(
                id,
                name,
                buffers[index]?.duration ?? length,
                length
              ),
              type: "add-clip",
            } as const,
          ]),
        ],
        type: "batch",
      });
    });
    return () => {
      cancelled = true;
    };
  }, [dispatch]);

  const engine = useArrangementEngine({
    doc,
    metronome: NO_METRONOME,
    overridden: automation.overridden,
    recordings: sources,
  });
  const { engine: running, play, stop } = engine;
  const ready = running !== null && sources.size > 0;
  // The play switch of the preview's bar plays the loops, from their start.
  useEffect(() => {
    if (!ready) {
      return;
    }
    if (playing) {
      play(0);
    } else {
      stop();
    }
  }, [play, playing, ready, stop]);

  return (
    <div className="rounded-xl h-96 w-full min-w-0 overflow-hidden border bg-card">
      <MixerView
        arrangement={arrangement}
        engine={engine}
        onMix={automation.changeMix}
        onSelectTrack={setSelected}
        overridden={automation.overridden}
        selectedTrack={selected}
      />
    </div>
  );
}
```

## For an agent

The fader declares one action, `setValue`, and the name on its Thumb is what an agent finds it by. The bridge of the framework you use (`createAgent` in `@ui-sdk/<framework>/agent`) reads its value and range, sets it with the source `"agent"`, and the same `onValueChange` hears it, so an app can refuse a value as it would a person's.
