T-047 — Editor inspector: Instrument and Note scopes, per-note edits on top of the fit, note list, kept in state and presets

Status: done (D1–D9 accepted by the maintainer, 2026-12-04; the maintainer’s check in a DAW pending) · Area: rust · Depends on: T-044, T-019 (and T-045, T-046, done)

Read for that: Spec 003 (Edit, Window, egui and audio), T-046 (Outcome: PianoShared::selected_note, the picker, the dock), T-045 (Outcome: width classes), T-019 (D1 sections, D2 model identity, D3 preset file), T-016 (the worker and the swap), T-049 (set_scala: a main-thread input of the worker behind a mutex), crates/dsp/src/piano/{coeffs,exchange,model,engine}.rs, crates/params/src/{lib,state,preset}.rs, crates/piano/src/{params,gui,lib}.rs, crates/piano/src/gui/{keyboard,size,tests}.rs.

Why: the Edit tab holds only Microtuning and a placeholder line. Spec 003 plans an inspector to edit the model precisely enough to compare small changes, note by note, but the fitted model has no editable per-note quantities yet, overrides have no storage, and the engine only rebuilds from instrument-wide Settings. This task decides what a note edit is, how it reaches the engine and where it is kept, and builds the Instrument and Note scopes. The String scope waits for physical strings (T-010; Spec 003 Edit: the model’s string axis holds fitted components, not strings).

What

  1. Per-note fields (D1): a small fixed set of edits each key can carry, as offsets on top of the fit: Tune, Level, Brightness, Sustain, Release, Hammer contact. Each has metadata like a parameter (stable id, name, unit, range, default = neutral, scale, decimals, help text, when it takes effect).
  2. Instrument scope (D2, D3): the instrument-wide counterparts, as ordinary parameters (automatable, host undo through gestures, presets) in a group shown on Edit; some fields have an existing Play control as their counterpart.
  3. Engine (D4): the edits are an input of the coefficient worker beside Settings and the Scala targets; CoeffSet applies them per key, so the swap of T-016 carries them; no new audio-thread path.
  4. State and presets (D5, D6): a new state section NOTE and a [notes] table in the preset file, keyed by MIDI note and field id; kept across a model change (the fields are relative), unknown ids dropped and reported.
  5. Inspector UI (D7, D8): scope pills Instrument · Note; in Note scope a target line (C4 · MIDI 60), a row per field (label, value editor, unit, scope tag, override mark, reset), Reset note; a note list (name, MIDI number, override count), synchronised with the dock’s selected note and the picker; a Modified filter. Side by side when the window is standard or wide, a compact selector above the rows when narrow.
  6. Editing behaviour (D9): drafts keyed by note and field id; Enter commits, Escape restores, invalid text stays in the field with a message and leaves the sound unchanged; a drag updates continuously (the worker coalesces); no Apply, because no edit is costly.

Out of scope: the String scope (T-010), edits to individual partials or fitted components, inharmonicity edits (moving measured partials along a B law needs a decision of its own), a parameter search box (D8), an undo stack of the editor’s own (D9), note output or per-note automation, T-030’s export/import from the GUI.

Decisions (accepted by the maintainer, 2026-12-04)

