From 7a4ddf5ccebde846353b607f6e18e3240eaf7f92 Mon Sep 17 00:00:00 2001 From: Marijn Kruisselbrink Date: Wed, 28 Dec 2022 19:00:28 -0800 Subject: [PATCH] Group system ports by common prefix. Extra "other" ("External") ports were already being grouped by their common prefix into bundles to better display ports coming from different jack clients. This commit factors out that logic into a separate method to also apply this logic to extra "system" ("Hardware") ports. This way hardware ports from different devices/clients (for example when using pipewire as jack backend) are grouped by device rather than all being listed as one bundle. --- gtk2_ardour/port_group.cc | 54 +++++++++++++++++++++++++-------------- gtk2_ardour/port_group.h | 1 + 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/gtk2_ardour/port_group.cc b/gtk2_ardour/port_group.cc index 900b385585..334e1fb7a2 100644 --- a/gtk2_ardour/port_group.cc +++ b/gtk2_ardour/port_group.cc @@ -697,8 +697,7 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) { if (!extra_system[*i].empty()) { - boost::shared_ptr b = make_bundle_from_ports (extra_system[*i], *i, inputs); - system->add_bundle (b, allow_dups); + add_bundles_for_ports (extra_system[*i], *i, inputs, allow_dups, system); } } @@ -712,23 +711,7 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) { if (extra_other[*i].empty()) continue; - std::string cp; - std::vector nb; - for (uint32_t j = 0; j < extra_other[*i].size(); ++j) { - std::string nn = extra_other[*i][j]; - std::string pf = nn.substr (0, nn.find_first_of (":") + 1); - if (pf != cp && !nb.empty()) { - boost::shared_ptr b = make_bundle_from_ports (nb, *i, inputs); - other->add_bundle (b); - nb.clear(); - } - cp = pf; - nb.push_back(extra_other[*i][j]); - } - if (!nb.empty()) { - boost::shared_ptr b = make_bundle_from_ports (nb, *i, inputs); - other->add_bundle (b); - } + add_bundles_for_ports (extra_other[*i], *i, inputs, allow_dups, other); } if (!allow_dups) { @@ -747,6 +730,39 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp emit_changed (); } +void +PortGroupList::add_bundles_for_ports (std::vector const & p, ARDOUR::DataType type, bool inputs, bool allow_dups, boost::shared_ptr group) const +{ + bool has_colon = true, has_slash = true; + for (const auto& s : p) { + if (s.find('/') == std::string::npos) has_slash = false; + if (s.find(':') == std::string::npos) has_colon = false; + } + std::string sep = has_slash ? "/" : has_colon ? ":" : ""; + if (sep.empty()) { + boost::shared_ptr b = make_bundle_from_ports (p, type, inputs); + group->add_bundle (b, allow_dups); + return; + } + + std::vector nb; + std::string cp; + for (const auto& s : p) { + std::string pf = s.substr (0, s.find_first_of (sep) + 1); + if (pf != cp && !nb.empty()) { + boost::shared_ptr b = make_bundle_from_ports (nb, type, inputs); + group->add_bundle (b, allow_dups); + nb.clear(); + } + cp = pf; + nb.push_back(s); + } + if (!nb.empty()) { + boost::shared_ptr b = make_bundle_from_ports (nb, type, inputs); + group->add_bundle (b, allow_dups); + } +} + boost::shared_ptr PortGroupList::make_bundle_from_ports (std::vector const & p, ARDOUR::DataType type, bool inputs, std::string const& bundle_name) const { diff --git a/gtk2_ardour/port_group.h b/gtk2_ardour/port_group.h index 8240f5e6d2..dcc722601e 100644 --- a/gtk2_ardour/port_group.h +++ b/gtk2_ardour/port_group.h @@ -144,6 +144,7 @@ private: void emit_changed (); void emit_bundle_changed (ARDOUR::Bundle::Change); boost::shared_ptr make_bundle_from_ports (std::vector const &, ARDOUR::DataType, bool, std::string const& bundle_name = std::string()) const; + void add_bundles_for_ports (std::vector const &, ARDOUR::DataType, bool, bool, boost::shared_ptr) const; void maybe_add_processor_to_list (boost::weak_ptr, std::list > *, bool, std::set > &); mutable PortGroup::BundleList _bundles;