T-025 — crates/params: one parameter description and one thread-safe value store used by the plugin and its editor
Status: done — D1–D5 as proposed, scope set by the maintainer (2026-12-02) · Area: rust · Depends on: T-003 (and T-016, T-043, whose parameter code it replaces)
Read for that: T-016 (D7: ids, automation, state v2), T-043 (the Gain edit rules this task generalises), Piano 13 (Changing parameters while playing: the three classes), Plugin formats (audio-thread rules), crates/piano/src/{params,audio,lib,gui}.rs.
Why: the plugin has three parameters, each wired by hand: Gain alone has the editor-edit and gesture path of T-043 (pending GUI value, host-change flag with write count, gesture begin/end), Sustain and A4 only host automation and state. T-020 puts every parameter in the editor, and every later control (T-018 tuning, T-010 noises, Piano 14’s quality levels) would repeat the wiring. T-025 describes each parameter once and gives all of them the same, tested edit path.
Scope (maintainer, 2026-12-02): the plugin and its editor only. Nothing for the standalone app or web remote of ADR-0008 (still proposed); the crate stays framework-free so they can use it later.
What
- New crate
crates/params(instruments-params):#![deny(unsafe_code)], no dependency on clack, egui orinstruments-dsp. - Description (D1):
ParamDescand a parameter table type; the piano’s table lives incrates/piano, its ranges taken frominstruments_dsp::piano::Settingsand the gain constants. - Store (D2): one cell per parameter with the T-043 semantics, generic over the table; the clack translation (events in, events out) stays in
crates/piano. - State (D3): format version 3, keyed by parameter id; versions 1 and 2 still load.
- Text (D4): formatting and parsing from the description, used by the host’s
value_to_text/text_to_valueand by the editor. - The plugin uses the crate for all three parameters;
crates/piano/src/params.rskeeps only the table and the clack glue. GUI edits of Sustain and A4 work like Gain’s (reported to the host with gestures, applied through T-016’s path), though the editor shows only Gain until T-020. - Pages: Architecture overview (
crates/paramsno longer planned), Plugin formats (state v3), T-016’s D7 note.
Decisions (as built)
| Question | Options | Proposal | |
|---|---|---|---|
| D1 | What a description holds | (a) ParamDesc { id: u32, name, group, unit, min, max, default, scale, class, decimals, automatable } with Scale::{Linear, Log} (editor slider mapping only; the host sees the plain value range) and Class::{Smoothed, AtStrike, Recompute} from Piano 13; ids stable forever; group gives the editor section and the CLAP module path; (b) a trait per parameter | (a): plain const data, testable as a table (ids unique and non-zero, min < default-range checks, finite) |
| D2 | How values move between threads | (a) one ParamCell per parameter, the T-043 algorithm unchanged: value word (f32 bits + host-changed flag + write count), pending-GUI word (value or none + count), gesture and gesture-reported flags; ParamStore holds a cell per table entry, created once (allocates at construction only); all operations are atomics, wait-free on the audio thread; the store reports pending GUI edits and gestures as plain data (param index, begin/value/end) that crates/piano turns into clack events; values are clamped to the range, NaN → default; (b) a lock-free queue of edits | (a): T-043’s rules are reviewed and tested; generalising them keeps every test meaningful. Gestures become per parameter (dragging A4 brackets A4’s events) |
| D3 | State format | (a) version 3: [3, count: u16 LE, count × (id: u32 LE, value: f32 LE)]; unknown ids are skipped, missing ids keep their defaults, values clamped, NaN → default, a truncated or over-long payload or count > 1024 is refused; v1 and v2 decode as today (positional); (b) keep the positional v2 and bump on every new parameter | (a): new parameters no longer need a format bump, and a newer plugin’s state loads in an older one minus the unknown parameters |
| D4 | Text | (a) format(value) = the value with decimals decimals, a space, the unit (Gain 1 decimal, Sustain and A4 2, so the host-visible text is today’s: "0.0 dB", "1.00 ×", "440.00 Hz"); parse(text) accepts the number with or without the unit, rejects non-finite, clamps; (b) per-parameter closures | (a): one rule for the host and the editor |
| D5 | Where the recompute-class values live | (a) the store is the one source; when a recompute-class value is applied (host event on the audio thread, GUI edit emitted, flush, state load) the plugin also writes it to SettingsRequests (atomics, as today); activate reads the store; (b) keep them only in SettingsRequests | (a): one place for the editor, state and host to read; SettingsRequests stays the engine’s mailbox |
Out of scope: new parameters, the editor’s layout (T-020), presets (T-019), anything of ADR-0008.
Done when: the gates of AGENTS.md pass (including cargo xtask bundle piano --release, clap-validator, the GUI smoke test); T-043’s tests pass against the generic cell (ported, not weakened) and have twins for one recompute-class parameter; state v1, v2 and v3 round-trip and malformed states are refused (tests); no_alloc still passes; the default sound is unchanged (golden test).
Outcome
crates/params(instruments-params):ParamDesc,ParamTable(const-validated: ids unique and non-zero, finite ranges, default inside, aLogparameter needsmin > 0),ParamCell(T-043’s algorithm per parameter,cell.rs),ParamStore(emit_gui_changesreportsGuiEvent::{Begin, Value, End}per index;save_state/load_stateinstate.rs).crates/piano/src/params.rsholds the table (Gain → Output, Sustain → Strings,Scale::Log, A4 → Tuning), the clack translation,PluginMainThreadParamsandPluginStateImpl.SharedParams::sync_recomputerefreshesSettingsRequestsfrom the store atactivateand at the start of every block, so the mailbox cannot stay behind a state load that crosses an audio-thread write.- State v3 per D3; legacy layouts are passed as id lists (
LEGACY_STATE), so table order may change. Duplicate ids in a v3 payload: the last one wins. The plugin reads at mostMAX_STATE_BYTES + 1bytes. - Implemented by Codex (gpt-6.2-sol) from this page; the groups were left empty and set afterwards (D1).
- Gates (2 cores):
cargo nextest run -j 2→ 116 passed, 1 skipped;clap-validator validate→ 35 passed, 0 failed, 9 skipped; GUI smoke test passed.
Review triage (Mistral Large 4, 2026-12-02)
| Point | Right? | Done |
|---|---|---|
| No verified defect; 13 probes (v3 duplicates, counts, truncation, legacy lengths, NaN on every write path, text edges, load during emit, 3-thread stress) all pass | — | probes kept as regression tests, crates/params/src/review_tests.rs |
An in-flight Value event reaches the host across a state load | known, accepted in T-043’s review | none |
| Counts wrap after 2³¹ writes | unreachable (as T-043) | none |
ParamTable::new does not check Log ⇒ min > 0 | right, latent | const assert added |
value_to_text does not clamp the host’s value | as before; hosts pass in-range values | none |