From 170bc45de9e0011811598f0b5224d5b5668cf4b4 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 31 Jul 2024 17:38:40 +0200 Subject: [PATCH] Sort MIDI Ports by human readable name in connection matrix This is mainly for the benefit of CoreMIDI where MIDI ports are identified by kMIDIPropertyUniqueID and ALSA where Ardour uses a unique hash for persistent names. --- gtk2_ardour/port_group.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gtk2_ardour/port_group.cc b/gtk2_ardour/port_group.cc index 790f64b249..4cf9ae7159 100644 --- a/gtk2_ardour/port_group.cc +++ b/gtk2_ardour/port_group.cc @@ -628,10 +628,19 @@ PortGroupList::gather (ARDOUR::Session* session, ARDOUR::DataType type, bool inp if (ports.size () > 0) { struct SortByPortName { + bool _use_pretty_name; + SortByPortName (bool use_pretty_name) : _use_pretty_name (use_pretty_name) {} bool operator() (std::string const& lhs, std::string const& rhs) const { - return PBD::naturally_less (lhs.c_str (), rhs.c_str ()); + if (_use_pretty_name) { + /* add port-name as suffix (in case pretty-name is unset) */ + std::string l = AudioEngine::instance()->get_hardware_port_name_by_name (lhs) + lhs; + std::string r = AudioEngine::instance()->get_hardware_port_name_by_name (rhs) + rhs; + return PBD::naturally_less (l.c_str (), r.c_str ()); + } else { + return PBD::naturally_less (lhs.c_str (), rhs.c_str ()); + } } - } port_sorter; + } port_sorter (type == DataType::MIDI); std::sort (ports.begin (), ports.end (), port_sorter);