T-009 — The piano CLAP plugin: the plugin plays the v1 engine with the committed Salamander model
Status: done (manual DAW check done in Reaper, 2026-12-03) — D1 (compiled in) chosen, D2–D5 accepted (maintainer, Dec 2026) · Area: rust, piano · Depends on: T-008
Read for that: T-008 (Outcome), T-003 (plugin structure, Fixes after review), Plugin formats (audio-thread rules), ADR-0001, ADR-0007 (attribution), crates/piano/src/{lib,audio,gui}.rs, crates/dsp/src/piano/engine.rs, crates/model-format/src/piano.rs.
Why: T-008’s PianoEngine plays the fitted model, but the plugin still plays T-003’s placeholder SineVoices. T-009 swaps in the engine, so the plugin sounds like the piano in a DAW. The egui GUI stays T-003’s editor until T-020.
What
- The plugin carries the committed
salamander-c5model (D1), parses it once (D2) and builds aPianoEngineinactivate(new+prepare, main thread). processdrives the engine instead ofSineVoices: note on/off (CLAP and MIDI dialects), the sustain pedal (D3), Gain; sleeps when the engine is inactive (unchanged rule).- The editor and the descriptor drop the “placeholder sine” wording and show the model and its attribution (D4).
Decisions
| Question | Options | Proposal | |
|---|---|---|---|
| D1 | How the plugin finds its model | (a) compiled in with include_bytes! (manifest 2.4 kB + tensors 0.7 MB) and parsed with PianoModelV1::from_bytes; (b) a resources folder in the bundle (Linux/Windows .clap is a single file, so the folder would sit next to it and has to be found through the library’s path); (c) a path stored in the state | (a): nothing to find, nothing to lose, no file I/O; the plugin grows by 0.7 MB. Loading other models from a file comes with presets and settings (T-019/T-030) |
| D2 | When the model is parsed and the engine built | (a) parsed once per process into a OnceLock on the first instance’s new_shared (an invalid model fails instantiation); activate builds PianoEngine::new + prepare (allocates, ~ms, main thread); (b) parse in every activate | (a): parsing and validation once; activate is the CLAP place to allocate |
| D3 | Sustain pedal and controller messages | (a) MIDI CC 64 (value ≥ 64 down) → Event::Sustain, from either dialect (CLAP hosts send controllers as MIDI events); CC 120 (all sound off) and CC 123 (all notes off) → Event::AllNotesOff; (b) a pedal parameter as well | (a): CC 64 is what keyboards and hosts send; a pedal parameter can come with T-025 |
| D4 | What the GUI shows until T-020 | (a) T-003’s editor (title, Gain) plus the model name and the attribution line CC BY requires (Salamander Grand Piano V3 by Alexander Holm, CC BY 3.0; model CC BY 4.0); the descriptor’s description says “Modal piano (work in progress)”; (b) nothing new | (a): CC BY needs the attribution where the sound is used (ADR-0007) |
| D5 | Mono output (a host giving one channel) | (a) mic 1 only (the engine renders stereo into stack chunks, as now); (b) the sum of both mics | (a): summing two mics comb-filters; a mic blend is T-020 |
Done when
Tests first, in crates/piano/tests/host.rs (clack-host, in-process): a note-on yields non-silent output and the processor sleeps again after the key’s decay with the pedal up; with CC 64 down a released key keeps sounding where without it the tail falls by > 40 dB; MIDI-dialect note-on equals CLAP-dialect note-on; the output at 44.1 kHz and 96 kHz is finite. process allocates nothing (assert_no_alloc around it in debug tests). All gates green, including cargo xtask bundle piano --release and clap-validator validate, and the GUI smoke test (the editor’s text changes).
Pages: this page’s Outcome, T-003’s placeholder note, backlog row and Status. Manual DAW check by the maintainer (as T-003’s).
Out of scope: loading models from a file (T-019/T-030), parameter swaps (T-016), velocity curve and tuning (T-018), GUI controls (T-020), a release fit for the dampers (T-039).
Outcome
- Code:
crates/piano/src/model.rs(model(): the committedmodels/piano/salamander-c5/2026-12-01-r2/manifest and tensors throughinclude_str!/include_bytes!, parsed once into aOnceLockon the firstnew_shared;attribution()),PianoShared.model,audio.rs(PianoEngine::new+prepareinactivate; CC 64 →Event::Sustain, CC 120/123 →AllNotesOff; mono = mic 1), the editor (460×200) shows “modal piano, stage 1” and the attribution line built from the manifest. The descriptor and the crate description no longer say “placeholder”.SineVoicesstays incrates/dsp(its processor tests), unused by the plugin. - Size: the release bundle is 8.3 MB on Linux (the model is 0.7 MB of it).
- Tests (
crates/piano/tests/host.rs, in-process clack host): silence and sleep without notes; a struck key sounds, the two channels differ, Gain −40 dB works, a released key dies away and the plugin sleeps again; with CC 64 down the tail 0.5–0.7 s after release is > 40 dB above the damped one; pedal up damps again; MIDI note-on (velocity 102) equals CLAP note-on (102/127) within 1e-6 of the peak; CC 120 silences at once; A0 + C8 finite and sounding at 44.1 and 96 kHz.tests/no_alloc.rs:processwith six notes, a MIDI note, pedal down/up and a gain change underassert_no_alloc. Unit test: the built-in model parses and its attribution names Salamander (CC BY 3.0) and the model’s CC BY 4.0. - Gates: fmt, clippy,
cargo nextest run(50 tests);cargo xtask bundle piano --release+clap-validator0.4.1: 35 passed, 0 failed, 9 skipped (as T-003); GUI smoke test passes. - Not done here: the manual check in a DAW (as T-003’s: load, play, pedal, Gain, reopen the editor, save and reload). Result: done in Reaper, 2026-12-03, see T-003 (pedal and editor fine; factory presets not listed by Reaper).
The host callback corrections and their regression checks are tracked in T-041.