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; needsdownload.jl maestro, 1.9 GB;fitalso fits the Hardest touch and writes the preset;fit <onsets.csv> <model.csv>reports on other inputs without writing),t048_plot.pyfor the plot (matplotlib in a scratch venv).t050_layers.jl measure | fitmeasures all 16 Salamander layers (~1 min). A new model means rerunningt048_velocity.jl modelandfit(the preset names the model). Itincludes T-007’s script, so all scripts shareMain: give new helpers distinct names (read_csvandhalfwidthalready exist there). Anything from MAESTRO goes totraining/results/maestro/orpresets/maestro/(CC BY-NC-SA), never intocrates/. - T-035’s driver:
t035_tilt.jl measure | fit | check | hammer(~10 s, ~5 s, ~1 min, ~30 s with-t 8; all butfitneed the samples),t035_plot.py.fitwritest035_tilt.toml; its curve and pivot are copied by hand intoReferencePiano’sBELOW_FIRST_TILT_*constants (as T-050’s slope), thent007_reference_piano.jl buildand the Rust paths below. The pivot is computed from the first layer’s spectra indata/t048/model.csv, so it does not depend on whether that file was rendered with the tilt. A new model also means rerunningt048_velocity.jl modelandfit(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::newmultiplies every mode of a key by one ratio, and keeps the oldfreq × A4/440path exactly when the shift is 0). A stepped parameter is aDESCRIPTIONSentry withlabels; its value is the label index, stored asf32. 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 throughPianoMainThread::apply_snapshot(crates/piano/src/params.rs). A new model also means updating[model]incrates/piano/presets/*.inpiano(a test fails otherwise). - Tuning sources (T-049):
CoeffSet::with_targetstakes optional per-key first-partial targets (KeyTargets, Hz) on top of T-018’skey_cents;SettingsRequestsholds the external source (ExternalTuning, the plugin’sMtsClient, polled by the worker every 5 ms while MTS-ESP is on) and the Scala targets (set_scala). Note filtering is inaudio.rs(is_filtered). Tests play a master withinstruments_piano::testing::use_external_tuning(tests/common’sMaster);scripts/test-libmts.shruns the client against ODDSound’s reallibMTS.so. The Scala text lives in state sectionSCALand a preset’s[tuning]. MTS-ESP (id 10) is in the group Microtuning, whichgui.rsdraws 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
DESCRIPTIONSincrates/piano/src/params.rs(new id, never reuse one) plus its application inaudio.rs(Class::Recompute→SettingsRequestsviaupdate_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 ininstruments_piano::testingmust be thread-local; a process-wide hook passes locally under nextest and fails in CI. Before pushing test hooks, also runcargo test -p instruments-piano. - Note edits and inspector (T-047): per-note edits are
NoteEdits(crates/dsp/src/piano/edits.rs), applied inCoeffSet::build; they live inSettingsRequests(set_note_edits/note_edits), so the plugin keeps no other copy; state sectionNOTE, preset[notes.C4], both throughparams::note_records/note_edits_frominapply_snapshot. A new note field: aNoteFieldvariant (index = id − 1), aNOTE_FIELD_DESCRIPTIONSentry with itsNOTE_HELP, its effect inCoeffSet::build, andinstrument_indexif a parameter is its counterpart. The inspector isgui/inspector.rs; frame tests useinspector_harnessandtype_intoingui/tests.rs; integration tests set edits withtesting::edit_note_of_last_instanceor a state withNOTErecords. - 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) ingui/keyboard.rs. Integration tests play keys as the editor does throughinstruments_piano::testing::EditorKeys::of_last_instance()(“last” on the calling thread). Frame tests drive the dock with pointer events throughKeyboardHarnessingui/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.rslays 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) ingui/size.rs; layout tests draw headless egui frames at a size (draw_atingui/tests.rs; the middle region scrolls, so check presence in a tall window).GUI_SMOKE_SIZE=WxHresizes the open editor in the smoke test. The look follows mathstruct.org/instruments (palette ingui/palette.rsfrom the site’s CSS; wordmark ingui/wordmark.rsis the site’s SVG path data, rasterized bygui/outline.rs; slider ingui/slider.rs). New editor preferences go intoEDIT(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): thegui-testshell 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 runcargo test -p instruments-piano --test gui_x11 -- --ignored --nocapturewithDISPLAYset (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 todemos/CHANGES.md, commits, thenscripts/publish-demos.sh(--dry-runshows the tree; it refuses uncommitted changes indemos/,crates/,models/). Composed pieces: editcrates/demos/src/compose.rs, thencargo run -p instruments-demos -- compose. Mutopia needswww.mutopiaproject.org(allowed in theinstrumentsenvironment). - 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 incrates/dsp/tests/piano.rs,crates/model-format/tests/piano_v4.rsandcrates/dsp/examples/chord_attack.rs; delete the old directory (T-039 H5). Plugin tests incrates/piano/tests/host.rsrender through clack-host in 64-sample blocks;no_alloc.rsis 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) viaPianoEngine::set_pedal_settings, set by the plugin each block from parameters 14–16. A key’s damping weight isKeyState::damping; a span’sDecay(Free,Damped,Blended, the blend inModeState::br/bi) replaced the olddamped: bool. The soft pedal usesCoeffSet::level_db/softer(rebuilt with each set).GUI_SMOKE_PEDALS=halfcaptures the dock with all three pedals in use. - Engine:
PianoEngine::new(&PianoModelV4)thenprepare(rate, max_block)(both allocate; ~ms; defaultSettings, no worker) or, in the plugin,activate(rate, Arc<SettingsRequests>)(starts the coefficient worker, joined on drop);event/renderare real-time safe andrendersets FTZ itself; a host that splits blocks callsbegin_blockonce andrender_segmentper piece (T-016). Keys in hammer contact go throughresonator::process_attack(≈ 2× per mode while in contact);cargo run -p instruments-dsp --release --example chord_attacktimes it. NoteOn velocity is 0..1 and mapped ×127 to MIDI velocity. Golden margin is ~2× because Julia renders the golden output fromf64tables while the file holdsf32; if a new model fails narrowly, render the golden from thef32-rounded tables in Julia. cargo nextest run --releasedoes not build the dsp tests (assert_no_alloc::AllocDisableris debug-only, pre-existing inprocessor.rs); debug runs are the gate. For release timing use a throwaway example.- Model files: load with
instruments_model_format::piano::PianoModelV4::load(dir)andPianoGolden::load(dir, &model); arrays are row-major with the Julia shape (at(&[k, s, q, p]),row(prefix)). Julia writes throughwrite_piano_model; a change of format means bumpingformat_versionon both sides and in the page. - T-042’s driver:
t042_contact.jl measure(onset rise per sample →t042_rise.csv, ~1 min) andcheck(attack level, onset steps →t042_check.csv); the contact law iscontact_lawint007_reference_piano.jl,build(...; contact = false)gives the impulse tables. - T-039’s driver:
t039_release_fit.jl fit(~1 min; needs the samples) writest039_damper.toml, which T-007’sbuildreads forpartial.damped_decay(MODEL_VERSIONthere 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; needsdata/t038/env_b.csv),build(~1.5 min: tables, model directory, renders indata/t007/),check(~1 min, needs the samples; prints the attack-level table and lists samples > +6 dB).EXCLUDEDholds left-out layers. Scripts thatincludethe T-036–T-038 drivers shareMain(render,prepareexist there).prepare(...; fade = true)fails on some samples. T-038’sfitnow usesEDGES = (0.5, 2, 6); the previous run is indata/t038/v2/. - T-038’s driver:
diag34 min,fit5 min,audio [samples…]~1 h for 7 samples;reportrebuilds the tables fromdata/t038/and writes them toresults/; it reads T-037’sdata/t037/stage_b.csv.TailFit.fade_startgives a sample’s fade-out;CurveProblem(...; ndev)andPenalisedcarry per-partial deviations. Julia:0.75f0is a Float32 literal, write0.75 * f0. - T-037’s driver
t037_fit_keyboard.jl: stages A and B take ~7 h with-t 4; checkpoints indata/t037/(stage A, B0, B progress every 25 steps); modesB,B0B,BRrestart 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 indata/t036/to listen to. - T-006’s full run takes ~42 min with
-t 4;t006_analyse_salamander.jl C4v8prints one sample’s fits in ~30 s.partials.csvhas per-partial decay fits (columns intraining/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).