T-003 — Cargo workspace with the DSP crate and a first CLAP plugin on clack with an egui GUI

Status: done (manual DAW check done in Reaper, 2026-12-03) · Area: rust · Depends on: —

Read for that: Overview (layout), ADR-0001, ADR-0002, ADR-0006, Plugin formats (real-time rules), Testing and evaluation (gates). The crates’ own docs and examples at the versions you pin (AGENTS.md: no framework API from memory): clack-plugin, clack-extensions (both 0.2 on crates.io in Nov 2026; clack’s repository has plugin examples, including a GUI one), baseview, egui-baseview.

What: The skeleton every later task builds on. It proves the whole chain — workspace, DSP crate, CLAP plugin, GUI in the host window, bundling, validation — with a deliberately trivial sound.

  1. Workspace at the repository root: Cargo.toml with resolver = "3", edition = "2024", rust-version equal to rust-toolchain.toml, members crates/*; shared [workspace.dependencies]; release profile with lto = "thin", codegen-units = 1.
  2. crates/dsp (library, no plugin dependencies): a Processor trait in the shape of ADR-0002 (prepare(sample_rate, max_block), process(&mut self, events, outputs), reset()), and one implementation, a placeholder sine voice per held note with gain — clearly marked as a placeholder until the piano engine (T-008). Events carry a sample offset within the block. No allocation after prepare.
  3. crates/piano (cdylib, the plugin that will become the piano): CLAP id io.github.danielboigk.instruments.piano, name “Instruments Piano”, features instrument, stereo. Extensions: note-ports (one input, CLAP and MIDI dialects), audio-ports (one stereo output), params (one parameter, Gain in dB, smoothed), state (save/load parameters, with a version number), gui (egui through egui-baseview, embedded in the host’s parent window; one slider bound to Gain). GUI ↔ audio only through atomics; host automation updates the slider.
  4. crates/xtask: cargo xtask bundle piano [--release] → target/bundled/Instruments Piano.clap (Linux: the .so renamed; macOS: the bundle directory with Info.plist; Windows: the .dll renamed).
  5. Flake: add clap-validator (not in nixpkgs as of Nov 2026: build it from source from free-audio/clap-validator at a release tag, the same way as Graphicle in flake.nix) to the dev shells.
  6. Tests: dsp unit tests (block-size independence with sizes 1, 64, 513; silence when no notes; assert_no_alloc around process in debug tests).

Done when:

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo nextest run pass in the dev shell.
  • cargo xtask bundle piano --release produces the bundle, and clap-validator validate on it passes.
  • The overview page and this page match what was built (crate names, commands); docs/toolchain mentions clap-validator.
  • Manual check by the maintainer (a cloud session has no DAW): load the bundle in a CLAP host on Linux (Bitwig or Reaper), play notes, move the slider, automate Gain, reopen the GUI. Note the result on this page.

Out of scope: CI (T-021), the model file (T-015), the piano engine (T-008).

Result (Nov 2026)

  • Workspace: crates/dsp (instruments-dsp), crates/piano (instruments-piano, cdylib), crates/xtask; .cargo/config.toml aliases cargo xtask. Pinned majors: clack-plugin/-extensions 0.2, egui-baseview 0.9 (baseview 0.4, egui 0.37), clack-host 0.2 (tests).
  • DSP API as implemented (ADR-0002 updated): Processor { prepare, reset, event, render, is_active }; the plugin renders up to each event’s sample offset (clack’s event batcher). The placeholder SineVoices keeps one state per key, as Piano 13 plans.
  • Plugin: note port (CLAP + MIDI dialects; MIDI note on/off and all-notes-off), stereo output, Gain (dB, −60…+6, smoothed 20 ms, automatable, gestures from the GUI reported to the host), versioned state (exactly [1][f32 dB], five bytes; host told to rescan values after load), embedded egui editor (fixed size 420×160 logical, scaled by gui.set_scale). Processing sleeps when silent unless the editor is open (so GUI edits reach the host).
  • Gates: fmt, clippy (-D warnings), 9 tests (4 DSP incl. block-size independence and no allocation; 2 parameter/state units; 3 in-process host tests).
  • clap-validator 0.4.1 on the release bundle: 44 tests, 35 passed, 0 failed, 9 skipped (all for optional extensions we don’t implement: preset discovery, 64-bit audio, configurable/activatable ports).
  • GUI smoke test on Xvfb + Mesa llvmpipe (scripts/gui-smoke-test.sh in .#gui-test): editor embeds as a child of the parent X11 window, renders (title, note, slider), and is removed by destroy.
  • Findings: egui 0.37 has no fonts unless the default_fonts feature is on (text rendered as boxes) — enabled in the workspace. Outside NixOS, Nix’s Mesa needs LIBGL_DRIVERS_PATH and __EGL_VENDOR_LIBRARY_FILENAMES set (baseview tries EGL first) — done in the gui-test shell. Editor errors are printed to stderr for the host’s log.
  • Not done here: the manual check in a DAW (no DAW in a cloud session).
  • Since T-009 the plugin plays PianoEngine instead of the placeholder SineVoices (T-009); the plugin structure above is unchanged.

Fixes after review (Dec 2026)

Found in a review of the plugin code (issues #2–#5 on GitHub), fixed with tests:

  • Zero-velocity note-on (crates/dsp, PR #6): SineVoices treats a NoteOn with velocity ≤ 0 as a note-off. Before, such a key stayed active forever and the plugin never slept. The MIDI path already mapped 0x90 with data2 == 0 to note-off; CLAP note-ons with velocity 0 now behave the same.
  • Strict state decode (PR #7): params::state::decode accepts exactly five bytes; trailing bytes are rejected. A longer format must bump the version, never extend version 1.
  • Gesture retry (PR #8): sync_gesture only records a gesture begin/end as reported once try_push succeeded, so a full output buffer delays the event to the next block instead of dropping it.
  • Host-change flag (PR #9): host-side gain changes made on the main thread (inactive flush, state load) set a flag the audio thread takes, instead of the audio thread comparing f32 values; the audio thread’s own write-back after automation (publish_gain_db) sets none.

Manual check (maintainer)

Load target/bundled/Instruments Piano.clap in Bitwig or Reaper on Linux; play notes; move the slider; automate Gain; close and reopen the editor; save and reload the project. Result (maintainer, Reaper on Linux, 2026-12-03, build of main after T-018): notes play; the editor opens, closes and reopens (T-020’s editor: grouped controls, keyboard with held/sounding/undamped marks, sustain-pedal state, meters); the controls change the sound; Gain automates; settings survive closing and reopening the project. Found: the Root menu showed A▯ because the editor’s font has no ♯/♭ (labels changed to C#, Eb …, test parameter_text_uses_characters_the_editor_font_has); Reaper’s preset menu lists no factory presets (only Reset to factory default), though clap-validator’s preset-discovery tests pass, so the preset check stays open for a host that browses CLAP presets (Bitwig). The first attempt loaded a stale pre-T-020 bundle: after rebuilding, clear Reaper’s CLAP cache and rescan.