Piano notes — working hints for piano tasks

Keep current; read only for piano tasks.

  • T-048/T-050 drivers: t048_velocity.jl model | measure | fit (~12 s, ~10 s, ~3 min with -t 8; needs download.jl maestro, 1.9 GB; fit also fits the Hardest touch and writes the preset; fit <onsets.csv> <model.csv> reports on other inputs without writing), t048_plot.py for the plot (matplotlib in a scratch venv). t050_layers.jl measure | fit measures all 16 Salamander layers (~1 min). A new model means rerunning t048_velocity.jl model and fit (the preset names the model). It includes T-007’s script, so all scripts share Main: give new helpers distinct names (read_csv and halfwidth already exist there). Anything from MAESTRO goes to training/results/maestro/ or presets/maestro/ (CC BY-NC-SA), never into crates/.
  • T-035’s driver: t035_tilt.jl measure | fit | check | hammer (~10 s, ~5 s, ~1 min, ~30 s with -t 8; all but fit need the samples), t035_plot.py. fit writes t035_tilt.toml; its curve and pivot are copied by hand into ReferencePiano’s BELOW_FIRST_TILT_* constants (as T-050’s slope), then t007_reference_piano.jl build and the Rust paths below. The pivot is computed from the first layer’s spectra in data/t048/model.csv, so it does not depend on whether that file was rendered with the tilt. A new model also means rerunning t048_velocity.jl model and fit (the preset moves: T-035 shifted γ from 2.38 to 1.96).
  • Tuning (T-018): maths in crates/dsp/src/piano/tuning.rs (key_cents: per-key first-partial cents from 12-TET; CoeffSet::new multiplies every mode of a key by one ratio, and keeps the old freq × A4/440 path exactly when the shift is 0). A stepped parameter is a DESCRIPTIONS entry with labels; its value is the label index, stored as f32. Parameter text stays within Latin-1 (the editor’s font has no ♯/♭; a test checks).
  • State and presets (T-019): new non-parameter state is a new v4 section (4-byte tag) in crates/params/src/state.rs, never a new version; state and preset loads both go through PianoMainThread::apply_snapshot (crates/piano/src/params.rs). A new model also means updating [model] in crates/piano/presets/*.inpiano (a test fails otherwise).
  • Tuning sources (T-049): CoeffSet::with_targets takes optional per-key first-partial targets (KeyTargets, Hz) on top of T-018’s key_cents; SettingsRequests holds the external source (ExternalTuning, the plugin’s MtsClient, polled by the worker every 5 ms while MTS-ESP is on) and the Scala targets (set_scala). Note filtering is in audio.rs (is_filtered). Tests play a master with instruments_piano::testing::use_external_tuning (tests/common’s Master); scripts/test-libmts.sh runs the client against ODDSound’s real libMTS.so. The Scala text lives in state section SCAL and a preset’s [tuning]. MTS-ESP (id 10) is in the group Microtuning, which gui.rs draws on the Edit tab (EDIT_GROUPS), and on Play too in the wide layout (T-045).
  • Parameters (T-025): a new parameter is one entry in DESCRIPTIONS in crates/piano/src/params.rs (new id, never reuse one) plus its application in audio.rs (Class::Recompute → SettingsRequests via update_recompute/sync_recompute); state v3 needs no bump.
  • Test hooks are per thread: CI runs cargo test (the tests of one binary as parallel threads in one process), not nextest (one process per test), so anything in instruments_piano::testing must be thread-local; a process-wide hook passes locally under nextest and fails in CI. Before pushing test hooks, also run cargo test -p instruments-piano.
  • Note edits and inspector (T-047): per-note edits are NoteEdits (crates/dsp/src/piano/edits.rs), applied in CoeffSet::build; they live in SettingsRequests (set_note_edits/note_edits), so the plugin keeps no other copy; state section NOTE, preset [notes.C4], both through params::note_records/note_edits_from in apply_snapshot. A new note field: a NoteField variant (index = id − 1), a NOTE_FIELD_DESCRIPTIONS entry with its NOTE_HELP, its effect in CoeffSet::build, and instrument_index if a parameter is its counterpart. The inspector is gui/inspector.rs; frame tests use inspector_harness and type_into in gui/tests.rs; integration tests set edits with testing::edit_note_of_last_instance or a state with NOTE records.
  • Editor notes (T-046): ownership and the editor’s note path in crates/piano/src/notes.rs (NoteTable, EditorNotes); the dock (keyboard geometry, Player, picker, zoom) in gui/keyboard.rs. Integration tests play keys as the editor does through instruments_piano::testing::EditorKeys::of_last_instance() (“last” on the calling thread). Frame tests drive the dock with pointer events through KeyboardHarness in gui/tests.rs. The smoke test clicks a key (GUI_SMOKE_TAB=play|edit, GUI_SMOKE_ZOOM=0|1|2).
  • Editor (T-020, T-044, T-045): crates/piano/src/gui.rs lays out controls from the table (control_sections); a new parameter gets its control without GUI code. The window is resizable: size logic and the width classes (Narrow < 700, Standard, Wide ≥ 1000 logical points) in gui/size.rs; layout tests draw headless egui frames at a size (draw_at in gui/tests.rs; the middle region scrolls, so check presence in a tall window). GUI_SMOKE_SIZE=WxH resizes the open editor in the smoke test. The look follows mathstruct.org/instruments (palette in gui/palette.rs from the site’s CSS; wordmark in gui/wordmark.rs is the site’s SVG path data, rasterized by gui/outline.rs; slider in gui/slider.rs). New editor preferences go into EDIT (bump its inner version byte; v2 holds theme and size, v1 is still written while no size is kept). GUI_SMOKE_THEME=light|dark GUI_SMOKE_SCALE=1|1.5|2 GUI_SMOKE_PPM=<file.ppm> scripts/gui-smoke-test.sh (in .#gui-test) captures the editor while a chord plays; convert the PPM to PNG (no ImageMagick in the shells; a stdlib-Python PNG writer works). If the smoke test cannot connect to the X server (ConnectionRefused): the gui-test shell may find the system’s /usr/bin/Xvfb, which crashes on the shell’s library path; start Nix’s (ls -d /nix/store/*-xvfb-*/bin/Xvfb) by hand on a free display, wait for /tmp/.X11-unix/X<n>, then run cargo test -p instruments-piano --test gui_x11 -- --ignored --nocapture with DISPLAY set (T-047). Helpers in a sandbox (Codex) cannot run Xvfb or clap-validator’s subprocess mode; run those two gates yourself.
  • Demo renders (T-040): a task that changes the sound runs cargo xtask render-demos, adds a line to demos/CHANGES.md, commits, then scripts/publish-demos.sh (--dry-run shows the tree; it refuses uncommitted changes in demos/, crates/, models/). Composed pieces: edit crates/demos/src/compose.rs, then cargo run -p instruments-demos -- compose. Mutopia needs www.mutopiaproject.org (allowed in the instruments environment).
  • Plugin: the model is compiled in from models/piano/salamander-c5/2026-12-04/ (crates/piano/src/model.rs; format v4); a new model means a new directory and changing that path, the golden test in crates/dsp/tests/piano.rs, crates/model-format/tests/piano_v4.rs and crates/dsp/examples/chord_attack.rs; delete the old directory (T-039 H5). Plugin tests in crates/piano/tests/host.rs render through clack-host in 64-sample blocks; no_alloc.rs is its own test binary because of the global allocator.
  • Pedals (T-010): Event::Sustain(f32) / Soft(f32) are travel 0…1, Sostenuto(bool); PedalSettings (zone, soft depth) via PianoEngine::set_pedal_settings, set by the plugin each block from parameters 14–16. A key’s damping weight is KeyState::damping; a span’s Decay (Free, Damped, Blended, the blend in ModeState::br/bi) replaced the old damped: bool. The soft pedal uses CoeffSet::level_db/softer (rebuilt with each set). GUI_SMOKE_PEDALS=half captures the dock with all three pedals in use.
  • Engine: PianoEngine::new(&PianoModelV4) then prepare(rate, max_block) (both allocate; ~ms; default Settings, no worker) or, in the plugin, activate(rate, Arc<SettingsRequests>) (starts the coefficient worker, joined on drop); event/render are real-time safe and render sets FTZ itself; a host that splits blocks calls begin_block once and render_segment per piece (T-016). Keys in hammer contact go through resonator::process_attack (≈ 2× per mode while in contact); cargo run -p instruments-dsp --release --example chord_attack times it. NoteOn velocity is 0..1 and mapped ×127 to MIDI velocity. Golden margin is ~2× because Julia renders the golden output from f64 tables while the file holds f32; if a new model fails narrowly, render the golden from the f32-rounded tables in Julia.
  • cargo nextest run --release does not build the dsp tests (assert_no_alloc::AllocDisabler is debug-only, pre-existing in processor.rs); debug runs are the gate. For release timing use a throwaway example.
  • Model files: load with instruments_model_format::piano::PianoModelV4::load(dir) and PianoGolden::load(dir, &model); arrays are row-major with the Julia shape (at(&[k, s, q, p]), row(prefix)). Julia writes through write_piano_model; a change of format means bumping format_version on both sides and in the page.
  • T-042’s driver: t042_contact.jl measure (onset rise per sample → t042_rise.csv, ~1 min) and check (attack level, onset steps → t042_check.csv); the contact law is contact_law in t007_reference_piano.jl, build(...; contact = false) gives the impulse tables.
  • T-039’s driver: t039_release_fit.jl fit (~1 min; needs the samples) writes t039_damper.toml, which T-007’s build reads for partial.damped_decay (MODEL_VERSION there names the output directory). Clap-validator and the plugin tests time releases: C4’s damped T60 is ~1.5 s now.
  • T-007’s driver: t007_reference_piano.jl export (seconds; needs data/t038/env_b.csv), build (~1.5 min: tables, model directory, renders in data/t007/), check (~1 min, needs the samples; prints the attack-level table and lists samples > +6 dB). EXCLUDED holds left-out layers. Scripts that include the T-036–T-038 drivers share Main (render, prepare exist there). prepare(...; fade = true) fails on some samples. T-038’s fit now uses EDGES = (0.5, 2, 6); the previous run is in data/t038/v2/.
  • T-038’s driver: diag 34 min, fit 5 min, audio [samples…] ~1 h for 7 samples; report rebuilds the tables from data/t038/ and writes them to results/; it reads T-037’s data/t037/stage_b.csv. TailFit.fade_start gives a sample’s fade-out; CurveProblem(...; ndev) and Penalised carry per-partial deviations. Julia: 0.75f0 is a Float32 literal, write 0.75 * f0.
  • T-037’s driver t037_fit_keyboard.jl: stages A and B take ~7 h with -t 4; checkpoints in data/t037/ (stage A, B0, B progress every 25 steps); modes B, B0B, BR restart from them. Run long jobs detached (nohup setsid … &): the Bash tool stops background jobs after 2 h, and the container can restart (it did once, mid stage B).
  • T-036’s driver: t036_fit_real_note.jl C4v8 (~18 min, both mics in parallel), --sweep C4 (~76 min); 1.25 s per Adam step for 16 partials over 6 s. Renders land in data/t036/ to listen to.
  • T-006’s full run takes ~42 min with -t 4; t006_analyse_salamander.jl C4v8 prints one sample’s fits in ~30 s. partials.csv has per-partial decay fits (columns in training/results/salamander/README.md).
  • Pkg.test() loads Enzyme (first run precompiles for minutes; tests ~1 min). T-013’s driver: julia --project=training -t 4 training/scripts/t013_fit_one_note.jl (~6 min).