From 8dbbc1df5479a27d930df24991a14495931e5bbe Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 27 Nov 2020 22:13:41 -0700 Subject: [PATCH] library changes to get libtemporal setup at application startup --- libs/ardour/graph.cc | 2 ++ libs/ardour/session_state.cc | 26 ++++++++++++++------------ libs/pbd/pbd/rcu.h | 12 ++++++++++-- libs/temporal/enums.cc | 18 +++++++++++++++++- libs/temporal/tempo.cc | 8 ++++++++ libs/temporal/temporal/tempo.h | 2 ++ 6 files changed, 53 insertions(+), 15 deletions(-) diff --git a/libs/ardour/graph.cc b/libs/ardour/graph.cc index d1b1e27c9c..5a08e2c787 100644 --- a/libs/ardour/graph.cc +++ b/libs/ardour/graph.cc @@ -28,6 +28,7 @@ #include "pbd/pthread_utils.h" #include "temporal/superclock.h" +#include "temporal/tempo.h" #include "ardour/audioengine.h" #include "ardour/debug.h" @@ -535,6 +536,7 @@ void Graph::setup_thread_local_variables () { Temporal::_thread_sample_rate = _session.sample_rate (); + Temporal::TempoMap::fetch (); } void diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 9a69f6408f..b998cfa09a 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -1557,6 +1557,20 @@ Session::set_state (const XMLNode& node, int version) goto out; } + /* need the tempo map setup ASAP */ + + if ((child = find_named_node (node, "TempoMap")) == 0) { + error << _("Session: XML state has no Tempo Map section") << endmsg; + goto out; + } else { + try { + TempoMap::SharedPtr new_map (new TempoMap (*child, version)); + TempoMap::update (new_map); + } catch (...) { + goto out; + } + } + node.get_property ("name", _name); if (node.get_property (X_("sample-rate"), _base_sample_rate)) { @@ -1645,18 +1659,6 @@ Session::set_state (const XMLNode& node, int version) goto out; } - if ((child = find_named_node (node, "TempoMap")) == 0) { - error << _("Session: XML state has no Tempo Map section") << endmsg; - goto out; - } else { - try { - TempoMap::SharedPtr new_map (new TempoMap (*child, version)); - TempoMap::update (new_map); - } catch (...) { - goto out; - } - } - if ((child = find_named_node (node, "Locations")) == 0) { error << _("Session: XML state has no locations section") << endmsg; goto out; diff --git a/libs/pbd/pbd/rcu.h b/libs/pbd/pbd/rcu.h index cdad78325c..8d544a8176 100644 --- a/libs/pbd/pbd/rcu.h +++ b/libs/pbd/pbd/rcu.h @@ -144,11 +144,19 @@ template class /*LIBPBD_API*/ SerializedRCUManager : public RCUManager { public: - SerializedRCUManager (T* new_rcu_value) - : RCUManager (new_rcu_value) + SerializedRCUManager(T* new_rcu_value) + : RCUManager(new_rcu_value) + , current_write_old (0) { } + void init (boost::shared_ptr new_rcu_value) { + assert (*RCUManager::x.m_rcu_value == boost::shared_ptr ()); + + boost::shared_ptr* new_spp = new boost::shared_ptr (new_rcu_value); + g_atomic_pointer_set (&RCUManager::x.gptr, new_spp); + } + boost::shared_ptr write_copy () { _lock.lock (); diff --git a/libs/temporal/enums.cc b/libs/temporal/enums.cc index 8acb7429a6..0405efd881 100644 --- a/libs/temporal/enums.cc +++ b/libs/temporal/enums.cc @@ -27,6 +27,8 @@ using namespace PBD; using namespace Temporal; using namespace std; +static bool libtemporal_initialized = false; + void setup_libtemporal_enums () { @@ -62,5 +64,19 @@ setup_libtemporal_enums () void Temporal::init () { - setup_libtemporal_enums (); + if (!libtemporal_initialized) { + setup_libtemporal_enums (); + + + /* this should be the main (typically GUI) thread. Normally + * this will be done by some + * Gtkmm2ext::UI::event_loop_precall() but we need to make sure + * that things are set up for this thread before we get started + */ + + Temporal::_thread_sample_rate = 44100; + TempoMap::init (); + + libtemporal_initialized = true; + } } diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 74763bc0d6..ec065d46cc 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -2877,3 +2877,11 @@ TempoMap::MementoBinder::set_state (XMLNode const & node, int version) const /* now update this thread's view of the current tempo map */ fetch (); } + +void +TempoMap::init () +{ + SharedPtr new_map (new TempoMap (Tempo (120), Meter (4, 4))); + _map_mgr.init (new_map); + fetch (); +} diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index 50e4b5e39a..79c7a85542 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -619,6 +619,8 @@ class LIBTEMPORAL_API TempoMap : public PBD::StatefulDestructible static thread_local SharedPtr _tempo_map_p; static SerializedRCUManager _map_mgr; public: + static void init (); + static void update_thread_tempo_map() { _tempo_map_p = _map_mgr.reader(); } static SharedPtr use() { assert (_tempo_map_p); return _tempo_map_p; } static SharedPtr fetch() { update_thread_tempo_map(); return use(); }