T-050 — Shaped velocity response: the model’s level below its first layer from Salamander’s own soft layers, and a velocity curve that can follow MAESTRO’s bend
Status: done · Implementation: Claude · Area: julia, rust · Depends on: T-048
Read for that: T-048 (Outcome: the measured curve), T-018 (D2: Velocity curve, ), ADR-0007 (MAESTRO-derived numbers stay out of the plugin; Salamander-derived ones may go in), crates/dsp/src/piano/model.rs (velocity_weights), training/src/ReferencePiano.jl (BELOW_FIRST_DB_PER_DECADE, excitation_db), crates/piano/src/audio.rs (shape_velocity).
Why: one exponent barely improves T-048’s fit (RMS 3.79 → 3.68 dB) because the measured Disklavier-velocity → model-velocity map is S-shaped: the softest notes () are louder than the model plays them, the soft range ( 30–65) softer, the top () louder, reaching the model’s last layer near . Part of this may be the model rather than the curve.
What the samples already say (probe, 2026-12-03)
The model uses four of Salamander’s 16 layers (v4, v8, v12, v16 at MIDI 40, 60.5, 92.5, 124, the middles of their SFZ ranges); below v4 it extrapolates with a guessed 40 dB/decade (T-007 H3). Salamander’s own v1–v3 (SFZ ranges 1–26, 27–34, 35–36) are recorded but unused. Broadband attack level 10–110 ms after onset, relative to v4:
| key | v1 (13.5) | v2 (30.5) | v3 (35.5) | v12 (92.5) | v16 (124) |
|---|---|---|---|---|---|
| C2 | −11.5 | −3.8 | −1.3 | +5.8 | +10.2 |
| C4 | −7.6 | −3.6 | −1.7 | +7.8 | +9.8 |
| C6 | −5.6 | −1.7 | +0.7 | +12.4 | +16.5 |
| C7 | −9.3 | −7.9 | −3.3 | +11.8 | +19.0 |
| mean C2–C7 (6 keys) | −8.6 | −4.3 | −1.5 | ||
| model (40 dB/decade) | −18.9 | −4.7 | −2.1 |
So at MIDI 13.5 the model is ~10 dB too quiet against the very piano it was fitted to. That is the direction of T-048’s bottom bin ( 1–29 needed 18.6 where the exponent gave 6.0). The intermediate layers (e.g. C4 v9 at 68.5: +4.4 dB, interpolated +4.6) agree with the model’s dB-linear interpolation, so between 40 and 124 the model follows its recordings. The top of the bend ( needing ) cannot come from the model: v16 is the loudest recording, so that part belongs to the curve.
What
- Measure (
training/scripts/t050_layers.jl): the attack level of all 16 layers of every sampled key from C2 to C7 (21 keys; T-048’s feature, below, is not resolvable in the low bass, where a 100 ms window does not separate the harmonics, nor above C7, where few harmonics lie below 5 kHz), in T-048’s feature (harmonic bands 1–6 below 5 kHz, 10–110 ms), relative to v4; table and plot totraining/results/salamander/(CC BY 4.0). - Model below the first layer (D1): fit the law on step 1’s levels of v1–v3, replace T-007’s guess, rebuild the model (new
MODEL_VERSIONdirectory, golden vectors, the Rust paths listed in Status’ Plugin hint), and re-render the demos (T-040). The default sound changes only below MIDI 40. - Refit T-048 against the new model (
t048_velocity.jl model | fit); check the bottom bin for selection bias by repeating the fit with the onset-rise threshold at 6 dB instead of 10. - Curve (D2): build the curve family, fit it in
t048_velocity.jl fit, and updatepresets/maestro/maestro-velocity.inpiano(still CC BY-NC-SA, outside the plugin).
Decisions (accepted by the maintainer, 2026-12-03)
| Question | Options | Proposal | |
|---|---|---|---|
| D1 | Level below the first layer | (a) keep the format’s one number, below_first_layer_db_per_decade, fitted on v1–v3 of all keys (least squares through v4; ≈ 20 dB/decade from the probe, but it misses v2 by ~2 dB); (b) a new law, level linear in velocity below the first layer (≈ 0.33 dB per MIDI step from the probe; v1 within 0.1 dB, v2 within 1.2 dB), a new excitation.below_first field, format v2 → v3; (c) add v1 (and v2) as excitation layers (T-037/T-038 refits, hours; model +25–50 %; also gives their softer spectrum) | (b): it matches the recordings at both soft layers for one number and a small format change; (a) is the fallback if the format bump is unwanted; (c) is the right answer only if a soft note’s timbre matters, which T-048 does not measure |
| D2 | Curve family | (a) two parameters: Velocity curve (as now) and a new Hardest touch (MIDI 64–127, default 127): ; (b) T-018 D2 (b): Softest and Hardest output velocities; (c) a piecewise-linear curve with fixed knots (3–5 new parameters, editor work) | (a): on T-048’s measured curve, , follows the bins within ~3 MIDI steps (e.g. : 75 vs 74.6 measured; : 95 vs 94.6), where one exponent misses by up to 29; one new id, class AtStrike, one more multiply at note-on; default 127 leaves every project unchanged. (b) moves the outputs, but the data need the input range compressed. (c) only if (a) leaves a bend after D1 |
| D3 | Order | (a) D1 first, refit, then D2 on what is left; (b) D2 alone | (a): with the bottom fixed in the model, D2’s fit is not pulled by a defect the curve should not paper over; the model change also helps every MIDI source, not only the preset’s users |
Done when
- Step 1’s table covers every sampled key; a test (written from this page) checks the D1 law against a synthetic level table, and the Rust
velocity_weightsand Juliaexcitation_dbagree on the new law at generated velocities (both sides tested). - The rebuilt model passes the golden tests; demos re-rendered with a line in
demos/CHANGES.md. - T-048’s refit reported before and after D1 and with the 6 dB threshold; for D2 the RMS residual and the per-bin table against the measured curve; the preset updated and its preset test passing with the new parameter.
- Hardest touch (if D2 a): unit test of the curve (identity at defaults, monotone, endpoints), state round-trip; gates of AGENTS.md including bundle +
clap-validator(plugin code changes); the editor shows the new control without GUI code (T-020), so the GUI smoke test runs once.
Outcome
D1, the model: below MIDI 40 the level now falls by 0.36 dB per velocity step (model format v3, excitation.below_first_layer_db_per_velocity), fitted on Salamander’s own layers v1–v3 of the 21 sampled keys C2–C7 (RMS 1.94 dB; one slope per decade would give 20.5 dB, RMS 2.28 dB; T-007’s guessed 40 dB/decade missed by RMS 5.95 dB). Plot training/results/salamander/t050_layers.png, table t050_layers.csv. Model salamander-c5/2026-12-03: its tables are byte-identical to 2026-12-02; only the manifest’s law and the golden output (C7 at velocity 20) changed. Velocity 20 is now −7.2 dB from velocity 40 (was −12 dB), velocity 10 −10.8 dB (was −24 dB).
T-048 refit (1,136 onsets; Huber-clamped RMS; mean residual per Disklavier-velocity bin u 1–29, 30–44, 45–54, 55–64, 65–74, 75–84, 85–94, 95–109):
| fit | RMS dB | mean residual per bin, dB |
|---|---|---|
| old model, one exponent (T-048: γ 1.43) | 3.68 | −6.6 … +2.0 … −6.1 (bent) |
| new model, one exponent (γ 1.78) | 3.57 | +1.6, +1.9, +1.2, +0.2, −0.7, −2.1, −2.2, −5.0 (bent) |
| new model, γ and Hardest touch (γ 2.38, H 85.3) | 3.46 | −1.2, +0.1, +0.7, +0.4, −0.1, 0.0, −0.2, −3.0 (flat but the top bin, 15 onsets) |
| old model, γ and H (γ 1.64, H 84.2) | 3.62 | — |
| new model, γ and H, onset-rise threshold 6 dB (1,205 onsets) | 3.47 | γ 2.41, H 84.5; lowest bin −0.1 |
So both steps were needed: D1 removes the bottom of the bend, D2 the top. The 6 dB threshold changes nothing material, so the soft bins are not a selection artefact. The remaining RMS is scatter (per-key voicing, polyphony), not shape. Plot training/results/maestro/t048_velocity.png (curves, residual per bin under each, residual per onset).
The page’s D2 estimate was wrong in its numbers, not its form: H ≈ 104 and γ ≈ 2 were read off T-048’s “measured curve”, which holds the single exponent’s per-piece and per-key offsets fixed. Between the layers the model’s level is close to logarithmic in velocity, so scaling the input velocity (what H does) is nearly the same as a level offset; H is pinned only by the saturation at the top and by the law below MIDI 40, and the joint fit with free offsets lands at H ≈ 85. The “v (measured)” column of t048_bins.csv keeps T-048’s meaning (offsets of the single exponent) and is not comparable with the H fit.
Preset: presets/maestro/maestro-velocity.inpiano now holds Velocity curve −62.5 % and Hardest touch 85.3 (still CC BY-NC-SA 4.0, outside the plugin; model 2026-12-03).
What was built:
training/scripts/t050_layers.jl measure | fit(~1 min with-t 8, needs the samples),t050_plot.py;VelocityFit.fit_below_first,shape_velocity,fit_curve(γ grid per H on a coarse H grid, both refined by golden section),fit_gamma(...; hardest); tests intraining/test/velocityfit.jl.- Format v3 on both sides:
PianoModelFile.jl(PIANO_FORMAT_VERSION = 3),ReferencePiano.excitation_db(BELOW_FIRST_DB_PER_VELOCITY = 0.36),crates/model-format(FORMAT_VERSION = 3, the type renamedPianoModelV3, test filetests/piano_v3.rs: v1, v2, a negative slope and the old field refused),PianoModel::velocity_weights(unit test below, at and above the layers). t048_velocity.jl:fitalso fits γ with H and writes both into the preset;measure <rise_db> <out.csv>andfit <onsets.csv> <model.csv>(report only) for the checks above.- Plugin: parameter Hardest touch (id 9, MIDI 64–127, default 127, class
AtStrike, group Hammer, appended so index = id − 1):shape_velocity(x, c, H) = min(1, x·127/H)^γ, bit-identical at the defaults. Tests: curve unit tests inaudio.rs, host metadata and a host render (hardest_touch_strikes_a_soft_note_harder), the editor’s control count (6 sliders fit the Play view; checked in the GUI capture). - Demos re-rendered (
demos/CHANGES.md). - Gates (2026-12-03):
cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo nextest run(163 passed, 1 skipped), JuliaPkg.test()(2,505 passed, after the review fixes),cargo xtask bundle piano --release+clap-validator(38 passed, 0 failed, 6 skipped),scripts/gui-smoke-test.sh(passed).
Review triage (Mistral Large and Codex, 2026-12-03)
Both reviewed the diff against this page’s What and Decisions. Both checked the cross-language agreement with probes: excitation_db against velocity_weights over velocities −5…130 differ by at most 2e-15 dB, and shape_velocity in Julia and Rust by at most 4e-5 MIDI steps. Both found the fitted numbers consistent with the committed CSVs.
| Point | From | Right? | Done |
|---|---|---|---|
| step 1’s plot missing, results README without the new files, status hint naming the deleted model, backlog row still open, no 6 dB report | both | yes when they looked; written after their snapshot | — |
doc comments still say format v2 (model-format, dsp/piano/model.rs, overview) | Mistral | yes | changed to v3 |
| the MAESTRO preset test and the state/preset round trip do not check id 9 | both | yes (a missing check; Codex showed the test passing with "9" removed) | assertions added (preset: present and in 64–127, loaded value; round trip: id 9 = 70) |
| the shipped 0.36 is not the fit’s 0.3598 | Mistral | rounding, now said where the constant is defined and on the model-file page | — |
model_db48 clamps the model lookup at velocity 1, but a shaped curve reaches lower (u = 10 → v 0.77: 0.08 dB off) | Codex | yes | below 1 the line through velocities 1 and 2 is extended (exact: below the first layer the level is linear in velocity); fits rerun |
| the γ search (0.2–5) is wider than the plugin’s (0.25–4), so a fit could report a residual for a curve the preset cannot hold | Codex | yes (failing test first: synthetic γ 4.8 and 0.21) | default grids now span 4^∓1; test kept |
t050_layers.jl fit writes NaN into the TOML when a layer is missing | Codex | yes | fit refuses an incomplete table, naming the keys |
| only 21 of 30 sampled keys measured | Codex | by design (the feature is resolvable only C2–C7) | What 1 now says so |
| the demo listing still names 2026-12-02 | Codex | not reproduced: it read its own worktree’s stale target/; the main checkout’s listing names 2026-12-03 | — |
| the layer CSV holds absolute levels | Codex | by design (dB on an arbitrary reference, relative values taken in fit, README says so) | — |
Julia’s validator accepts manifests the Rust reader refuses (version 3.0, a rate above u32, untyped optional sources/fit fields) | Codex | yes, pre-existing (since v1), not caused by T-050 | not fixed here; the writer only writes valid values; recorded for the next change of the format |