2d225258b4
Add TailMode{None,Auto,Manual} + derived -72dB TRIMEND + 8s cap in render_settings;
wire into OfflineRenderBackend with snapshot/restore of the tail settings; add
CAPTURE_ITEM_TAIL/CAPTURE_TRACK_TAIL variant actions (plain actions stay exact-bounds).
299 lines
14 KiB
C++
299 lines
14 KiB
C++
// Standalone tests for reasampler::render_settings — no REAPER, no framework.
|
|
// Covers the pure pieces behind the capture family: the source-mode ->
|
|
// RENDER_SETTINGS bit mapping, the TailMode -> RENDER_* (tail/normalize/trim-end)
|
|
// mapping + the -72 dB derived ratio + the 8 s manual clamp, P_RAZOREDITS parsing
|
|
// -> ranges + union, scope -> source mode, range inference (razor-else-time), the
|
|
// FX-bypass plan (corrects the "items captured through parent FX" defect), and the
|
|
// capture-action taxonomy table (stable ids, scope x tail-variant matrix).
|
|
|
|
#include "../src/render_settings.h"
|
|
|
|
#include <cmath>
|
|
#include <cstdio>
|
|
#include <set>
|
|
#include <string>
|
|
|
|
using namespace reasampler;
|
|
|
|
static int g_fail = 0;
|
|
#define CHECK(cond) do { if(!(cond)) { \
|
|
std::printf("FAIL line %d: %s\n", __LINE__, #cond); ++g_fail; } } while(0)
|
|
|
|
// --- renderSettingsFor: wet-only bit mapping ---------------------------------
|
|
|
|
static void testMasterMixWet() {
|
|
// Master mix -> value 0 (no source bits), supported.
|
|
RenderSettingsChoice c = renderSettingsFor(SourceMode::MasterMix, 1.0);
|
|
CHECK(c.settings == kRenderMasterMix);
|
|
CHECK(c.supported);
|
|
// TimeSelection aliases master mix — same result.
|
|
CHECK(renderSettingsFor(SourceMode::TimeSelection, 1.0).settings == kRenderMasterMix);
|
|
// wetDry argument is irrelevant (all three-scope capture actions are wet); passing 0.0
|
|
// must still yield the same wet master-mix bits.
|
|
CHECK(renderSettingsFor(SourceMode::MasterMix, 0.0).settings == kRenderMasterMix);
|
|
}
|
|
|
|
static void testSelectedTracksWet() {
|
|
// Selected tracks -> via master (&128), header-confirmed.
|
|
RenderSettingsChoice c = renderSettingsFor(SourceMode::SelectedTracks, 1.0);
|
|
CHECK(c.settings == kRenderSelTracksViaMaster);
|
|
CHECK(c.supported);
|
|
}
|
|
|
|
static void testSelectedItemsSingleFile() {
|
|
// Items render to ONE file (single-file bit set) so N items -> 1 bank entry.
|
|
RenderSettingsChoice c = renderSettingsFor(SourceMode::SelectedItems, 1.0);
|
|
CHECK((c.settings & kRenderSelItems) != 0);
|
|
CHECK((c.settings & kRenderSingleFile) != 0);
|
|
CHECK(c.supported);
|
|
}
|
|
|
|
static void testRazorSingleFile() {
|
|
// Razor edits render to ONE file (same single-file rationale as items).
|
|
RenderSettingsChoice c = renderSettingsFor(SourceMode::RazorArea, 1.0);
|
|
CHECK((c.settings & kRenderRazorEdits) != 0);
|
|
CHECK((c.settings & kRenderSingleFile) != 0);
|
|
CHECK(c.supported);
|
|
}
|
|
|
|
static void testRealtimeIsUnsupportedOffline() {
|
|
// The realtime mode is not an offline-render source — must report unsupported
|
|
// so the offline backend refuses it rather than rendering the master mix.
|
|
CHECK(!renderSettingsFor(SourceMode::Realtime, 1.0).supported);
|
|
}
|
|
|
|
// --- tail: TailMode -> RENDER_* mapping (docs/product/capture-tail.md) --------
|
|
|
|
static void testTailNoneIsExactBounds() {
|
|
// None -> exact bounds, byte-identical to the pre-tail capture: tail flag clear,
|
|
// 0 ms, disable-all normalize (the current default), no trim. Asserting the exact
|
|
// bit values (not just "some value") pins the byte-identical contract: if the
|
|
// mapping regressed to set a tail bit or a non-disable-all normalize, this fails.
|
|
TailRenderSettings t = tailRenderSettingsFor(TailMode::None, 0.0);
|
|
CHECK(t.tailFlag == kTailFlagNone); // 0
|
|
CHECK(t.tailMs == 0.0);
|
|
CHECK(t.normalize == kNormalizeDisableAll); // 262144
|
|
CHECK(t.trimEnd == 0.0);
|
|
// manualTailMs must be ignored for None (a stray tail from a leftover ms is the bug).
|
|
TailRenderSettings t2 = tailRenderSettingsFor(TailMode::None, 5000.0);
|
|
CHECK(t2.tailFlag == kTailFlagNone);
|
|
CHECK(t2.tailMs == 0.0);
|
|
}
|
|
|
|
static void testTailAutoIsSurgicalTrim() {
|
|
// Auto -> custom-bounds tail bit, 8 s cap, SURGICAL normalize (ONLY &32768), and
|
|
// the -72 dB TRIMEND ratio. The disable-all bit must NOT be set (it is semantically
|
|
// opposed to trim — this assertion catches a regression to the None normalize).
|
|
TailRenderSettings t = tailRenderSettingsFor(TailMode::Auto, 0.0);
|
|
CHECK(t.tailFlag == kTailFlagCustomBounds); // &1
|
|
CHECK(t.tailMs == kMaxTailMs); // 8000
|
|
CHECK(t.normalize == kNormalizeTrimEnd); // exactly 32768, nothing else
|
|
CHECK((t.normalize & kNormalizeDisableAll) == 0); // disable-all is NOT set
|
|
// TRIMEND is the derived -72 dB ratio ~= 0.00025119 (the DAW-confirm value).
|
|
CHECK(std::fabs(t.trimEnd - 0.00025119) < 1e-8);
|
|
// manualTailMs is ignored for Auto (Auto always uses the 8 s cap).
|
|
CHECK(tailRenderSettingsFor(TailMode::Auto, 3000.0).tailMs == kMaxTailMs);
|
|
}
|
|
|
|
static void testAutoTrimRatioDerivesFromDb() {
|
|
// The ratio must DERIVE from the -72 dB constant (10^(dB/20)), not be a hardcoded
|
|
// float — recompute it independently and require an exact match with the mapping.
|
|
double expected = std::pow(10.0, kAutoTrimThresholdDb / 20.0);
|
|
CHECK(autoTrimEndRatio() == expected);
|
|
CHECK(tailRenderSettingsFor(TailMode::Auto, 0.0).trimEnd == expected);
|
|
// Sanity: -72 dB is well below unity but above zero.
|
|
CHECK(expected > 0.0 && expected < 0.001);
|
|
}
|
|
|
|
static void testTailManualFixedNoTrim() {
|
|
// Manual -> custom-bounds tail, the requested ms (within cap), disable-all
|
|
// normalize (no trim). A Manual capture is a fixed tail, so it keeps today's
|
|
// disable-all exactly like the no-tail path.
|
|
TailRenderSettings t = tailRenderSettingsFor(TailMode::Manual, 2500.0);
|
|
CHECK(t.tailFlag == kTailFlagCustomBounds);
|
|
CHECK(t.tailMs == 2500.0);
|
|
CHECK(t.normalize == kNormalizeDisableAll);
|
|
CHECK(t.trimEnd == 0.0);
|
|
}
|
|
|
|
static void testTailManualClampsToCap() {
|
|
// The 8 s cap is a runaway guard that applies to Manual too: ms > 8000 -> 8000.
|
|
CHECK(tailRenderSettingsFor(TailMode::Manual, 9000.0).tailMs == kMaxTailMs);
|
|
CHECK(tailRenderSettingsFor(TailMode::Manual, 8000.0).tailMs == kMaxTailMs);
|
|
// Below the cap is passed through unchanged.
|
|
CHECK(tailRenderSettingsFor(TailMode::Manual, 100.0).tailMs == 100.0);
|
|
// A negative request floors to 0 (no negative tail leaks into RENDER_TAILMS).
|
|
CHECK(tailRenderSettingsFor(TailMode::Manual, -50.0).tailMs == 0.0);
|
|
}
|
|
|
|
// --- parseRazorEdits: P_RAZOREDITS string -> ranges --------------------------
|
|
|
|
static void testParseSingleTrackAudioArea() {
|
|
// One track-audio triple: start end "" (empty quoted GUID = track audio).
|
|
auto r = parseRazorEdits("1.5 3.25 \"\"");
|
|
CHECK(r.size() == 1);
|
|
CHECK(r[0].startSeconds == 1.5);
|
|
CHECK(r[0].endSeconds == 3.25);
|
|
}
|
|
|
|
static void testParseMultipleAreas() {
|
|
auto r = parseRazorEdits("0.0 1.0 \"\" 2.0 4.0 \"\"");
|
|
CHECK(r.size() == 2);
|
|
CHECK(r[0].startSeconds == 0.0 && r[0].endSeconds == 1.0);
|
|
CHECK(r[1].startSeconds == 2.0 && r[1].endSeconds == 4.0);
|
|
}
|
|
|
|
static void testParseSkipsEnvelopeLaneAreas() {
|
|
// A triple whose GUID is a real {…} is an ENVELOPE-lane area — skipped, since
|
|
// razor captures render track audio only. Only the track-audio triple survives.
|
|
auto r = parseRazorEdits(
|
|
"1.0 2.0 \"\" 3.0 4.0 {AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE}");
|
|
CHECK(r.size() == 1);
|
|
CHECK(r[0].startSeconds == 1.0 && r[0].endSeconds == 2.0);
|
|
}
|
|
|
|
static void testParseEmptyAndMalformed() {
|
|
CHECK(parseRazorEdits("").empty());
|
|
// Empty/inverted range dropped (end <= start).
|
|
CHECK(parseRazorEdits("5.0 5.0 \"\"").empty());
|
|
CHECK(parseRazorEdits("5.0 1.0 \"\"").empty());
|
|
// Trailing garbage token in a time field -> that triple dropped, not a crash.
|
|
CHECK(parseRazorEdits("1.0x 2.0 \"\"").empty());
|
|
// A dangling partial triple (missing GUID token) is ignored.
|
|
CHECK(parseRazorEdits("1.0 2.0").empty());
|
|
}
|
|
|
|
static void testRazorUnionBounds() {
|
|
// Union = min start .. max end across all areas (the exact render window).
|
|
std::vector<RazorRange> ranges = {{2.0, 3.0}, {0.5, 1.0}, {4.0, 6.5}};
|
|
RazorRange u = razorUnionBounds(ranges);
|
|
CHECK(u.startSeconds == 0.5);
|
|
CHECK(u.endSeconds == 6.5);
|
|
// Empty -> {0,0} sentinel (caller treats as "no razor area").
|
|
RazorRange empty = razorUnionBounds({});
|
|
CHECK(empty.startSeconds == 0.0 && empty.endSeconds == 0.0);
|
|
}
|
|
|
|
// --- sourceModeForScope: scope -> render source mode -------------------------
|
|
|
|
static void testScopeSourceModes() {
|
|
// Each scope drives a distinct render source. Item -> items, Track -> tracks.
|
|
// (There is no master scope — to capture the master you render a track.) These
|
|
// feed renderSettingsFor and must be supported.
|
|
CHECK(sourceModeForScope(CaptureScope::Item) == SourceMode::SelectedItems);
|
|
CHECK(sourceModeForScope(CaptureScope::Track) == SourceMode::SelectedTracks);
|
|
// Every scope's source mode is an offline-supported render source.
|
|
CHECK(renderSettingsFor(sourceModeForScope(CaptureScope::Item), 1.0).supported);
|
|
CHECK(renderSettingsFor(sourceModeForScope(CaptureScope::Track), 1.0).supported);
|
|
}
|
|
|
|
// --- inferRangeSource: razor-else-time (orthogonal to scope) -----------------
|
|
|
|
static void testRangeInference() {
|
|
// Razor present -> razor union wins; no razor -> time selection.
|
|
CHECK(inferRangeSource(true) == RangeSource::Razor);
|
|
CHECK(inferRangeSource(false) == RangeSource::TimeSelection);
|
|
}
|
|
|
|
// --- fxBypassPlanFor: the FX-scope invariant ----------------------------------
|
|
|
|
static void testItemScopeBypassesEverythingButTake() {
|
|
// Item = take/item FX ONLY. Bypass the item's own track FX, its ancestors, and
|
|
// the master. (If this returned bypassSelfFx=false the M7 defect — items heard
|
|
// through the track's FX — would recur; the assertion pins the fix.)
|
|
FxBypassPlan p = fxBypassPlanFor(CaptureScope::Item);
|
|
CHECK(p.bypassSelfFx);
|
|
CHECK(p.bypassAncestorFx);
|
|
CHECK(p.bypassMaster);
|
|
}
|
|
|
|
static void testTrackScopeKeepsSelfBypassesAncestorsAndMaster() {
|
|
// Track = item FX + the track's OWN FX. Keep self FX; bypass ancestors + master.
|
|
// Master stays a bypass target even though it is no longer a capture scope.
|
|
FxBypassPlan p = fxBypassPlanFor(CaptureScope::Track);
|
|
CHECK(!p.bypassSelfFx); // the whole point: the track's own FX stays live
|
|
CHECK(p.bypassAncestorFx); // no parent/folder FX
|
|
CHECK(p.bypassMaster); // no master FX
|
|
}
|
|
|
|
// --- captureActionTable: the scope x tail-variant taxonomy -------------------
|
|
|
|
static void testTableHasScopeAndTailVariants() {
|
|
const auto& table = captureActionTable();
|
|
// Four rows: item/track x (None exact-bounds, Auto "…with tail"). No master scope.
|
|
CHECK(table.size() == 4);
|
|
|
|
std::set<std::string> ids;
|
|
// Count each (scope, tailMode) pairing so we assert the FULL matrix is present,
|
|
// not merely that some item + some track row exist.
|
|
int itemNone = 0, itemAuto = 0, trackNone = 0, trackAuto = 0;
|
|
for (const auto& def : table) {
|
|
// Every id is a non-empty CEREBELLUM_REASAMPLER_ string and is UNIQUE
|
|
// (duplicate ids would collide on registration).
|
|
std::string id = def.commandString;
|
|
CHECK(id.rfind("CEREBELLUM_REASAMPLER_", 0) == 0);
|
|
CHECK(ids.insert(id).second); // false if duplicate
|
|
// Every scope resolves to a supported offline source.
|
|
CHECK(renderSettingsFor(sourceModeForScope(def.scope), 1.0).supported);
|
|
// Tail variants only ever ship None or Auto (Manual has no dedicated action yet).
|
|
CHECK(def.tailMode == TailMode::None || def.tailMode == TailMode::Auto);
|
|
|
|
if (def.scope == CaptureScope::Item && def.tailMode == TailMode::None) ++itemNone;
|
|
if (def.scope == CaptureScope::Item && def.tailMode == TailMode::Auto) ++itemAuto;
|
|
if (def.scope == CaptureScope::Track && def.tailMode == TailMode::None) ++trackNone;
|
|
if (def.scope == CaptureScope::Track && def.tailMode == TailMode::Auto) ++trackAuto;
|
|
}
|
|
// Exactly one row per (scope, tail) cell — the full 2x2 matrix, no dupes/gaps.
|
|
CHECK(itemNone == 1);
|
|
CHECK(itemAuto == 1);
|
|
CHECK(trackNone == 1);
|
|
CHECK(trackAuto == 1);
|
|
}
|
|
|
|
static void testTailVariantIdsAreDistinctFromExactRows() {
|
|
// The …_TAIL variants must be NEW forever-stable ids, not a rename of the exact
|
|
// rows (renaming would break shipped keybindings on the exact-bounds actions).
|
|
const auto& table = captureActionTable();
|
|
std::string itemNoneId, itemAutoId, trackNoneId, trackAutoId;
|
|
for (const auto& def : table) {
|
|
if (def.scope == CaptureScope::Item && def.tailMode == TailMode::None) itemNoneId = def.commandString;
|
|
if (def.scope == CaptureScope::Item && def.tailMode == TailMode::Auto) itemAutoId = def.commandString;
|
|
if (def.scope == CaptureScope::Track && def.tailMode == TailMode::None) trackNoneId = def.commandString;
|
|
if (def.scope == CaptureScope::Track && def.tailMode == TailMode::Auto) trackAutoId = def.commandString;
|
|
}
|
|
// The exact-bounds ids are the shipped CAPTURE_ITEM / CAPTURE_TRACK strings —
|
|
// pin them so a future edit that silently changes them fails the gate.
|
|
CHECK(itemNoneId == "CEREBELLUM_REASAMPLER_CAPTURE_ITEM");
|
|
CHECK(trackNoneId == "CEREBELLUM_REASAMPLER_CAPTURE_TRACK");
|
|
CHECK(itemAutoId == "CEREBELLUM_REASAMPLER_CAPTURE_ITEM_TAIL");
|
|
CHECK(trackAutoId == "CEREBELLUM_REASAMPLER_CAPTURE_TRACK_TAIL");
|
|
}
|
|
|
|
int main() {
|
|
testMasterMixWet();
|
|
testSelectedTracksWet();
|
|
testSelectedItemsSingleFile();
|
|
testRazorSingleFile();
|
|
testRealtimeIsUnsupportedOffline();
|
|
testTailNoneIsExactBounds();
|
|
testTailAutoIsSurgicalTrim();
|
|
testAutoTrimRatioDerivesFromDb();
|
|
testTailManualFixedNoTrim();
|
|
testTailManualClampsToCap();
|
|
testParseSingleTrackAudioArea();
|
|
testParseMultipleAreas();
|
|
testParseSkipsEnvelopeLaneAreas();
|
|
testParseEmptyAndMalformed();
|
|
testRazorUnionBounds();
|
|
testScopeSourceModes();
|
|
testRangeInference();
|
|
testItemScopeBypassesEverythingButTake();
|
|
testTrackScopeKeepsSelfBypassesAncestorsAndMaster();
|
|
testTableHasScopeAndTailVariants();
|
|
testTailVariantIdsAreDistinctFromExactRows();
|
|
|
|
if (g_fail == 0) std::printf("render_settings: all tests passed\n");
|
|
else std::printf("render_settings: %d CHECK(s) FAILED\n", g_fail);
|
|
return g_fail == 0 ? 0 : 1;
|
|
}
|