Cut shell/capture comment bloat ~33% (comments only, zero code change)

This commit is contained in:
2026-07-29 20:48:59 -04:00
parent 1f24c4b095
commit 54f5f24506
22 changed files with 699 additions and 1215 deletions
+25 -32
View File
@@ -1,10 +1,9 @@
// realtime_lifecycle.cpp — the in-flight realtime-capture state machine + globals
// (Q-W3 hoist out of main.cpp; the code moved verbatim, the session threaded as a
// parameter). See the header.
// realtime_lifecycle.cpp — the in-flight realtime-capture state machine + globals.
// See the header.
//
// Compiled into the reaper_reasampler MODULE. Includes reaper_plugin_functions.h
// Compiled into the reaper_reasampler module. Includes reaper_plugin_functions.h
// WITHOUT REAPERAPI_IMPLEMENT — main.cpp is the one TU that defines the API
// pointers; here they are extern (CLAUDE.md §contract).
// pointers; here they are extern.
#include "shell/capture/realtime_lifecycle.h"
@@ -17,15 +16,13 @@
namespace reasampler::capture {
// --- M8 in-flight realtime capture (async, timer-driven) --------------------
RealtimeRecordBackend g_rtBackend;
RealtimeCaptureHandle g_rtCapture;
ReaProject* g_rtCaptureProject = nullptr;
// Commit a finished realtime capture (a Done tick/abort with an Ok result): add the
// Sample to the ACTIVE bank (session.bank() resolves to book.activeIndex() — B2),
// persist + MarkProjectDirty. Shared by the tick-completion path and the abort
// paths. On a non-Ok result, logs the failure only.
// Commits a finished realtime capture (a Done tick/abort with an Ok result): adds
// the Sample to the active bank, persists + MarkProjectDirty. Shared by the
// tick-completion and abort paths. On a non-Ok result, logs the failure only.
void CommitRealtimeResult(ReaSamplerSession& session, const CaptureResult& res)
{
if (res.status != CaptureStatus::Ok)
@@ -34,40 +31,36 @@ void CommitRealtimeResult(ReaSamplerSession& session, const CaptureResult& res)
return;
}
session.bank().add(res.sample);
// B-cap: record the file the capture created in the owned-file manifest, at the same
// point the Sample is added and before the same persist. Recorded regardless of the
// index AddResult — even a hash-collapse still WROTE a file the tool owns, and the
// manifest dedups a repeat path itself (Phase R prune reconciles manifest vs index).
// Record the file in the owned manifest regardless of the index AddResult — even
// a hash-collapse still wrote a file the tool owns; the manifest dedups a repeat
// path itself (prune reconciles manifest vs index).
session.owned().add(res.sample.relativePath);
// S9: a capture add changes what a live instance could play (a new sample landed in the
// active bank) -> bump before the persist so the stamped generation refreshes instances.
// A capture add changes what a live instance could play, so bump the generation
// before persisting to refresh instances.
session.bumpBankGeneration();
session.saveToActiveProject(); // persist book + manifest + generation + MarkProjectDirty (travels with .rpp)
session.saveToActiveProject(); // persist book + manifest + generation + MarkProjectDirty
}
// Advance any in-flight realtime capture one tick. Cheap when none is running (a
// null check) and fast even mid-record (tick() only reads the transport until the
// terminal tick). Detects a project switch mid-capture and aborts+restores so the
// capture never leaks across projects. Called from OnTimer BEFORE session.poll() so
// poll's project-switch handling sees a cleaned-up project.
// Advances any in-flight realtime capture one tick. Detects a project switch
// mid-capture and aborts+restores so the capture never leaks across projects.
// Called from OnTimer before session.poll() so poll's own project-switch handling
// sees an already-cleaned-up project.
void DriveRealtimeCapture(ReaSamplerSession& session)
{
if (!g_rtCapture) return;
// Project switch guard: if the active project is no longer the one the capture
// belongs to, a new/other project became active mid-record abort + restore
// (into the ORIGINAL project the state is bound to) and drop it. Do NOT finalize
// into the new project.
// If the active project is no longer the one the capture belongs to, a project
// switch happened mid-record: abort + restore into the original project the
// state is bound to, and drop it — never finalize into the new project.
ReaProject* active = EnumProjects(-1, nullptr, 0);
if (active != g_rtCaptureProject)
{
RealtimeTickResult r = g_rtBackend.abort(*g_rtCapture);
// Only commit if the ORIGINAL project is still open and active would be it —
// on a switch we restored into the original but must not persist into the
// now-active foreign project. Log the outcome without persisting. On a Failed
// abort surface abort()'s own message — it distinguishes a clean tab-switch
// abort from the closed-project DROP (the captured project was closed mid-record,
// review §1: nothing restored because the pointers were already freed).
// Log without persisting — we restored into the original project but must
// not persist into the now-active foreign one. A Failed abort surfaces
// abort()'s own message, distinguishing a clean tab-switch abort from the
// closed-project case (nothing restored because the pointers were already
// freed).
if (r.status == RealtimeTickStatus::Done)
ShowConsoleMsg("ReaSampler realtime capture: project switched mid-record -- "
"captured audio restored into the original project; not "