From 287a21c09ee823f7b457f08383a969b78f367bb7 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 2 May 2023 23:35:31 +0200 Subject: [PATCH] Add API to query hardware port name In case of internal backends this allows to retrieve the Device name for a given (hashed unique) port-name. As opposed to "pretty-name" (which defaults to hw-port-name), this cannot be changed by the user. It is intended to be used when probing for control surfaces. --- libs/ardour/ardour/port_manager.h | 1 + libs/ardour/port_engine_shared.cc | 6 ++++++ libs/ardour/port_manager.cc | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/libs/ardour/ardour/port_manager.h b/libs/ardour/ardour/port_manager.h index 7254004395..dd9d53ae21 100644 --- a/libs/ardour/ardour/port_manager.h +++ b/libs/ardour/ardour/port_manager.h @@ -160,6 +160,7 @@ public: std::string make_port_name_relative (const std::string& name) const; std::string make_port_name_non_relative (const std::string& name) const; std::string get_pretty_name_by_name (const std::string& portname) const; + std::string get_hardware_port_name_by_name (const std::string& portname) const; std::string short_port_name_from_port_name (std::string const& full_name) const; bool port_is_mine (const std::string& fullname) const; diff --git a/libs/ardour/port_engine_shared.cc b/libs/ardour/port_engine_shared.cc index bc4494245a..a5bd6b7567 100644 --- a/libs/ardour/port_engine_shared.cc +++ b/libs/ardour/port_engine_shared.cc @@ -616,6 +616,12 @@ PortEngineSharedImpl::get_port_property (PortEngine::PortHandle port, const std: return 0; } } + if (key == "http://ardour.org/metadata/hardware-port-name") { + value = std::static_pointer_cast(port)->hw_port_name (); + if (!value.empty()) { + return 0; + } + } return -1; } diff --git a/libs/ardour/port_manager.cc b/libs/ardour/port_manager.cc index 4c2eed90de..a15fb43b55 100644 --- a/libs/ardour/port_manager.cc +++ b/libs/ardour/port_manager.cc @@ -355,6 +355,26 @@ PortManager::get_pretty_name_by_name (const std::string& portname) const return string (); } +std::string +PortManager::get_hardware_port_name_by_name (const std::string& portname) const +{ + PortEngine::PortHandle ph = _backend->get_port_by_name (portname); + + if (ph) { + std::string value; + std::string type; + if (0 == _backend->get_port_property (ph, "http://ardour.org/metadata/hardware-port-name", value, type)) { + return value; + } else { + return short_port_name_from_port_name (portname); + } + } + + return string (); +} + + + bool PortManager::port_is_mine (const string& portname) const {