Extract elapsedAtLeast to core/util, dedupe the throttle rationale, and correct the alloc-count/PLAN citations

This commit is contained in:
2026-08-03 14:58:33 -04:00
parent 170b2e4994
commit 32c7e959ae
7 changed files with 129 additions and 24 deletions
+17 -11
View File
@@ -136,8 +136,8 @@ void enumerateLiveGuids(ReaProject* proj, std::set<std::string>& allGuids,
// One detection tick: REAPER exposes no "item/track added" callback, so this diffs live
// GUIDs against the baseline and auto-tags the new ones into the active mode. Called every
// timer tick regardless of panel open/close, but the enumeration itself is throttled to
// kDetectIntervalMs (see the gate below). READ-ONLY on the project; mutates only the
// timer tick regardless of panel open/close; the enumeration's throttle and its correctness
// argument are the gate immediately below. READ-ONLY on the project; mutates only the
// in-memory membership index — deliberately OUTSIDE any Undo block (auto-tag is a
// background metadata update, not a destructive edit; an Undo block here would flood
// REAPER's history with an entry per tick that sees new content).
@@ -147,12 +147,18 @@ void enumerateLiveGuids(ReaProject* proj, std::set<std::string>& allGuids,
bool detectNewContent() {
if (!g_panel.session) return false;
// Throttles the enumeration (O(T+I) REAPER calls + allocations) to kDetectIntervalMs,
// independent of how often the caller ticks. A skipped tick leaves reloadPending/the
// baseline untouched, so the guards below still run before the NEXT diff whenever this
// gate next opens — only the diff's cadence changes, not its correctness.
// Throttles the enumeration (O(T+I) REAPER calls + allocations) to kDetectIntervalMs via
// elapsedAtLeast (core/util; wraparound-safe against GetTickCount()'s rollover, see its
// header). A skipped tick leaves reloadPending/the baseline untouched, so the guards below
// still run before the NEXT diff whenever this gate next opens — only the diff's cadence
// changes, not its correctness.
//
// KNOWN CONSEQUENCE, not new: a new item's mode resolves from
// preExistingTrackModes()/activeModeId() at ENUMERATION time (below), not creation time, so
// switching mode or moving the item before the next tick can land it in a different mode
// than a tighter cadence would — the window existed at ~33 ms; now widened ~16x.
const unsigned int now = GetTickCount();
if (now - g_panel.lastDetectTick < kDetectIntervalMs) return false;
if (!elapsedAtLeast(now, g_panel.lastDetectTick, kDetectIntervalMs)) return false;
g_panel.lastDetectTick = now;
ReaProject* proj = EnumProjects(-1, nullptr, 0);
@@ -556,10 +562,10 @@ void bankPanelNotifyProjectLoaded() {
}
void bankPanelRefresh() {
// New-content auto-tag detection is CALLED every tick regardless of panel open/close
// (tracks/items are created in the arrange view, not the panel), but the enumeration
// it drives is throttled — see kDetectIntervalMs. READ-ONLY on the project; only
// mutates the in-memory membership index.
// New-content auto-tag detection runs every tick regardless of panel open/close (tracks/
// items are created in the arrange view, not the panel); detectNewContent (panel_input.cpp,
// above) is the authoritative comment for its throttle, correctness argument, and
// read-only/mutation contract.
const bool tagged = panel::detectNewContent();
// Lane minting runs ONLY when detection just tagged new content — a track can only