T-040 — Demo renders: a few MIDI pieces rendered with the current piano, refreshed whenever the sound changes
Status: done — D1–D4 accepted (maintainer, Dec 2026): (a) + (b), (a), (a), (a) · Area: rust, piano, docs · Depends on: T-009
Read for that: T-009 (engine and model as the plugin plays them), T-008 (PianoEngine API), ADR-0007 (what may be published), the Backlog flow.
Why: the maintainer wants to hear how the piano sounds now, without a DAW and without access to the session’s machine, and to follow how it changes from task to task. A handful of short pieces in different styles, rendered with exactly what the plugin plays, in a place reachable from GitHub.
What
- Offline renderer
cargo xtask render-demos(or a smallcrates/demosbinary): reads standard MIDI files (note on/off with velocity, CC 64 sustain, tempo map) with a MIDI crate, plays them throughinstruments_dsp::PianoEnginewith the model the plugin compiles in, at 48 kHz in 64-sample blocks (as a host would), and writes stereo WAV. The output is peak-normalised with a fixed headroom and the same gain for all pieces, so loudness changes between iterations stay audible. - Encoding to a compressed format (D3) with a tool from the flake.
- Demo set
demos/midi/(D1): 5–6 pieces of 30–90 s each in different styles, with ademos/README.mdthat lists each piece, its source and licence, and what to listen for (attack, release, pedal, bass, treble, repeated notes). - Publishing (D2), with a
demos/CHANGES.mdline per refresh: the date, the commit, the task, and what changed in the sound. - The flow: a line in the backlog’s per-task flow says “when the task changes the sound (model, engine, plugin DSP), run
render-demosand publish”.
Decisions
| Question | Options | Proposal | |
|---|---|---|---|
| D1 | Where the MIDI comes from (licences, ADR-0007) | (a) public-domain compositions as MIDI files under a free licence (Mutopia Project: CC0 / CC BY / CC BY-SA, per file), e.g. Bach prelude (baroque), Chopin nocturne (romantic), Satie Gymnopédie (impressionist, sparse), Joplin rag (ragtime), plus (b); (b) short pieces written in the repo by a script (we own them, MIT/CC0): a blues/boogie bass, jazz voicings with pedal, a pop-ballad chord pattern, a velocity and register test; (c) MAESTRO performances: real human timing, but CC BY-NC-SA, so the renders would be NC too and could not sit beside the MIT code | (a) + (b): real repertoire for musical judgement, (b) covers genres whose repertoire is still in copyright (pop, jazz standards) and gives exact tests. Sequenced MIDI sounds mechanical, which is acceptable here. (c) only privately, as ADR-0007 already says |
| D2 | Where the audio lives, so it is reachable without the machine and does not bloat main | (a) the orphan branch listening, force-pushed with one commit per refresh: always exactly the current files, no growing history, linked from the README; (b) commit to demos/ on main: simplest, but every refresh adds ~3–5 MB to the history for good; (c) a GitHub Release per refresh with the files as assets: keeps every version for comparison, needs gh release | (a), with the previous version kept next to the new one (previous/) so a refresh can be compared A/B. The MIDI, the renderer and CHANGES.md live on main. (c) if you want the full history of versions |
| D3 | Format | (a) Ogg Vorbis (q 6, ~190 kb/s, plays in browsers and on GitHub’s raw links); (b) MP3 (V0, ~240 kb/s; plays everywhere, including older phones); (c) Opus | (a), or (b) if you listen on devices without Ogg support (older iPhones/Safari) |
| D4 | When to refresh | (a) after each task that changes the sound, as a step of that task; (b) on demand only; (c) automatically in CI on every push to main (needs the encoder in CI, and the bot pushes the branch) | (a): it costs a minute per task and keeps CI simple. (c) later, with T-021 |
Done when
Tests first: the MIDI reader turns a small hand-written file (two notes, a tempo change, pedal down/up) into the expected engine events at the right sample offsets; rendering is deterministic (the same file and model give bit-identical WAV); the renderer does not allocate inside the block loop (assert_no_alloc, as the plugin). The demo set renders in under a minute, the encoded files are on the branch of D2, the README links them, demos/README.md lists sources and licences, the backlog flow has the refresh step, and the first entry of CHANGES.md describes the current sound (T-039’s dampers).
Outcome
- Code:
crates/demos(instruments-demos):midi.rs(midly 0.5 without its rayon feature; all tracks and channels merged, tempo map from any track, note on/off with velocity 0 as off, a key held by two voices goes up when the last lets go, CC 64 on change, CC 120/123 →AllNotesOff; format 2 refused;arrangecuts and lets go of every key and the pedal there),render.rs(render_into: 64-sample blocks split at event offsets, no allocation),wav.rs(24-bit stereo, no dither),compose.rs(the pieces written in the repo),lib.rs(SET,render_score: 4 s tail, the last 1.5 s faded). The binaryrender-demos render|compose;cargo xtask render-demosruns its release build. The model is the plugin’s:instruments_piano::modelis now public.scripts/publish-demos.shbuilds thelisteningcommit (orphan, one commit, force-pushed) fromtarget/demos/.oggenccomes fromvorbis-toolsin the flake. - Gain: a fixed −6 dB for every piece and refresh (
GAIN_DB), lowered for all alike only if a peak would pass −1 dBFS. At 0 dB the full-keyboard chord of the test piece peaked at +4 dBFS; at −6 dB the peaks are −9.2 … −2.0 dBFS. - Demo set (
demos/midi/, 7 files — one more than planned: the test is a separate file rather than folded into a piece): four public-domain Mutopia files (Bach BWV 846 prelude, Chopin Op. 28 No. 4 instead of a nocturne, because Mutopia’s nocturnes are CC BY-SA, Satie Gymnopédie 1, Joplin Maple Leaf Rag; cut at 75–90 s) and three written in the repo (boogie, ballad with jazz voicings, velocity/register test). Only the Chopin file has pedal and only the Satie file has dynamics; the others play at velocity 90 throughout. The environmentinstrumentsnow allowswww.mutopiaproject.org. - Speed: the set (9.3 min of audio) renders in 3.6 s, 26 s with the build check and Ogg encoding; 7.2 MB of Ogg (q 6).
- Tests (
crates/demos/tests/demos.rs,no_alloc.rs): a hand-written format-1 file (tempo track with a change from 120 to 60 bpm, two notes, pedal down/up, velocity-0 note-off) gives the expected events at the exact samples; overlapping voices and repeated pedal values;arrange; block splitting checked with a probe processor; renders bit-identical twice and from a fresh engine; WAV header and sample coding; the committed composed files matchcompose; every piece of the set reads; the block loop underassert_no_alloc. - Changed from the page:
CHANGES.mdcarries date, task and what changed; themaincommit stands in thelisteningbranch’s README and commit message (the line is written before its own commit exists). - Gates: fmt, clippy,
cargo nextest run(59 tests);cargo xtask bundle piano --release+clap-validator: 35 passed, 0 failed, 9 skipped. The GUI is unchanged.