#pragma once // render_settings — the REAPER-free logic behind the capture action family. // // PURE MODULE (CLAUDE.md §load-bearing split): NO REAPER types, NO SWELL, NO // vendor/ includes. Standard library only. The capture shell (capture.cpp) and // action layer (main.cpp) read the actual DAW state (time selection, selected // tracks/items, razor strings, the ancestor-track chain) and hand the raw values // here so the genuinely-pure, easy-to-get-wrong pieces are unit-tested outside // the DAW: // // 1. sourceMode -> the RENDER_SETTINGS integer bit value (wet only). // 2. a P_RAZOREDITS string -> the list of (start,end) ranges + their union bound. // 3. range inference: razor-present -> razor union, else time selection. Range // is a SOURCE choice orthogonal to the capture scope. // 4. the FX-scope bypass plan: given a scope + an ancestor-chain length, which // tracks' FX to bypass so each scope hears only the FX it should (the M7 // "items captured through parent FX" defect is corrected here). // 5. the capture-action table (id string, description, scope) — the taxonomy, // in one place so main.cpp iterates it instead of hand-listing. // // The RENDER_SETTINGS bit MEANINGS are transcribed verbatim from // reaper_plugin_functions.h line ~3041 (see kRender* constants); the CHOICE of // which bits each source mode sets is this module's logic and is tested. #include #include #include "bank_model.h" // SourceMode (pure enum) namespace reasampler { // --- RENDER_SETTINGS source/processing bits (verbatim from SDK header ~3041) -- // // Only the bits this module actually uses are named. Values are the documented bit // weights; the DOC of each is the SDK header's, not a guess. inline constexpr int kRenderMasterMix = 0; // (&(1|2))==0, no source bits inline constexpr int kRenderSelItems = 32; // &32 selected media items inline constexpr int kRenderSelItemsViaMaster = 64; // &64 selected media items via master inline constexpr int kRenderSelTracksViaMaster = 128; // &128 selected tracks via master inline constexpr int kRenderRazorEdits = 4096; // &4096 render razor edits // NOTE: kRenderPreFaderStems (&8192) is NOT used. REAPER offline render has no // true pre-FX "dry" bit. FX scoping is done by the FX-bypass-around-render // mechanism (see fxBypassPlan below) — bypassing the FX-enable of the tracks that // fall outside a scope — NOT by any render bit. All capture actions render wet // (post the FX that remain enabled); the scope decides which FX remain enabled. inline constexpr int kRenderSingleFile = (4 << 16); // items/razor -> one file // The RENDER_SETTINGS value for a given source mode. `supported` is false only // for SourceMode::Realtime (that is the M8 backend, not offline render). struct RenderSettingsChoice { int settings = kRenderMasterMix; bool supported = true; // false => not an offline-render source (e.g. Realtime) }; // Maps a source mode to its RENDER_SETTINGS value (which content the render // covers). FX scoping is orthogonal — done by fxBypassPlan, not by these bits. // `wetDry` is accepted but ignored for the mapping — retained in CaptureRequest // as the seam for future dry work (M10 null test). // // CONFIRMED (SDK header ~3041): // MasterMix / TimeSelection -> master mix (0). // SelectedTracks -> &128 selected tracks via master. // SelectedItems -> &32 | single-file (one wav, not one-per-item). // RazorArea -> &4096| single-file. RenderSettingsChoice renderSettingsFor(SourceMode mode, double wetDry); // --- Capture scope: the FX-scope invariant (Daniel, critical) ---------------- // // Three FX scopes. The render RANGE (razor-else-time) is orthogonal to the scope. // Item -> item/take FX ONLY (no track, no parent/folder, no master FX). // Track -> item FX + the selected track's OWN track FX (no parent/folder/master). // Master -> the whole chain (nothing bypassed). enum class CaptureScope { Item, Track, Master, }; // The render source mode each scope drives. Item captures selected items, Track // captures selected tracks (via master), Master captures the master mix. SourceMode sourceModeForScope(CaptureScope scope); // --- Range inference: razor-else-time (orthogonal to scope) ------------------- // // Every scope action infers its render range the same way: if a razor area is // present, use the razor union; otherwise use the time selection. Razor is a // range SOURCE, not a capture mode (the M7 four-mode model conflated them). enum class RangeSource { Razor, // a razor area is present -> use its union bound TimeSelection, // no razor -> use the time selection }; // Picks the range source. Pure so the "razor wins when present" rule is tested // without a DAW; the shell supplies whether any razor area was found. RangeSource inferRangeSource(bool hasRazorArea); // --- FX-bypass plan: which tracks' FX to bypass for a scope ------------------- // // Given a CaptureScope, returns three boolean flags: whether to bypass (a) the // captured track's OWN FX, (b) each of its ancestor (parent/folder) tracks' FX, // and (c) the master FX. The caller (FxBypassGuard) resolves these flags to // concrete MediaTrack* by walking the ancestor chain via GetParentTrack and // clears I_FXEN on each flagged track, snapshotting first (RAII restore). // // SCOPE BOUNDARY: I_FXEN bypasses a track's FX plugins but NOT its volume/pan. // The guard (FxBypassGuard, main.cpp) therefore ALSO neutralizes the fader GAIN // (D_VOL -> unity) of every track in this same bypass set, so a Track/Item // capture rendered via master does NOT bake in the parent/folder/master fader // level (Daniel: the capture is likely re-routed through that chain later). PAN // is deliberately left untouched (D_PAN is coupled to D_WIDTH/D_PANLAW — a clean // neutralize is non-trivial; flagged as a follow-up, not half-done). This plan // selects the SET; the guard applies both the FX bypass and the gain neutralize. struct FxBypassPlan { bool bypassSelfFx = false; // the captured track's own FX bool bypassAncestorFx = false; // every ancestor (parent/folder) track's FX bool bypassMaster = false; // the master track's FX }; FxBypassPlan fxBypassPlanFor(CaptureScope scope); // A single razor-edit area: a time range on one track (envelope GUID ignored — // razor captures target track-audio areas, not envelope lanes). struct RazorRange { double startSeconds = 0.0; double endSeconds = 0.0; }; // Parses ONE track's P_RAZOREDITS string (SDK header ~2899): space-separated // TRIPLES of . The envelope GUID is "" (an empty // quoted string, i.e. the literal two chars `""`) for a track-audio area and a // GUID like {…} for an envelope-lane area. // // Returns only the track-audio ranges (envelope-lane triples are skipped — razor // captures target track audio, not envelope lanes). Malformed/short trailing tokens are ignored, not fatal. // A range with end <= start is dropped (no negative/empty areas leak through). std::vector parseRazorEdits(const std::string& razorString); // The union bound (min start, max end) of a set of razor ranges — the exact // window the offline render must cover so every area is inside the rendered file. // Returns {0,0} for an empty input (caller treats that as "no razor area"). RazorRange razorUnionBounds(const std::vector& ranges); // --- Capture-action taxonomy (the bindable set main.cpp registers) ----------- // // One row per bindable SCOPE action. Three scopes (item / track / master); the // range each captures (razor-else-time) is inferred at fire time, not a mode. // Tail is OFF for every row (exact bounds); a tail-on variant is a later opt-in, // YAGNI now. Bounded, discoverable, NO dialogs (the tool's no-clutter ethos). // // commandString is FOREVER-STABLE (user keybindings key off it) — never change a // shipped value. baseName feeds the file stem (sanitized by capture_paths). struct CaptureActionDef { const char* commandString; // CEREBELLUM_REASAMPLER_… FOREVER-STABLE id string const char* description; // Actions-list label const char* baseName; // file-stem base for this capture CaptureScope scope; // FX scope (item / track / master) }; // The capture-action table. Iterated by main.cpp to register the family and route // each fired command back to its definition. Kept here (pure) so the taxonomy is // one testable list, not scattered registration code. // // Three scope rows: CAPTURE_ITEM, CAPTURE_TRACK, CAPTURE_MASTER. This replaces the // M7 four-mode table (master / tracks / items / razor) — razor is now an inferred // range, not a mode, and each scope enforces its FX-scope invariant via // fxBypassPlanFor. const std::vector& captureActionTable(); } // namespace reasampler