QuestionOptionsProposal
D1What a note edit can change(a) six fields, each mapped onto the coefficients of one key: Tune (cents, −100…+100, all modes of the key by one ratio, on top of the tuning system, Scala and MTS-ESP), Level (dB, −24…+12, added to the key’s excitation in every layer), Brightness (dB/octave, −6…+6, b · log2 p added to the excitation of partial p, so the first partial keeps its level), Sustain (×, 0.25…4, log, divides the free decay rates, as String sustain does), Release (×, 0.25…4, log, divides the damped decay rates: longer release above 1), Hammer contact (×, 0.5…2, log, multiplies the contact time of every layer: shorter is brighter); (b) (a) without Hammer contact and Brightness (only what Play already has instrument-wide); (c) edits of single partials (frequency, decay, level per mode)(a): each field is one line in CoeffSet::with_targets (or the strike), meaningful for any key, so the Note scope is useful before strings exist; (c) is many rows of fitted components that the Spec defers to the String scope and that a refit would invalidate
D2How a note edit combines with the instrument-wide value(a) composition: the note’s value is an offset on top of the instrument’s (cents and dB add, factors multiply); the row shows the note’s offset, the effective value beside it (effective −3 cents), and its source (instrument / note); reset sets the note’s offset to neutral and removes it; (b) replacement, as the Spec words it: a note override replaces the instrument value for that key(a): the instrument values include Play controls and automation (String sustain, A4); with (b) an edited C4 would stop following String sustain and the A4 slider, which reads as a bug. With (a) the Spec’s rules still hold: a note row shows effective value and source, reset shows the inherited value, an explicit neutral override is kept (an override is present until reset, whatever its value)
D3Instrument scope(a) the Instrument scope lists the parameters of the model groups: Strings (String sustain, the counterpart of Sustain; still on Play too) and a new group Voicing with three new parameters, Brightness, Release and Hammer contact (ids 11–13, appended, defaults neutral, Class::Recompute except Hammer contact, AtStrike); Tune and Level have no instrument row (A4, the tuning controls and Gain on Play are that), the Note rows name them as the inherited value; (b) instrument-wide values as state-only values like the note edits (no host automation); (c) no Instrument scope yet(a): the Spec says the parameter table’s group decides where a control appears, and host parameters bring automation, host undo and presets for free; three new ids cost nothing in state v3/v4 (missing ids load as defaults, so old projects sound the same)
D4Path to the engine, recompute(a) a NoteEdits value (88 keys × 6 fields, f32, plus a presence bit per field) set from the main or GUI thread with SettingsRequests::set_note_edits (a mutex like set_scala, then publish); the worker rebuilds the whole CoeffSet as for any setting; CoeffSet gains a per-key contact factor that the engine multiplies into contact_s at the strike; (b) as (a), but the worker rebuilds only the edited key’s span and copies the rest from the current set; (c) per-key atomics read by the audio thread(a): a rebuild takes milliseconds (T-016) and the worker already coalesces a drag to its latest value every 5 ms; one code path, no partial-copy bugs. (b) is an optimisation to take if a drag measurably stutters (the tests time a rebuild); (c) puts model maths on the audio thread
D5Kept in state(a) state section NOTE (T-019 D1), [1, count u16, count × (midi u8, field u16, value f32)], only present fields, written only when there is at least one; field ids stable like parameter ids; values clamped on load, NaN dropped, unknown field ids and notes outside 21–108 dropped and counted in the host log; (b) a dense 88 × 6 table(a): a project with no edits stays byte-identical to today (as EDIT v1 did in T-045), the section is small, and an older build skips it
D6Model identity and presets(a) edits survive a model change: the fields are relative to the fit and keyed by MIDI note, so they mean the same on any 88-key model; a load with another model identity keeps them and adds one log line (n note edits were made with model X); presets carry them in a [notes] table ([notes.C4] or [notes."60"], keys = field names, tune_cents = 3.0), a preset load replaces all note edits (none in the preset = none after loading); (b) drop the edits when the model differs (T-019 D2’s default for model-keyed sections); (c) edits in state only, not in presets(a): the Spec asks to keep compatible edits and report incompatible ones; relative fields are always compatible. This revises T-019 D2’s dropped for this section only. (c) would lose a voicing when it is shared
D7Layout(a) Edit, top to bottom: Microtuning (as now), the scope pills, then the scope’s body. Note in the standard and wide classes: note list on the left (a 168-point column of 88 rows, scrolling on its own, the selected note centred when it changes elsewhere), rows on the right; narrow: a selector line (‹ › buttons, the note’s name, its override count) above the rows. Instrument: the model groups’ controls as on Play, one column. The dock’s picker and keyboard select the same note (PianoShared::selected_note) ; (b) the note list only in wide; (c) a pop-up note list(a): the Spec (side by side when wide, selector above when compact); at 720 points the list column leaves ~520 points for the rows, enough for label 106 + slider 125 + value 80 + effective and reset; the list is 88 short rows, drawn with show_rows so only the visible ones are laid out
D8Search and filter(a) no search box now (six fields, three Instrument rows); a Modified toggle that hides unedited rows and limits the note list to edited notes; Reset note and, behind a confirmation, Reset all notes; (b) a search box over row labels as the Spec lists(a): a search over six rows is noise; the Spec’s search returns when the String scope multiplies the rows (T-010)
D9Commit, Apply, undo(a) a drag updates continuously; a typed value commits on Enter or focus loss, Escape restores; invalid text stays in the field with a short message, the engine keeps the last valid value; no Apply (no edit is costly; it comes back if one becomes so); a committed note edit marks the state dirty (state.mark_dirty); no editor undo stack, reset is the way back; Instrument rows are parameters and get the host’s undo through gestures; (b) an editor undo stack for note edits(a): the Spec’s behaviour minus Apply; clack-extensions 0.2 has no binding for CLAP’s undo extension, so a stack of our own would not reach the host’s Undo menu

