diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index c9d2de4d07..9f8102c928 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -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 diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index b412841180..a1a6268f61 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -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 Session::AudioEngineSetupRequired; PBD::Signal1 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) { diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 41fb75ccc9..975b38eee9 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -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());