fix(bank_panel): drive new-content baseline re-arm from persist's load signal

The detector re-armed its GuidBaseline on a pointer compare (proj != lastProject),
a weaker signal than persist's GUID-primary identity. On a load onto a recycled
ReaProject* the baseline never reset, so the just-loaded project's pre-existing
tracks diffed against the previous project and were mass-tagged into the active
mode — opening a Design-saved project mis-tagged its Arrange tracks. Re-arm now
rides persist's authoritative load signal via bankPanelNotifyProjectLoaded().
This commit is contained in:
2026-07-23 19:26:06 -04:00
parent 938c85a223
commit 02b6350dc9
4 changed files with 120 additions and 16 deletions
+43 -15
View File
@@ -227,15 +227,26 @@ struct PanelState {
//
// Each timer tick diffs the live track+item GUID set against the previous tick to
// auto-tag content created SINCE the last tick into the then-active mode. The
// baseline carries the first-poll-after-open guard so pre-existing content is never
// mass-tagged (it stays Arrange). `lastProject` detects a project switch so the
// baseline re-arms per project (a switch never diffs across two projects). Both live
// for the extension's lifetime alongside the session, independent of panel open/close
// — detection must run whether or not the dock is visible (content is created in the
// arrange, not the panel).
// baseline carries the first-poll-after-open guard (GuidBaseline self-arms on its
// first observe()) so pre-existing content is never mass-tagged (it stays Arrange).
//
// Project-load re-arm is driven by persist's AUTHORITATIVE load lifecycle, NOT by a
// pointer compare here. main.cpp calls bankPanelNotifyProjectLoaded() on the exact
// tick persist restores a project's membership + active mode (the same tick it
// reapplies the active mode); that sets reloadPending so the NEXT detect tick this
// same tick re-baselines against the fully-loaded set and reports nothing new. This
// replaces the former `proj != lastProject` re-arm, which used a WEAKER signal than
// persist (pointer-only vs persist's GUID-primary identity) and so missed a load onto
// a RECYCLED ReaProject* address — the just-loaded project's pre-existing tracks then
// diffed against the previous project's stale baseline and were mass-tagged into the
// active mode (the reload-mis-tag bug). Coordinating with persist's signal makes the
// two identity checks agree by construction.
//
// Lives for the extension's lifetime alongside the session, independent of panel
// open/close — detection must run whether or not the dock is visible (content is
// created in the arrange, not the panel).
GuidBaseline contentBaseline;
ReaProject* lastProject = nullptr;
bool sawProject = false; // false until the first detect tick sees a project
bool reloadPending = false; // set by bankPanelNotifyProjectLoaded; drained next detect tick
};
PanelState g_panel;
@@ -714,14 +725,19 @@ void detectNewContent() {
ReaProject* proj = EnumProjects(-1, nullptr, 0);
// Project switch (or first ever tick) re-arms the first-poll guard so we never diff
// across two projects. GUID-address recycling is bounded here: a missed reset can at
// worst re-baseline against the wrong project for one tick; the identity-of-record
// (persist's minted project GUID) governs the bank/model reload, not this detector.
if (!g_panel.sawProject || proj != g_panel.lastProject) {
// A project (re)load re-arms the first-poll guard so we never diff across two
// projects. The signal is persist's — main.cpp calls bankPanelNotifyProjectLoaded()
// on the tick persist restores the project's membership + active mode, which sets
// reloadPending. Draining it here re-baselines against the fully-loaded set (that
// same tick's reapply-active-mode enumerated those tracks, so they are present),
// and the observe() below returns nothing new — pre-existing untagged tracks stay
// Arrange. GuidBaseline self-arms on its first observe() for the very first tick, so
// no separate first-tick handling is needed here. Using persist's GUID-primary load
// signal (not a local pointer compare) is what fixes the reload-mis-tag: the two
// identity checks can no longer diverge on a recycled ReaProject* address.
if (g_panel.reloadPending) {
g_panel.contentBaseline.reset();
g_panel.lastProject = proj;
g_panel.sawProject = true;
g_panel.reloadPending = false;
}
std::set<std::string> live;
@@ -1141,6 +1157,18 @@ std::vector<std::string> bankPanelSelectedSampleIds() {
return ids;
}
void bankPanelNotifyProjectLoaded() {
// Persist restored a project's membership + active mode this tick (main.cpp calls
// this from the same consumeLoadSignal() branch that reapplies the active mode).
// Arm the new-content detector to re-baseline on its next tick so the just-loaded
// project's pre-existing content is treated as the baseline (nothing new) rather
// than diffed against the previous project and mass-tagged into the active mode.
// A flag (not an inline reset) because detectNewContent owns the baseline and runs
// later in the SAME OnTimer tick — it drains this and re-baselines against the live
// set in one place, keeping the reset and the observe() adjacent and ordered.
g_panel.reloadPending = true;
}
void bankPanelRefresh() {
// New-content auto-tag detection runs EVERY tick regardless of panel open/close:
// tracks/items are created in the arrange view, not the panel, so detection must
+11
View File
@@ -50,6 +50,17 @@ std::vector<std::string> bankPanelSelectedSampleIds();
// reflected without the panel diffing the bank itself.
void bankPanelRefresh();
// Notifies the panel that persist just (re)loaded a project's view model (membership +
// active mode). main.cpp calls this on the exact tick it drains persist's load signal
// and reapplies the active mode. It re-arms the new-content detector so the just-loaded
// project's PRE-EXISTING content is taken as the baseline (reported as nothing new),
// never diffed against the previously-open project and mass-tagged into the active mode.
// This coordinates the detector's project-identity signal with persist's authoritative
// (GUID-primary) one — the two can no longer diverge on a recycled ReaProject* address,
// which is what caused a project opened in Design to mis-tag its Arrange tracks. READ/
// arm of panel state only; no project or bank mutation.
void bankPanelNotifyProjectLoaded();
// The panel's current tail-mode setting (mode + Manual length), read by the plain
// CAPTURE_ITEM / CAPTURE_TRACK actions when building a CaptureRequest so a capture
// applies whatever the panel toggle is set to. Default None (exact bounds) — a
+9 -1
View File
@@ -216,8 +216,16 @@ static void OnTimer()
// project saved in Design mode parks the Arrange tracks automatically, no manual
// toggle. Fires exactly once per load (consumeLoadSignal clears it); idle ticks
// skip it. proj = nullptr -> REAPER's active project (the one poll just loaded).
if (g_session.consumeLoadSignal())
//
// The SAME signal re-arms the bank panel's new-content detector: a load must
// re-baseline the detector against the just-loaded project's content so its
// pre-existing tracks are never mis-detected as "new" and mass-tagged into the
// active mode (the reload-mis-tag bug). Notify BEFORE the reapply so the detector's
// re-arm and the model restore ride the one authoritative load event.
if (g_session.consumeLoadSignal()) {
reasampler::bankPanelNotifyProjectLoaded();
reasampler::applyMode(g_session.view(), g_session.view().activeModeId(), nullptr);
}
// Reflect a live bank change (capture / project load) in the docked grid.
// Cheap when the bank is unchanged (a fingerprint compare); repaints only on