Strip FX writes from the Design View mode switch; split view.cpp into park/lanes/reconcile/tracks and add the record-scoped undo repair pass

This commit is contained in:
2026-08-06 17:19:43 -04:00
parent d455b9a2fa
commit c4038a9e9c
22 changed files with 1172 additions and 1146 deletions
+105
View File
@@ -0,0 +1,105 @@
// Standalone tests for the Design View park surface's pure decisions — no REAPER, no
// test framework.
//
// The properties under test: the four flags a park drives address exactly the four
// REAPER parameters the tool owns (never mute, never solo), and one mode apply leaves
// at most ONE undo point — none at all when a reapply found everything already where
// it wanted it.
#include "../src/shell/view/view_park.h"
#include "../src/shell/view/view.h" // applyMintsUndoPoint — the apply's undo-point fold
#include "core/view/view_mode_model.h" // makeParkPlan — the park flags' only producer
#include <cstdio>
#include <set>
#include <string>
#include <vector>
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)
// -- what a park is allowed to address ----------------------------------------
//
// trackFlagParm is the ONE mapping the park's pre-park read, the restore's write and
// the reconcile's repair all share; a mistyped parameter there is silent at compile
// time and drives the wrong track property forever.
static void testEachDrivenFlagAddressesItsOwnReaperParameter() {
const std::set<std::string> parms{trackFlagParm(Flag::ShowInTcp),
trackFlagParm(Flag::ShowInMixer),
trackFlagParm(Flag::MainSend),
trackFlagParm(Flag::FxEnable)};
CHECK(parms.size() == 4); // no two flags collapse onto one parameter
CHECK(parms.count("B_SHOWINTCP") == 1);
CHECK(parms.count("B_SHOWINMIXER") == 1);
CHECK(parms.count("B_MAINSEND") == 1);
CHECK(parms.count("I_FXEN") == 1);
}
static void testNoDrivenFlagCanEverAddressMuteOrSolo() {
// The never-touch-mute invariant, held at the one place a Flag becomes a REAPER
// parameter name.
for (const Flag f : {Flag::ShowInTcp, Flag::ShowInMixer, Flag::MainSend, Flag::FxEnable}) {
const std::string parm = trackFlagParm(f);
CHECK(parm != "B_MUTE");
CHECK(parm != "I_SOLO");
}
}
static void testAParkPlanDrivesEveryDrivenFlagToZero() {
// The four zeros are what a parked track's driven flags actually read; if
// makeParkPlan ever writes something else, this is the test that says so.
const TrackPlan park = makeParkPlan("{A}");
CHECK(park.flags.size() == 4);
std::set<std::string> parms;
for (const TrackFlagOp& op : park.flags) {
CHECK(op.guid == "{A}");
CHECK(op.value == 0);
parms.insert(trackFlagParm(op.flag));
}
CHECK(parms.size() == 4);
}
// -- the apply's one undo point ----------------------------------------------
//
// These pin applyMintsUndoPoint's fold only. The `wroteAnything` verdict it consumes
// — writeIfChanged / parkTrack / restoreTrack, all running against live REAPER calls
// — cannot be pinned here; docs/VERIFICATION.md §"Mode switching" is the sole cover
// for that plumbing being wired correctly.
static void testARealSwitchAlwaysLeavesAPointEvenWithNothingToWrite() {
// An explicitly fired action stays undoable even when the plan found nothing to
// write — the discard form is for reapplies only.
CHECK(applyMintsUndoPoint(/*realSwitch=*/true, /*wroteAnything=*/false));
CHECK(applyMintsUndoPoint(/*realSwitch=*/true, /*wroteAnything=*/true));
}
static void testAReapplyThatWroteSomethingLeavesAPoint() {
// A tag/untag reapply that actually parked a track: real project state moved.
CHECK(applyMintsUndoPoint(/*realSwitch=*/false, /*wroteAnything=*/true));
}
static void testAReapplyThatWroteNothingLeavesNoPointAtAll() {
// The project-load reapply over a project saved fully parked: every flag already
// sits where the plan wants it. Opening a project must not cost the user an undo
// step.
CHECK(!applyMintsUndoPoint(/*realSwitch=*/false, /*wroteAnything=*/false));
}
int main() {
testEachDrivenFlagAddressesItsOwnReaperParameter();
testNoDrivenFlagCanEverAddressMuteOrSolo();
testAParkPlanDrivesEveryDrivenFlagToZero();
testARealSwitchAlwaysLeavesAPointEvenWithNothingToWrite();
testAReapplyThatWroteSomethingLeavesAPoint();
testAReapplyThatWroteNothingLeavesNoPointAtAll();
if (g_fail == 0) std::printf("All tests passed.\n");
return g_fail ? 1 : 0;
}