From 91314b68a5529eddea8a769f38906f91a178f67f Mon Sep 17 00:00:00 2001 From: Mads Kiilerich Date: Sat, 18 Jun 2022 21:09:14 +0200 Subject: [PATCH] temporal: always use Temporal::reset() for superclock and TempoMap default values Make sure all code paths that use Temporal will initialize and reset it properly. Some code paths (in tet runners) doesn't use Sessions, so Temporal::reset() has to be invoked directly. Just set the static superclock variable to 0 as initial value. TempoMap will still be initialized early as a singleton, but we introduce a new constructor so it is created empty (and thus not really usable until Temporal::reset() or similar has populated it). We can thus drop the static initialization of superclock. The default superclock rate of 282240000 will now only live in Temporal::reset(). With this change there should no longer be any uninitialized use of superclock_ticks_per_second(), and there should not be any problems for DEBUG_EARLY_SCTS_USE to catch. (It is however broken in other ways - that will be fixed next.) --- libs/ardour/test/testrunner.cc | 3 +++ libs/temporal/superclock.cc | 2 +- libs/temporal/tempo.cc | 2 +- libs/temporal/temporal/superclock.h | 2 +- libs/temporal/temporal/tempo.h | 1 + libs/temporal/test/testrunner.cc | 4 +--- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/ardour/test/testrunner.cc b/libs/ardour/test/testrunner.cc index bff2268d50..41bc52393c 100644 --- a/libs/ardour/test/testrunner.cc +++ b/libs/ardour/test/testrunner.cc @@ -11,6 +11,7 @@ #include "pbd/debug.h" #include "ardour/ardour.h" +#include "temporal/types.h" #include "test_ui.h" static const char* localedir = LOCALEDIR; @@ -51,6 +52,8 @@ main(int argc, char* argv[]) CPPUNIT_ASSERT (ARDOUR::init (true, localedir)); + Temporal::reset(); + TestUI* test_ui = new TestUI(); CppUnit::TestResult testresult; diff --git a/libs/temporal/superclock.cc b/libs/temporal/superclock.cc index c90df0a6bd..54b1a38b13 100644 --- a/libs/temporal/superclock.cc +++ b/libs/temporal/superclock.cc @@ -19,7 +19,7 @@ #include "temporal/superclock.h" #ifndef COMPILER_MSVC -Temporal::superclock_t Temporal::_superclock_ticks_per_second = 282240000 ; /* 2^10 * 3^2 * 5^4 * 7^2 */ +Temporal::superclock_t Temporal::_superclock_ticks_per_second = 0; #endif int Temporal::most_recent_engine_sample_rate = 48000; /* have to pick something as a default */ diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 5a676e24dc..9ef3a4e662 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -4373,7 +4373,7 @@ TempoMap::ramped_twist_tempi (TempoPoint& unused, TempoPoint& focus, TempoPoint& void TempoMap::init () { - WritableSharedPtr new_map (new TempoMap (Tempo (120, 4), Meter (4, 4))); + WritableSharedPtr new_map (new TempoMap ()); _map_mgr.init (new_map); fetch (); } diff --git a/libs/temporal/temporal/superclock.h b/libs/temporal/temporal/superclock.h index e3394c915d..bbf7bc6f71 100644 --- a/libs/temporal/temporal/superclock.h +++ b/libs/temporal/temporal/superclock.h @@ -32,7 +32,7 @@ typedef int64_t superclock_t; #ifndef COMPILER_MSVC extern superclock_t _superclock_ticks_per_second; #else - static superclock_t _superclock_ticks_per_second = 282240000; /* 2^10 * 3^2 * 5^4 * 7^2 */ + static superclock_t _superclock_ticks_per_second = 0; #endif extern bool scts_set; diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index df877e70dc..1cc8c6c3ef 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -792,6 +792,7 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible /* and now on with the rest of the show ... */ public: + LIBTEMPORAL_API TempoMap () {} LIBTEMPORAL_API TempoMap (Tempo const& initial_tempo, Meter const& initial_meter); LIBTEMPORAL_API TempoMap (TempoMap const&); LIBTEMPORAL_API TempoMap (XMLNode const&, int version); diff --git a/libs/temporal/test/testrunner.cc b/libs/temporal/test/testrunner.cc index d1802576a0..9222e3caf0 100644 --- a/libs/temporal/test/testrunner.cc +++ b/libs/temporal/test/testrunner.cc @@ -51,9 +51,7 @@ main(int argc, char* argv[]) if (!PBD::init ()) return 1; Temporal::init (); - // TempoMap::SharedPtr tmap = TempoMap::write_copy (); /* get writable copy of current tempo map */ - // change it - // TempoMap::update (tmap); /* update the global tempo map manager */ + Temporal::reset(); CppUnit::TestResult testresult;