From 1114a05f1fcf6ca3dbddd3de467578ff701e2d40 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 20 Oct 2025 14:58:10 -0600 Subject: [PATCH] fix incorrect locally scoped tempo map management This is tricky to explain, so rather than explain what was wrong, I'll describe how it works now. Whenever a ScopedTempoMapOwner::in() call occurs, we check the current thread-local tempo map ptr. If it is not owned by us (and we have a local tempo map that we want to use), set it so that it is. We continue to fetch() the global tempo map ptr back into the thread-local ptr when the local scope depth drops to zero. --- libs/temporal/temporal/scope.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/temporal/temporal/scope.h b/libs/temporal/temporal/scope.h index 1f7f189da9..c4b7cee7aa 100644 --- a/libs/temporal/temporal/scope.h +++ b/libs/temporal/temporal/scope.h @@ -87,11 +87,17 @@ class LIBTEMPORAL_API ScopedTempoMapOwner friend struct TempoMapScope; void in () const { - if (_local_tempo_map && local_tempo_map_depth++ == 0 ) { - DEBUG_TRACE (PBD::DEBUG::ScopedTempoMap, string_compose ("%1: in to local tempo %2, TMAP set\n", scope_name(), local_tempo_map_depth)); - Temporal::TempoMap::set (_local_tempo_map); + if (_local_tempo_map) { + Temporal::TempoMap::SharedPtr gtmap (Temporal::TempoMap::use()); + ++local_tempo_map_depth; + if (gtmap->scope_owner() != this) { + DEBUG_TRACE (PBD::DEBUG::ScopedTempoMap, string_compose ("%1: in to local tempo %2, TMAP set\n", scope_name(), local_tempo_map_depth)); + Temporal::TempoMap::set (_local_tempo_map); + } else { + DEBUG_TRACE (PBD::DEBUG::ScopedTempoMap, string_compose ("%1: in to local tempo %s, map left unset\n", scope_name(), local_tempo_map_depth)); + } } else { - DEBUG_TRACE (PBD::DEBUG::ScopedTempoMap, string_compose ("%1: in to local tempo %2, no tm set\n", scope_name(), local_tempo_map_depth)); + DEBUG_TRACE (PBD::DEBUG::ScopedTempoMap, string_compose ("%1: in to local tempo scope\n", scope_name())); } }