# Studio tools

Tools for a story's lanes and device racks, and for the studio the user has open. The arrangement tools change the
saved story and need nothing open. The open-studio tools work on a live studio through its own controls.

| Tool | Description |
|---|---|
| [`soundbox.open_in_studio`](#soundboxopen_in_studio) | Lay a sound out on a new timeline |
| [`soundbox.mix_track`](#soundboxmix_track) | Name, mute, solo or set the level of a lane |
| [`soundbox.remove_track`](#soundboxremove_track) | Delete a lane and its clips |
| [`soundbox.add_device`](#soundboxadd_device) | Add a device to a lane's rack |
| [`soundbox.set_device`](#soundboxset_device) | Change or bypass a device |
| [`soundbox.remove_device`](#soundboxremove_device) | Remove a device |
| [`soundbox.studio_context`](#soundboxstudio_context) | Read the open studio |
| [`soundbox.studio_apply`](#soundboxstudio_apply) | Edit the open studio |

`track_index` runs from −16 to 16 on every tool. An unknown `story_id` fails with `No story with id <STORY_ID>`.

## Arrangement

### `soundbox.open_in_studio`

Lays a library sound out on a new story's timeline, split into stems on separate lanes where possible, and blocks until
the split is done. Stems the sound already has are reused.

| Argument | Type | Required | Description |
|---|---|---|---|
| `sound_id` | string | Yes | The sound |
| `separate` | boolean | No | Split into stems first. Default `true`; ignored for a stem or an edit |
| `stems` | string[] | No | Stems that get a lane, up to 16. Default all |
| `rest` | `discard`, `merge` | No | What happens to stems not named. `merge` puts them on one "rest" lane. Default `discard` |

**Result:** the story summary of the new story. See [Story summary](https://mirli.app/docs/mcp-stories/index.md#shared-behaviour).

**Errors:** the split failed; nothing was opened.

### `soundbox.mix_track`

Sets one lane's name, mute, solo or level. These belong to the lane, not to its clips. With any lane soloed, only
soloed lanes are heard.

| Argument | Type | Required | Description |
|---|---|---|---|
| `story_id` | string | Yes | The story |
| `track_index` | integer | Yes | The lane |
| `name` | string or null | No | The lane's name, up to 80 characters |
| `muted`, `soloed` | boolean | No | |
| `gain_db` | number | No | −40 to 24 |

**Result:** the lane's settings and `open_in_studio`.

**Errors:** `No story with id <STORY_ID>`.

### `soundbox.remove_track`

Deletes a lane and every clip on it. The lanes numbered after it each shift by one to close the gap.

| Argument | Type | Required | Description |
|---|---|---|---|
| `story_id` | string | Yes | The story |
| `track_index` | integer | Yes | The lane |

**Result:** `removed_clips` and the story summary.

**Errors:** `No story with id <STORY_ID>`.

### `soundbox.add_device`

Adds a device to a lane's rack at its defaults, with any `params` applied.

| Argument | Type | Required | Description |
|---|---|---|---|
| `story_id` | string | Yes | The story |
| `track_index` | integer | Yes | The lane |
| `kind` | string | Yes | `compressor`, `eq`, `reverb`, `delay`, `distortion`, `gate`, `limiter` or `autotune` |
| `params` | object | No | Knob values in stored units: seconds, dB, 0–1 for mixes. The input schema lists every knob's range and default |
| `bypassed` | boolean | No | Out of the signal path, settings kept |
| `position` | integer | No | Place in the chain from 0. Default last |

Example arguments, a compressor on lane 2 with two knobs changed:

```json title="soundbox.add_device arguments"
{
  "story_id": "<STORY_ID>",
  "track_index": 2,
  "kind": "compressor",
  "params": {
    "threshold": -18,
    "attack": 0.02
  }
}
```

**Result:** `story_id`, `track_index`, `device` (the new id), `clamped` (knobs set past their range, placed at the
end), `devices` (the lane's whole chain), `note` and `open_in_studio`. Devices are heard in the studio's playback and
rendered into `export_story`'s mixdown.

**Errors:** a knob the device does not have (the error lists its knobs).

### `soundbox.set_device`

Changes a device's knobs, bypasses it, or both.

| Argument | Type | Required | Description |
|---|---|---|---|
| `story_id` | string | Yes | The story |
| `track_index` | integer | Yes | The lane |
| `device` | string | Yes | The device's id, or its kind when the lane has one of that kind |
| `params` | object | No | Knob values |
| `bypassed` | boolean | No | |

**Result:** the same shape as `add_device`.

**Errors:** neither `params` nor `bypassed` passed; no such device (the error lists the chain); a kind with several
devices on the lane (the error lists their ids); an unknown knob.

### `soundbox.remove_device`

Removes one device from a lane's chain.

| Argument | Type | Required | Description |
|---|---|---|---|
| `story_id` | string | Yes | The story |
| `track_index` | integer | Yes | The lane |
| `device` | string | Yes | Id, or kind when the lane has one of that kind |

**Result:** the same shape as `add_device`.

**Errors:** as `set_device`.

## The open studio

These need Mirli open in a browser or the desktop app with a studio showing. The server asks that page and waits a few
seconds for its answer.

### `soundbox.studio_context`

Reads what an open studio shows.

| Argument | Type | Required | Description |
|---|---|---|---|
| `story_id` | string | No | Which studio. Omit when one is open |

**Result:** `story_id`, `title`, `open_in_studio`, and the live state: lanes (name, muted, soloed, effect kinds), every
clip (`id`, lane, start, length, label), the playhead in seconds, the selected clip ids, and the voices a line can be
cast to.

**Errors:** no studio open; the named story is not open in a studio; several studios open and no `story_id` (the error
lists them); the page sent a context the server cannot read.

### `soundbox.studio_apply`

Applies edits to an open studio through its own controls, so they land on the user's undo stack.

| Argument | Type | Required | Description |
|---|---|---|---|
| `actions` | object[] | Yes | 1–50 studio actions, applied in order. See [Studio action vocabulary](https://mirli.app/docs/agents-studio-actions/index.md) |
| `story_id` | string | No | Which studio. Omit when one is open |
| `summary` | string | No | Up to 200 characters, shown in the studio's toast and history |
| `allow_delete` | boolean | No | Run `delete_clip` actions. Default `false`: they are held |

**Result:** `story_id`, `applied` (the count), `actions` (those applied), `dropped` (actions naming nothing in the
studio, or malformed), `held_deletes`, `notes` and `open_in_studio`.

**Errors:** as `studio_context`.
