Q-W3: main.cpp → pointers+entry+dispatch via 4 capture hoists; one pure wav_codec RIFF owner; ICaptureBackend deleted; capture_realtime rename + finalize split; shared stampCaptureSample; makeUniqueTag gains monotonic counter (fixes same-second batch collisions). 60/60 green.

This commit is contained in:
2026-07-29 10:56:11 -04:00
parent d7d7f7e084
commit 09f7173db2
29 changed files with 2972 additions and 2426 deletions
+56
View File
@@ -0,0 +1,56 @@
#pragma once
// realtime_lifecycle — the in-flight realtime-capture state machine + globals
// (Q-W3 hoist out of main.cpp). A realtime record spans many timer ticks (it takes
// end-start wall-clock seconds and must NOT block REAPER's UI): the action STARTS
// it (capture_orchestrator::RunCaptureRealtimeTrack -> g_rtBackend.begin), OnTimer
// drives it here (DriveRealtimeCapture -> g_rtBackend.tick) each tick until a
// terminal verdict, then the handle is cleared.
//
// The three globals are EXPOSED (extern) rather than wrapped: the action bodies in
// capture_orchestrator manipulate them exactly as main.cpp did (zero-behavior-change
// move), and — load-bearing (CONTEXT.md §Phase Q hot-path guardrail) — the timer's
// IDLE FAST-PATH stays a SINGLE POINTER TEST at the call site:
// if (capture::g_rtCapture) capture::DriveRealtimeCapture(g_session);
// No per-tick cross-TU call, no accessor indirection, when nothing is recording.
//
// REAPER-facing: the .cpp includes reaper_plugin_functions.h WITHOUT
// REAPERAPI_IMPLEMENT (main.cpp owns the API pointers — CLAUDE.md §contract).
#include "shell/capture/capture.h" // RealtimeRecordBackend / RealtimeCaptureHandle
namespace reasampler {
class ReaSamplerSession;
}
namespace reasampler::capture {
// The realtime backend + the in-flight capture handle. Non-null handle == a
// capture is in progress (used to reject a second one, to drive the per-tick
// advance, and to abort on project switch / unload).
extern RealtimeRecordBackend g_rtBackend;
extern RealtimeCaptureHandle g_rtCapture;
// The ReaProject* the in-flight capture belongs to (opaque, compare-only) — lets
// OnTimer detect a project switch mid-capture and abort+restore rather than leak the
// temp track/arm/transport into or across projects. Only meaningful when
// g_rtCapture != nullptr.
extern ReaProject* g_rtCaptureProject;
// Commit a finished realtime capture (a Done tick/abort with an Ok result): add the
// Sample to the ACTIVE bank, record the owned file, bump the generation, persist +
// MarkProjectDirty. On a non-Ok result, logs the failure only.
void CommitRealtimeResult(ReaSamplerSession& session, const CaptureResult& res);
// Advance any in-flight realtime capture one tick. Cheap when none is running (a
// null check — though the caller already guards, see the header note) and fast even
// mid-record. Detects a project switch mid-capture and aborts+restores so the
// capture never leaks across projects. Called from OnTimer BEFORE session.poll().
void DriveRealtimeCapture(ReaSamplerSession& session);
// Unload teardown: abort any in-flight capture while the API pointers are still
// live — finalize-or-abort + restore so we never leave a temp track, an armed
// track, or an altered transport/cursor in the user's project on unload. Commits
// whatever was captured (best effort) before tearing down. No-op when idle.
void AbortRealtimeCaptureForUnload(ReaSamplerSession& session);
} // namespace reasampler::capture