From f9befd9669dd9bb8ea421e998cdb48a78ed74254 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 23 Jun 2024 23:59:42 +0200 Subject: [PATCH] Fix IO::build_legal_port_name.. amend prev commit --- libs/ardour/ardour/io.h | 4 ++-- libs/ardour/io.cc | 40 +++++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/libs/ardour/ardour/io.h b/libs/ardour/ardour/io.h index 05484c063f..e4cef915ab 100644 --- a/libs/ardour/ardour/io.h +++ b/libs/ardour/ardour/io.h @@ -237,8 +237,8 @@ private: int ensure_ports_locked (ChanCount, bool clear, bool& changed); - std::string build_legal_port_name (DataType type); - int32_t find_port_hole (const char* base); + std::string build_legal_port_name (std::shared_ptr, DataType type); + int32_t find_port_hole (std::shared_ptr, const char* base); void setup_bundle (); std::string bundle_channel_name (uint32_t, uint32_t, DataType) const; diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index 32d412d1c3..4a02c155cc 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -307,25 +307,25 @@ IO::add_port (string destination, void* src, DataType type) BLOCK_PROCESS_CALLBACK (); /* Create a new port */ - - string portname = build_legal_port_name (type); - - if (_direction == Input) { - if ((our_port = _session.engine().register_input_port (type, portname)) == 0) { - error << string_compose(_("IO: cannot register input port %1"), portname) << endmsg; - return -1; - } - } else { - if ((our_port = _session.engine().register_output_port (type, portname)) == 0) { - error << string_compose(_("IO: cannot register output port %1"), portname) << endmsg; - return -1; - } - } - { RCUWriter writer (_ports); std::shared_ptr p = writer.get_copy (); change.before = p->count (); + + string portname = build_legal_port_name (p, type); + + if (_direction == Input) { + if ((our_port = _session.engine().register_input_port (type, portname)) == 0) { + error << string_compose(_("IO: cannot register input port %1"), portname) << endmsg; + return -1; + } + } else { + if ((our_port = _session.engine().register_output_port (type, portname)) == 0) { + error << string_compose(_("IO: cannot register output port %1"), portname) << endmsg; + return -1; + } + } + p->add (our_port); change.after = p->count (); } @@ -418,7 +418,7 @@ IO::ensure_ports_locked (ChanCount count, bool clear, bool& changed) /* create any necessary new ports */ while (p->count ().get(*t) < n) { - string portname = build_legal_port_name (*t); + string portname = build_legal_port_name (p, *t); try { @@ -1334,7 +1334,7 @@ IO::bundle_changed (Bundle::Change /*c*/) string -IO::build_legal_port_name (DataType type) +IO::build_legal_port_name (std::shared_ptr ports, DataType type) { const int name_size = AudioEngine::instance()->port_name_size(); int limit; @@ -1381,21 +1381,19 @@ IO::build_legal_port_name (DataType type) snprintf (&buf1[0], name_size+1, ("%.*s/%s"), limit, nom.c_str(), suffix.c_str()); - int port_number = find_port_hole (&buf1[0]); + int port_number = find_port_hole (ports, &buf1[0]); snprintf (&buf2[0], name_size+1, "%s %d", &buf1[0], port_number); return string (&buf2[0]); } int32_t -IO::find_port_hole (const char* base) +IO::find_port_hole (std::shared_ptr ports, const char* base) { /* CALLER MUST HOLD IO LOCK */ uint32_t n; - std::shared_ptr ports = _ports.reader(); - if (ports->empty()) { return 1; }