* Playback: strips render on the audio thread itself The realtime callback handed strips to rayon's global pool whenever a session had four or more, then waited for them. The pool's workers run at normal priority, so under CPU load the callback waited for starved workers (priority inversion) and blocked, which the callback must never do. On the audio thread strips now render one after the other on the thread itself; offline renders (bounces) keep the parallelism. `as_audio_thread`, which marked pool workers while they rendered for the audio thread, is no longer needed. A headless stress test (opt-in: `cargo test -p soundcraft-playback -- --ignored`) plays a 16-track session with an EQ and a compressor per track, one callback per 512-frame period, while all cores but one spin. Before: 23 and 30 of 1500 callbacks missed their deadline; after: none in two runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Playback: count underruns and late callbacks; audio.health control method cpal reports underruns as `ErrorKind::Xrun`; they were only logged. The player now counts them, callbacks that overran their buffer period, and the worst callback load (relaxed atomics and one `Instant::now()` per callback, nothing on wasm32). `Player::health()` reads them; `Player::take_health()` reads and counts afresh without losing an event in between. The control channel reports them as `audio.health` (with the device's rate and buffer), and `soundcraft-cli app` knows it as a method. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: rustfmt the audio.health port cargo fmt --check failed on import grouping and a one-line if in the playback tests. * fix: cpal 0.18 sample_rate is a u32, and drop an unused import The output callback health timer used the old SampleRate newtype field, and note_stream_error removed the only use of Ordering in stream.rs. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
13 KiB
Control protocol
SoundCraft can be driven completely by other programs: scripts, test harnesses and AI agents. Every menu item, button, mouse gesture and keystroke maps to a command (or to synthetic input), and every command is reachable from:
| Surface | How |
|---|---|
| Desktop app control channel | soundcraft --control <port> (0 = pick a free port; printed as SOUNDCRAFT_CONTROL_PORT=…) |
| CLI against a running app | soundcraft-cli app --port <port> <method or command id> [JSON] (see cli.md) |
| Headless CLI | soundcraft-cli run --demo --cmd 'mix.volume={"track":"Kick","db":-6}' --bounce out.wav |
| MCP (headless) | soundcraft-cli mcp [--demo] |
| MCP (bridged to the app) | soundcraft-cli mcp --connect <port> |
Isolated automation profiles
Set SOUNDCRAFT_CONFIG_DIR to a fresh directory to isolate UI preferences, Autosave, Presets, and logs.
The nonempty value is used as the complete settings directory, even in portable mode (portable.txt beside the executable, which otherwise uses SoundCraftData next to it). Unset retains the normal platform paths;
an explicit empty value disables the settings directory instead of falling back to a personal profile. Save synthetic sessions to explicit scratch paths. Do not use SOUNDCRAFT_NO_PREFS
when testing preference persistence across restarts.
Run UI acceptance with --no-audio. This disables the output player; it does not disable recording
input opened by arm/monitor commands. An automated UI smoke run must never arm a track, enable input
monitoring, or start recording. Control input injects egui events; it does not establish operating-system
input delivery or screen-reader acceptance. Native screenshots use the presented viewport frame.
Wire format
Newline-delimited JSON over TCP on 127.0.0.1. One request per line, one reply per line:
{"id": 1, "method": "engine.execute", "params": {"command": "track.new", "params": {"count": 2, "format": "Stereo"}}}
{"id": 1, "ok": true, "result": {"tracks": [12, 13]}}
Errors: {"id": 1, "ok": false, "error": "bad parameters for mix.volume: no track named Nope"}. A line that is not a JSON object with a string method gets one error reply, and the connection is closed.
Methods
| Method | Params | What it does |
|---|---|---|
engine.execute (alias command) |
{command, params} |
Run a command programmatically. Never opens a dialog; empty params use defaults or the current selection. |
engine.commands |
{filter?} |
Every command: id, label, menu path, shortcut, params doc, enabled + reason. Includes UI-layer commands (window.*). |
engine.parity |
{} |
Parity report against the incumbent's menu catalog. |
session.inspect |
`{detail?: "summary" | "full"}` |
ui.inspect |
{} |
UI state (window, panels, dialogs), window size, playing/position, audio device, MIDI inputs (midi_inputs: name, enabled, open; midi_events: messages received so far; midi_events_dropped: messages a full input queue dropped), and edit_layout (timeline rect and every track row's rect, for clicking). |
audio.health |
{reset?: bool} |
How the realtime audio path keeps up since the output opened (or the last reset): health holds callbacks, xruns (underruns the device reported), late_callbacks (callbacks that overran their buffer period; not every one is audible, and the device may report the same overrun as an xrun) and worst_load (slowest callback as a share of its buffer period, to 0.001; 1.0 = it overran). Also device, silent, sample_rate and buffer_frames (null: the device default). The first blocks create plugins and may read late, so a stress run resets once playback is under way. reset: true returns the reading and counts afresh from it; no event falls between the two. |
ui.set |
any UiState fields |
e.g. {"window": "Mix", "narrow_mix": true}. |
ui.menu.list |
{} |
Every catalog menu path and the command that implements it (or null). |
ui.menu.invoke |
{path} or {id} |
Like clicking the menu item: may open its dialog (e.g. "Track > New..."). |
ui.click |
{x, y, button?, count?, cmd?, shift?, alt?, ctrl?} |
Synthetic click (window points). The reply is sent only after a UI pass has applied the press/release. |
ui.drag |
{x, y, to_x, to_y, steps?} |
Synthetic drag with the primary button. |
ui.scroll |
{x, y, dx?, dy?, unit?: "point"|"line", steps?, cmd?, shift?, alt?, ctrl?} |
A two-finger trackpad swipe over (x, y): dx/dy points spread over steps frames (default 8). Positive values move the content right/down (natural scrolling). unit: "line" sends mouse-wheel notches instead. With cmd it zooms; with shift it scrolls sideways. Point scrolling is trackpad-like: egui 0.37 scroll areas may rubber-band at an edge and spring back after the gesture, so a script that needs an exact final offset should use unit: "line" or drive the target with a command. |
ui.zoom |
{x, y, factor, steps?} |
A trackpad pinch around (x, y): factor > 1 spreads the fingers (zooms in). |
ui.move |
{x, y} |
Move the pointer. |
ui.key |
{key, cmd?, shift?, alt?, ctrl?} |
Key press (Space, Enter, A, F7, =…). |
ui.text |
{text} |
Type text into the focused field. At most 64 KiB of UTF-8 text per request. |
ui.screenshot |
{path?} |
PNG of the window (base64 in png_base64 when no path). Exactly one reply per request. A request is bound to the window geometry, focus state and open session it was admitted for. A geometry or DPI change is retried within its 8 s deadline, then fails screenshot stale; a change of focused window or of the open document cancels it (screenshot canceled: focus changed / ... the session changed) because those pixels must not be reported as a capture of the new state. It can also fail screenshot queue full (8 pending, 4 in flight), screenshot too large (64 MiB per image, 192 MiB aggregate encoding peak), screenshot path longer than 4096 bytes, or screenshot unavailable: the window has no capturable size yet (a first request before any window geometry is known, e.g. minimised before the first paint). Each request reserves its own worst-case encode peak — the captured RGBA image plus the raw copy, PNG buffer and base64 text built during encoding — so several small captures cannot retain or encode full-size images past the aggregate. The callback never writes a file: encoding and writing happen after collection, and a result arriving after the deadline returns screenshot timed out without creating the file. A native hidden/minimised window is asked for an explicit paint; browser hidden tabs cannot paint on request and time out. |
app.quit |
{} |
Quit. |
Scripted input (ui.click, ui.drag, ui.scroll, ui.zoom, ui.key, ui.text, ui.move) queues at most 4096 waiting events; a request that would exceed that bound fails with synthetic input queue full instead of growing the queue. A gesture's reply is delivered only after a UI pass has applied all of its events. Requests that follow it on the same connection (inspect, engine commands, screenshots) are therefore ordered after the gesture; requests already queued behind an undelivered gesture wait as well. If no UI pass can deliver the gesture within 15 s, it is canceled with synthetic input was not delivered and the request chain continues. Scripted input is automation, not a clipboard action: copy/selection commands it triggers are not published to the OS clipboard or PRIMARY selection.
Positions and references
- Tracks: id (number) or name (
"Kick"). - Clips: id (from
session.inspect). - Positions: samples (
96000), seconds ({"seconds": 2.5}), or a time string in any timebase, optionally prefixed:"bars_beats:5|1|000","min_secs:0:12.500","timecode:00:00:10:00","samples:48000". - Ranges:
start+end(orstart+length); omitted = the current edit selection.
Examples
P=$(soundcraft --demo --control 0 | sed -n 's/SOUNDCRAFT_CONTROL_PORT=//p') # or read stderr
soundcraft-cli app --port $P mix.solo '{"track":"Bass"}'
soundcraft-cli app --port $P transport.play
soundcraft-cli app --port $P ui.screenshot '{"path":"/tmp/shot.png"}'
soundcraft-cli app --port $P ui.menu.invoke '{"path":"Track > New..."}'
Offscreen (no window): cargo run -p soundcraft-ui-egui --example ui_shot -- out.png script.jsonl,
where each script line is a request ({"method": …, "params": …}), {"shot": "path.png"} or
{"steps": n}. Use --system-theme light|dark|none to supply the initial OS appearance, and
script events such as {"system_theme": "dark"} to change it on subsequent frames.
Appearance defaults to Dark. ui.theme {"mode":"system"} follows the appearance supplied by
the native or web integration at launch and on later frames, while the saved choice stays System.
When the integration cannot report an appearance, as on Linux, System reads the desktop's
settings portal (org.freedesktop.appearance color-scheme) and follows its changes; without
a portal answer it uses Dark. Manual Light and Dark stay fixed when the OS appearance changes.
An offscreen render without --system-theme supplies no OS appearance and therefore resolves
System to Dark, or on Linux to the desktop's portal setting when one is available.
view.scroll_into_view {"track":"Bass"} (a track id or name; without it, the first selected
track) brings the track to the top of the Edit window and the left of the Mix window, the same as
Scroll Into View in the track name menu. A window not on screen catches up when it is next shown.
Panel docking
Tracks and Groups, Clips, MIDI Editor, Memory Locations, and Undo History use movable panels. Commands target the active Edit or Mix view; floating panels stay inside the current viewport. Edit and Mix retain separate arrangements; Clips and MIDI Editor belong to Edit. Transport, plug-in, and specialist utility windows retain their existing hosts. The document/session view is protected.
The Edit window starts with Tracks and Groups in a 168-point column in a dock at the left edge, Clips in a 230-point column in a dock at the right edge, and the MIDI Editor under the session view between them. Both docks run the window's full height. Mix starts with Tracks and Groups docked at its left edge. Memory Locations and Undo History float. A dock column stacks tab groups top to bottom: a panel dropped on a group's middle joins it as a tab, on its upper or lower third stacks a new group above or below it, and at a column's edge makes a new column. A panel dropped at an empty window edge makes a dock there. Layouts, active tabs, panel visibility, and floating rectangles are saved with the app's existing UI preferences. These operations do not edit document contents.
Panel IDs: tracks, clips, midi, memory, history. The protected center is canvas.
ui.dock accepts operation and panel. Operations are open, close, activate, float (with finite positive rect: [x, y, width, height]), or move (with target and zone: tab|center|left|right|top|bottom|above|below; PascalCase names such as Left also parse). open and activate show a hidden panel at its saved location and bring a visible panel to the front. A panel with no saved location, or whose saved anchor cannot be restored, opens at its default place: Tracks and Groups and Clips join their dock's first group, or make that dock again at its default width when it is gone; the MIDI Editor opens under the session view; Memory Locations and Undo History float at their default rectangles. Center and tab group with the target; side zones split beside it; above and below stack the panel in a new group above or below a floating target's group. ui.dock.reset restores the default arrangement. Invalid moves return an error without changing the layout.
Invoke these UI commands through engine.execute, for example {"command":"ui.dock","params":{"operation":"float","panel":"tracks","rect":[100,100,320,440]}}.
Advanced ui.dock operations use the same validated transaction as pointer gestures:
moveFloating updates rect, resizeSplit accepts a boolean child path and
size ({"Ratio":0.5}, {"FixedFirst":280}, or {"FixedSecond":280}),
setStackOpen takes open, and resizeStack takes a point height or null.
A center move can include before (panel ID or null to append) for tab order.
The equivalent {"action": ...} form accepts a serialized shared docking action;
this is also the form emitted by the renderer. Protected-canvas and app-specific panel
rules apply equally to both forms.
The saved UI preferences and window configurations carry docking_version. Settings with no
version, or an older one, hold the split-frame layouts of earlier releases: they load with the
default Edit and Mix layouts and keep every other setting.