laying the groundwork for adding/removing transport masters
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 4 Oct 2018 17:19:30 +0000 (13:19 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Fri, 5 Oct 2018 18:15:02 +0000 (14:15 -0400)
libs/ardour/ardour/transport_master.h
libs/ardour/ardour/transport_master_manager.h
libs/ardour/transport_master.cc
libs/ardour/transport_master_manager.cc

index e4fee4bba23871a4cf47189cdcf44ce785111d10..721b8e7a4a2151bbcd08bc91d523f29a73081381 100644 (file)
@@ -155,7 +155,7 @@ class LIBARDOUR_API TransportMaster : public PBD::Stateful {
        TransportMaster (SyncSource t, std::string const & name);
        virtual ~TransportMaster();
 
-       static boost::shared_ptr<TransportMaster> factory (SyncSource, std::string const &);
+       static boost::shared_ptr<TransportMaster> factory (SyncSource, std::string const &, bool removeable);
        static boost::shared_ptr<TransportMaster> factory (XMLNode const &);
 
        virtual void pre_process (pframes_t nframes, samplepos_t now, boost::optional<samplepos_t>) = 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<std::string>   _name;
        Session*        _session;
        sampleoffset_t  _current_delta;
        bool            _pending_collect;
+       bool            _removeable;
        PBD::Property<TransportRequestType> _request_mask; /* lists transport requests still accepted when we're in control */
        PBD::Property<bool> _locked;
        PBD::Property<bool> _sclock_synced;
index 4c4159cb6fb34aa3b943f051b366a7c24cacc087..46d195bf244fc8ea814eab60883eacf1050c4b6e 100644 (file)
@@ -41,7 +41,7 @@ class LIBARDOUR_API TransportMasterManager : public boost::noncopyable
 
        typedef std::list<boost::shared_ptr<TransportMaster> > 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 ();
 
index 5d02eb00732dc64fb206e8515f6bd879b09fc617..5a53976dcbe5461dcc0ee289590aeebe2e0d4fc8 100644 (file)
@@ -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<TransportMaster>();
@@ -338,28 +341,49 @@ TransportMaster::factory (XMLNode const & node)
                return boost::shared_ptr<TransportMaster>();
        }
 
-       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>
-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<TransportMaster> 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<TransportMaster> (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<TransportMaster> (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<TransportMaster> (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<TransportMaster> (new Engine_TransportMaster (*AudioEngine::instance()));
+               tm.reset (new Engine_TransportMaster (*AudioEngine::instance()));
+               break;
        default:
                break;
        }
 
-       return boost::shared_ptr<TransportMaster>();
+       if (tm) {
+               tm->set_removeable (removeable);
+       }
+
+       return tm;
 }
 
 boost::shared_ptr<Port>
index dee67bc6edb4249f753611b47a2eb7c7c798c5fd..95b86b4f07f6aa23dbf30d1c56eb86f9891dee60 100644 (file)
@@ -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<TransportMaster> 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;