add a new counter (for sidechain numbering)
authorRobin Gareus <robin@gareus.org>
Tue, 12 Apr 2016 11:49:50 +0000 (13:49 +0200)
committerRobin Gareus <robin@gareus.org>
Tue, 12 Apr 2016 11:49:50 +0000 (13:49 +0200)
libs/ardour/ardour/session.h
libs/ardour/session.cc
libs/ardour/session_state.cc

index c9d2de4d07102e9103471d04483e665edf903b68..9f8102c92891ef639e5ab74f4febd8cd1c55f8da 100644 (file)
@@ -186,6 +186,12 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        static int get_info_from_path (const std::string& xmlpath, float& sample_rate, SampleFormat& data_format);
        static std::string get_snapshot_from_instant (const std::string& session_dir);
 
+       /** a monotonic counter used for naming user-visible things uniquely
+        * (curently the sidechain port).
+        * Use sparingly to keep the numbers low, prefer PBD::ID for all
+        * internal, not user-visible IDs */
+       static unsigned int next_name_id ();
+
        std::string path() const { return _path; }
        std::string name() const { return _name; }
        std::string snap_name() const { return _current_snapshot_name; }
@@ -1098,6 +1104,10 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        int  create (const std::string& mix_template, BusProfile*);
        void destroy ();
 
+       static guint _name_id_counter;
+       static void init_name_id_counter (guint n);
+       static unsigned int name_id_counter ();
+
        enum SubState {
                PendingDeclickIn      = 0x1,  ///< pending de-click fade-in for start
                PendingDeclickOut     = 0x2,  ///< pending de-click fade-out for stop
index b4128411801395bf4d27ceebc603d9a0c64f6b41..a1a6268f615fbe95037bd8fb00b569bb23f5eb48 100644 (file)
@@ -125,6 +125,7 @@ using namespace PBD;
 
 bool Session::_disable_all_loaded_plugins = false;
 bool Session::_bypass_all_loaded_plugins = false;
+guint Session::_name_id_counter = 0;
 
 PBD::Signal1<int,uint32_t> Session::AudioEngineSetupRequired;
 PBD::Signal1<void,std::string> Session::Dialog;
@@ -311,6 +312,8 @@ Session::Session (AudioEngine &eng,
        pthread_mutex_init (&_rt_emit_mutex, 0);
        pthread_cond_init (&_rt_emit_cond, 0);
 
+       init_name_id_counter (1); // reset for new sessions, start at 1
+
        pre_engine_init (fullpath);
 
        setup_lua ();
@@ -469,6 +472,24 @@ Session::~Session ()
        destroy ();
 }
 
+unsigned int
+Session::next_name_id ()
+{
+       return g_atomic_int_add (&_name_id_counter, 1);
+}
+
+unsigned int
+Session::name_id_counter ()
+{
+       return g_atomic_int_get (&_name_id_counter);
+}
+
+void
+Session::init_name_id_counter (guint n)
+{
+       g_atomic_int_set (&_name_id_counter, n);
+}
+
 int
 Session::ensure_engine (uint32_t desired_sample_rate)
 {
index 41fb75ccc92eb513ae610d02dfdad1c3258f810c..975b38eee9c18dadbd69acba34d8d3279f7adecd 100644 (file)
@@ -1084,6 +1084,9 @@ Session::state (bool full_state)
        snprintf (buf, sizeof (buf), "%" PRIu64, ID::counter());
        node->add_property ("id-counter", buf);
 
+       snprintf (buf, sizeof (buf), "%u", name_id_counter ());
+       node->add_property ("name-counter", buf);
+
        /* save the event ID counter */
 
        snprintf (buf, sizeof (buf), "%d", Evoral::event_id_counter());
@@ -1336,10 +1339,13 @@ Session::set_state (const XMLNode& node, int version)
                ID::init_counter (now);
        }
 
-        if ((prop = node.property (X_("event-counter"))) != 0) {
-                Evoral::init_event_id_counter (atoi (prop->value()));
-        }
+       if ((prop = node.property (X_("name-counter"))) != 0) {
+               init_name_id_counter (atoi (prop->value()));
+       }
 
+       if ((prop = node.property (X_("event-counter"))) != 0) {
+               Evoral::init_event_id_counter (atoi (prop->value()));
+       }
 
        if ((child = find_named_node (node, "MIDIPorts")) != 0) {
                _midi_ports->set_midi_port_states (child->children());