Done when

  • The gates of AGENTS.md pass, including bundle, clap-validator and the GUI smoke test.
  • Tests (written first):
    • Field metadata: ids unique and stable, defaults neutral, ranges valid, format/parse round-trip, names and units Latin-1 (like the parameter test).
    • CoeffSet (dsp): with no edits bit-identical to today; Tune +100 cents moves every mode of that key by 2^(1/12) and no other key; Level adds to every layer of that key; Brightness leaves partial 1 and adds b·log2 p to partial p; Sustain and Release scale the free and damped rates of that key only; Hammer contact scales the contact time at the strike; composition with String sustain, A4, Scala and an MTS-ESP master (D2).
    • Worker: setting edits publishes, one rebuild per change, a burst coalesces; a rebuild with edits is timed (warn above 10 ms).
    • State: NOTE round-trip; absent with no edits (project bytes as before); unknown field, note out of range, NaN, out-of-range value, truncated section; another model identity keeps the edits and reports (D6). Preset: [notes] round-trip by name and number, a preset without [notes] clears edits, a preset load ≡ the equivalent state load.
    • New parameters 11–13: defaults neutral, old projects and presets load unchanged, the default sound is unchanged (golden test).
    • egui frames: scope pills; the note list selects the note and the dock shows it (and the reverse, from a key click in Edit and the picker); a row drag changes the note edit and the effective value; Enter / Escape / invalid text; reset and Reset note; Modified filter; the list and rows in each width class (narrow selector, side by side at 720 and 1100); every Instrument-scope parameter appears once.
    • Host test (clack-host): an edited C4 renders differently from an unedited one and an unedited D4 renders sample-identical; a project saved with edits restores them; no_alloc with edits being changed while notes sound.
  • Smoke test: screenshots of Edit in Note scope (light and dark, 720 × 400 and 1100 × 600, one narrow) with an edited note, attached to the outcome.
  • The maintainer has edited a note in a DAW and heard it.

