From 67ba0bd992920032cc645cb2954084f54fa59b2f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 4 Oct 2018 13:19:30 -0400 Subject: laying the groundwork for adding/removing transport masters --- libs/ardour/ardour/transport_master.h | 10 ++++++- libs/ardour/ardour/transport_master_manager.h | 2 +- libs/ardour/transport_master.cc | 38 ++++++++++++++++++++++----- libs/ardour/transport_master_manager.cc | 17 +++++++----- 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/libs/ardour/ardour/transport_master.h b/libs/ardour/ardour/transport_master.h index e4fee4bba2..721b8e7a4a 100644 --- a/libs/ardour/ardour/transport_master.h +++ b/libs/ardour/ardour/transport_master.h @@ -155,7 +155,7 @@ class LIBARDOUR_API TransportMaster : public PBD::Stateful { TransportMaster (SyncSource t, std::string const & name); virtual ~TransportMaster(); - static boost::shared_ptr factory (SyncSource, std::string const &); + static boost::shared_ptr factory (SyncSource, std::string const &, bool removeable); static boost::shared_ptr factory (XMLNode const &); virtual void pre_process (pframes_t nframes, samplepos_t now, boost::optional) = 0; @@ -337,12 +337,20 @@ class LIBARDOUR_API TransportMaster : public PBD::Stateful { void get_current (double&, samplepos_t&, samplepos_t); + /* this is set at construction, and not changeable later, so it is not + * a property + */ + + bool removeable () const { return _removeable; } + void set_removeable (bool yn) { _removeable = yn; } + protected: SyncSource _type; PBD::Property _name; Session* _session; sampleoffset_t _current_delta; bool _pending_collect; + bool _removeable; PBD::Property _request_mask; /* lists transport requests still accepted when we're in control */ PBD::Property _locked; PBD::Property _sclock_synced; diff --git a/libs/ardour/ardour/transport_master_manager.h b/libs/ardour/ardour/transport_master_manager.h index 4c4159cb6f..46d195bf24 100644 --- a/libs/ardour/ardour/transport_master_manager.h +++ b/libs/ardour/ardour/transport_master_manager.h @@ -41,7 +41,7 @@ class LIBARDOUR_API TransportMasterManager : public boost::noncopyable typedef std::list > TransportMasters; - int add (SyncSource type, std::string const & name); + int add (SyncSource type, std::string const & name, bool removeable = true); int remove (std::string const & name); void clear (); diff --git a/libs/ardour/transport_master.cc b/libs/ardour/transport_master.cc index 5d02eb0073..5a53976dcb 100644 --- a/libs/ardour/transport_master.cc +++ b/libs/ardour/transport_master.cc @@ -68,6 +68,7 @@ TransportMaster::TransportMaster (SyncSource t, std::string const & name) , _session (0) , _current_delta (0) , _pending_collect (true) + , _removeable (false) , _request_mask (Properties::allowed_transport_requests, TransportRequestType (0)) , _locked (Properties::locked, false) , _sclock_synced (Properties::sclock_synced, false) @@ -285,6 +286,7 @@ TransportMaster::get_state () { XMLNode* node = new XMLNode (state_node_name); node->set_property (X_("type"), _type); + node->set_property (X_("removeable"), _removeable); add_properties (*node); @@ -329,6 +331,7 @@ TransportMaster::factory (XMLNode const & node) SyncSource type; std::string name; + bool removeable; if (!node.get_property (X_("type"), type)) { return boost::shared_ptr(); @@ -338,28 +341,49 @@ TransportMaster::factory (XMLNode const & node) return boost::shared_ptr(); } - return factory (type, name); + if (!node.get_property (X_("removeable"), removeable)) { + /* development versions of 6.0 didn't have this property for a + while. Any TM listed in XML at that time was non-removeable + */ + removeable = false; + } + + DEBUG_TRACE (DEBUG::Slave, string_compose ("xml-construct %1 name %2 removeable %3\n", enum_2_string (type), name, removeable)); + + return factory (type, name, removeable); } boost::shared_ptr -TransportMaster::factory (SyncSource type, std::string const& name) +TransportMaster::factory (SyncSource type, std::string const& name, bool removeable) { /* XXX need to count existing sources of a given type */ + boost::shared_ptr tm; + + DEBUG_TRACE (DEBUG::Slave, string_compose ("factory-construct %1 name %2 removeable %3\n", enum_2_string (type), name, removeable)); + switch (type) { case MTC: - return boost::shared_ptr (new MTC_TransportMaster (sync_source_to_string (type))); + tm.reset (new MTC_TransportMaster (sync_source_to_string (type))); + break; case LTC: - return boost::shared_ptr (new LTC_TransportMaster (sync_source_to_string (type))); + tm.reset (new LTC_TransportMaster (sync_source_to_string (type))); + break; case MIDIClock: - return boost::shared_ptr (new MIDIClock_TransportMaster (sync_source_to_string (type))); + tm.reset (new MIDIClock_TransportMaster (sync_source_to_string (type))); + break; case Engine: - return boost::shared_ptr (new Engine_TransportMaster (*AudioEngine::instance())); + tm.reset (new Engine_TransportMaster (*AudioEngine::instance())); + break; default: break; } - return boost::shared_ptr(); + if (tm) { + tm->set_removeable (removeable); + } + + return tm; } boost::shared_ptr diff --git a/libs/ardour/transport_master_manager.cc b/libs/ardour/transport_master_manager.cc index dee67bc6ed..95b86b4f07 100644 --- a/libs/ardour/transport_master_manager.cc +++ b/libs/ardour/transport_master_manager.cc @@ -57,10 +57,10 @@ TransportMasterManager::init () /* setup default transport masters. Most people will never need any others */ - add (Engine, X_("JACK Transport")); - add (MTC, X_("MTC")); - add (LTC, X_("LTC")); - add (MIDIClock, X_("MIDI Clock")); + add (Engine, X_("JACK Transport"), false); + add (MTC, X_("MTC"), false); + add (LTC, X_("LTC"), false); + add (MIDIClock, X_("MIDI Clock"), false); } catch (...) { return -1; } @@ -306,14 +306,16 @@ TransportMasterManager::init_transport_master_dll (double speed, samplepos_t pos } int -TransportMasterManager::add (SyncSource type, std::string const & name) +TransportMasterManager::add (SyncSource type, std::string const & name, bool removeable) { int ret = 0; boost::shared_ptr tm; + DEBUG_TRACE (DEBUG::Slave, string_compose ("adding new transport master, type %1 name %2 removeable %3\n", enum_2_string (type), name, removeable)); + { Glib::Threads::RWLock::WriterLock lm (lock); - tm = TransportMaster::factory (type, name); + tm = TransportMaster::factory (type, name, removeable); ret = add_locked (tm); } @@ -353,6 +355,9 @@ TransportMasterManager::remove (std::string const & name) for (TransportMasters::iterator t = _transport_masters.begin(); t != _transport_masters.end(); ++t) { if ((*t)->name() == name) { + if (!tm->removeable()) { + return -1; + } tm = *t; _transport_masters.erase (t); ret = 0; -- cgit v1.2.3