From 0786be859d8ad716f5b0eed53c3a82b4665c0efb Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 3 Dec 2023 20:38:31 +0100 Subject: [PATCH] Retain TransportMaster Ports across sessions Unloading a session should only remove session-ports. This fixes Timecode master sync when switching snapshots or sessions. --- libs/ardour/ardour/port_manager.h | 2 +- libs/ardour/audioengine.cc | 2 +- libs/ardour/port_manager.cc | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/libs/ardour/ardour/port_manager.h b/libs/ardour/ardour/port_manager.h index dd9d53ae21..ed9605e808 100644 --- a/libs/ardour/ardour/port_manager.h +++ b/libs/ardour/ardour/port_manager.h @@ -186,7 +186,7 @@ public: void set_port_pretty_name (std::string const&, std::string const&); - void remove_all_ports (); + void remove_session_ports (); /** reset port-buffers. e.g. after freewheeling */ void reinit (bool with_ratio = false); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 18154151e5..fc052ef749 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -834,7 +834,7 @@ AudioEngine::remove_session () SessionHandlePtr::set_session (0); } - remove_all_ports (); + remove_session_ports (); } void diff --git a/libs/ardour/port_manager.cc b/libs/ardour/port_manager.cc index f5aada8472..0b6681fefb 100644 --- a/libs/ardour/port_manager.cc +++ b/libs/ardour/port_manager.cc @@ -274,7 +274,7 @@ PortManager::clear_pending_port_deletions () } void -PortManager::remove_all_ports () +PortManager::remove_session_ports () { /* make sure that JACK callbacks that will be invoked as we cleanup * ports know that they have nothing to do. @@ -282,13 +282,20 @@ PortManager::remove_all_ports () PBD::Unwinder uw (_port_remove_in_progress, true); - /* process lock MUST be held by caller - */ + /* process lock MUST be held by caller */ { - RCUWriter writer (_ports); + RCUWriter writer (_ports); std::shared_ptr ps = writer.get_copy (); - ps->clear (); + + for (auto i = ps->begin (); i != ps->end (); ) { + std::shared_ptr port = i->second; + if (i->second->flags () & TransportMasterPort) { + ++i; + } else { + i = ps->erase (i); + } + } } /* clear dead wood list in RCU */ @@ -857,7 +864,7 @@ PortManager::reestablish_ports () if (i != p->end ()) { /* failed */ - remove_all_ports (); + remove_session_ports (); return -1; }