Outcome

  • Engine (crates/dsp/src/piano/edits.rs, new): NoteField (the six fields, their neutral values, compose: offsets add, factors multiply) and NoteEdits (88 × 6 values plus a presence bit per field; an override equal to the neutral value stays an override). CoeffSet::build(model, rate, settings, targets, edits) applies them per key (D1, D2): Tune multiplies the key’s frequency ratio after the tuning, Scala or MTS-ESP target; Level and Brightness (b · log2 p, the partial number now kept per mode in KeyModel::partial) add to every excitation layer; Sustain and Release divide the free and damped rates; Hammer contact goes into a per-key factor CoeffSet::contact that the strike multiplies into the contact time. With no edits and neutral Voicing values the tables are bit-identical (tested; the golden test passes unchanged).
  • Worker (D4): SettingsRequests holds the edits behind a mutex like the Scala tuning (set_note_edits publishes only on a change; note_edits clones); the worker rebuilds the whole set when the settings, the targets or the edits differ from the applied ones. A drag of 100 changes gave 1–9 builds; a rebuild takes milliseconds (the test warns above 10 ms).
  • Parameters (D3): Brightness (id 11, dB/oct, −6…+6), Release (12, ×, 0.25…4, log), Hammer contact (13, ×, 0.5…2, log), group Voicing, defaults neutral, Recompute. Deviation: D3 proposed AtStrike for Hammer contact; it goes through the coefficient set like the note field (the strike reads the factor from the current set), so Recompute; it is heard from the next strike either way. The note fields have their own ParamTable (params::NOTE_FIELDS, ids 1–6, not host parameters) for names, units, ranges, parsing and formatting, and help texts (NOTE_HELP) that say when a change is heard.
  • State and presets (D5, D6): NOTE v1 [1, count u16, count × (midi u8, field u16, value f32)], at most 88 × 16 records, written only when there are edits (a project without edits is byte-identical to before); a later version is skipped, a malformed v1 refuses the state like a malformed SCAL. Presets: [notes.C4] ([notes."C#4"], [notes."60"] also read), keys are the field names in lower case (tune, level, brightness, sustain, release, hammer_contact; a numeric key is read as a field id), a comment with name and unit. Snapshot::from_preset and to_preset take the field table. On load (apply_snapshot, state and preset alike) the edits replace all current ones; values are clamped to the field’s range; records naming no key, no field or no number are dropped and counted in one log line; with another model identity the edits are kept and one more log line says how many. Note names and the parser moved from the dock into instruments_params (note_name, parse_note).
  • Inspector (crates/piano/src/gui/inspector.rs, new; D7–D9): pills Instrument · Note and Modified. Note (the default): the note list (168 points, 88 rows drawn with show_rows, each name, MIDI number and edit count; it scrolls on its own and centres the selected note when the selection changes elsewhere), the target line (C4 · MIDI 60, Reset note, Reset all notes with a Yes/No confirmation), and one row per field: an override dot, the label (help on hover), slider, a text field, Reset when overridden, and under it the scope (NOTE / INSTRUMENT) with the source (on top of the tuning, on top of Gain, effective 1.20 × with Hammer contact 1.50 ×, inherits 1.00 × from String sustain). Typed text commits on Enter or focus loss, Escape restores, text that is no number stays with Not a number: type a value from … to … and changes nothing; a slider drag updates continuously. A committed edit marks the project dirty. Narrow: « and » on the target line instead of the list. Instrument: the groups Strings and Voicing as on Play. The list, the dock’s keyboard and picker share the selected note (Dock::choose scrolls a zoomed keyboard to it).
  • Deviation (layout): the inspector sits at the top of Edit and Microtuning under it; above it, Microtuning filled the visible part of Edit at 720 × 400. The note list’s height is that of the tab less the scope line, between 120 and 300 points.
  • Tests: edits::tests, coeffs::tests (bit-identity with no or neutral edits; each field changes only its key as documented; composition with String sustain, Brightness, Release, Hammer contact and A4; Tune on top of key targets), engine tests (the worker applies and coalesces edits; the contact factor), params (NOTE round trip and absence, malformed and later versions, the cap; [notes] by name and number, unknown notes and fields, a preset without notes; the note parser), tests/note_edits.rs through clack-host (+6 dB on C4 doubles its RMS and D4 renders sample-identical; neutral Voicing values leave the sound unchanged, others change it; a project keeps its edits and a load without them removes them; clamping and dropped records with one log line; another model keeps the edits; a preset round trip), no_alloc with Voicing automation and note edits changing while the chord rings, egui frames (the list and the keyboard select the same note; typed values commit, restore and report invalid text; row and note resets, reset all after a confirmation, the Modified filter; the layout per width class and the Instrument scope), the host metadata of ids 11–13.
  • Smoke test: with GUI_SMOKE_TAB=edit the loaded state carries edits of C4 (tune, level, brightness) and E4 (release) for the captures. In this container scripts/gui-smoke-test.sh failed because the gui-test shell finds the system’s /usr/bin/Xvfb first, which crashes on the shell’s Nix library path; running Nix’s Xvfb by hand (and waiting for its socket) worked.
  • Gates (2026-12-05): fmt, clippy, nextest (244 passed, 2 skipped), cargo test (as CI runs it), Julia Pkg.test(), cargo xtask bundle piano --release, clap-validator validate (38 passed, 0 failed, 6 skipped), the smoke test on Edit in light and dark at 720 × 400, 1100 × 600, 480 × 360 and scale 2, and on Play (the editor click still sounds: peak 0.37, tail 0.0013). The default sound is unchanged (golden test).
  • Not checked: a real DAW (hearing an edit, the project’s dirty mark, presets with [notes] in a host’s browser), macOS, Windows.

Captures from the X11 smoke test (Edit, Note scope, C4 with three edits, E4 with one): 720 × 400 light and dark, 1100 × 600 light and dark, 480 × 360, 720 × 400 at scale 2.