# COMPLETED.md — ReaSampler landed milestones Completed milestone entries removed from `PLAN.md`. Each entry preserves its original Goal, Verify, and checklist points with boxes marked done. --- ## Milestone 0 — Transition scaffold: reaper_mpeview → ReaSampler **Goal:** Retire the MPE scaffold and stand up the sampler's pure core in its place, preserving the pure-core / REAPER-shell split. **Verify:** `cmake -B build -S .` configures clean; `cmake --build build` builds the renamed extension target and the pure-core test target; `ctest --test-dir build` is green with the new `bank_model` + `peaks` suites present. - [x] Delete `src/mpe_model.{h,cpp}` and `src/mpe_view.{h,cpp}`; remove `tests/test_mpe_model.cpp`. - [x] Rename the CMake `project()` and the extension MODULE target from `reaper_mpeview` to `reaper_reasampler` (binary `OUTPUT_NAME` likewise); update `PREFIX ""` / platform SUFFIX blocks to the new target name. - [x] Replace the pure `mpe_model` static lib + `mpe_model_tests` executable with `bank_model` (pure static lib) + `bank_model_tests`; keep the CTest wiring. - [x] Repoint `src/main.cpp`: drop the `mpe_view.h` include and all `MpeView_*` calls (toggle / IsOpen / OnTimer / Cleanup); stub the extension entry so it loads, logs to console, and registers nothing MPE-specific. The `command_id` / `gaccel` / `hookcommand` registration *pattern* is preserved for reuse (CLAUDE.md §REAPER extension contract) — the MPE action string is removed. - [x] Choose and record the persistent action-id prefix for the sampler family (replaces `CEREBELLUM_MPEVIEW_TOGGLE`); this string is forever-stable once shipped (CLAUDE.md §action registration). - [x] Refresh `README.md` layout/next-step sections to the sampler module set. (Landed-work reflection is doc-keeper's; this point exists so the stale MPE README does not mislead the first implementer.) --- ## Milestone 1 — bank_model + JSON round-trip (pure) **Goal:** The `Sample` metadata struct and `BankIndex` (add / remove / query / tier moves / dedup-by-hash) with JSON serialize/deserialize to `std::string`. CONTEXT.md §Data model, §Module architecture. **Verify:** CTest green. Round-trip is lossless (deserialize(serialize(x)) == x) across all fields; dedup-by-hash and tier filtering asserted; **relative paths only** invariant enforced at the model boundary (no absolute path accepted/stored). - [x] Define `Sample` with the full field set (id, display name, relative path, source mode, source range in project time + PPQ, track GUID(s), wet/dry, channels, SR, length sec + beats, capture tempo, optional key, peak/RMS/LUFS, clip flag, tier, content hash, provenance, created ts). CONTEXT.md §Data model. - [x] `BankIndex`: ordered collection keyed by id; add / remove / query. - [x] Hash lookup for dedup-by-content-hash. - [x] Tier model (scratch | archive) + tier-move + tier filtering; scratch marked auto-prunable. - [x] JSON serialize/deserialize to/from `std::string`. - [x] Tests: full-field round-trip lossless; dedup collapses equal-hash adds; tier filter/move correct; relative-path invariant rejects absolute paths; empty-index and malformed-JSON edge cases. --- ## Milestone 2 — peaks (pure) **Goal:** Compute waveform min/max bins from raw PCM, dependency-free (not REAPER's peak API). CONTEXT.md §Module architecture, §Non-goals. **Verify:** CTest green. Fed a known signal (full-scale sine, ramp), asserted min/max envelope per bin matches expected within tolerance; channel count preserved; bin count honored for arbitrary sample lengths (incl. remainder bin). - [x] Min/max bin computation from interleaved PCM given a target bin count. - [x] Multi-channel handling (per-channel envelope; no silent fold). - [x] Tests: sine envelope ≈ ±amplitude; ramp envelope monotonic; DC/silence → zero envelope; short-buffer and non-divisible-length edge cases. --- ## Milestone 3 — Offline capture spike (REAPER shell) **Goal:** Offline-render the time-selection master mix to a wav in the project bank folder, add a `Sample`, log it. The render-driving spike. CONTEXT.md §REAPER API surface (offline render), Build order 3. **Verify (in DAW):** Render runs via `Main_OnCommand(42230)` ("Render using most recent settings") — REAPER always shows its offline-render progress window; no stock/header-documented fully-headless path exists. File lands in the project-relative bank folder at **32-bit float WAV** at project rate (lossless, dither-free → enables bit-identical/null-test). A `Sample` is added to the in-memory `BankIndex`. Non-destructive. Unsaved-project state triggers a Save-As prompt; capture is refused if the user cancels (no default-location fallback). **Bit-identical repeats:** two identical requests produce byte-identical files. **Exact bounds:** rendered length matches the requested range (no rounding, no added silence without an explicit tail). - [x] `ICaptureBackend` interface + `CaptureRequest` (source mode, time range, wet/dry, tail, SR/bit-depth/channels, output path). CONTEXT.md §capture. - [x] `OfflineRenderBackend`: drive `GetSetProjectInfo` render settings + `GetSetProjectInfo_String` file/pattern/format; **verify every flag against `vendor/reaper-sdk/sdk/reaper_plugin_functions.h`.** - [x] Resolve the no-dialog render command/flag on the current REAPER build (open question) and confirm it runs headless. - [x] Populate a `Sample` from the finished file; hand to `bank_model`; console-log. - [x] Verify bit-identical repeats and exact-bounds by hand on a known range. --- ## Milestone 4 — persist (index ↔ project ext state) **Goal:** Write the `BankIndex` JSON to project ext state, reload on project open; project-relative path resolution. CONTEXT.md §persist, §Persistence & paths. **Verify (in DAW):** Index survives Save / Save As / close+reopen; **bank travels with the .rpp**; **relative paths only** in the persisted index (Save As to a new folder still resolves the bank). - [x] `SetProjExtState` / `GetProjExtState` under namespace `"reasampler"`. - [x] Bank-folder resolution from the current project path (`EnumProjects` / `GetProjectPathEx`); store under a project-relative subfolder. - [x] Reload-on-open; confirm survival across Save / Save As. **Notes/decisions:** - Storage: `SetProjExtState` / `GetProjExtState`, namespace `"reasampler"`, keys `bank_index` (serialized JSON) and `project_guid`; relative paths only in the persisted index. - Project identity: keyed off a **minted GUID** stored in ext state (REAPER exposes no native per-project GUID), not the raw `ReaProject*` — a recycled pointer cannot misread a project switch as a Save-As. - Save-As: **copy** semantics (Daniel's decision) — the `reasampler_bank/` folder is copied under the new `.rpp`; the old project's bank stays intact. Every ext-state write calls `MarkProjectDirty` so captures/GUID changes flush on the normal save. - Known limitation (narrow, accepted): if a user does Save-As, closes the copy *without saving*, then reopens that copy to a *different* folder while the original is also open, identities can collide. Force-saving after Save-As would close the hole but was rejected as violating non-destructive.