From 591e59dae4e82da5bf30f8fa9e8163d55c05d94c Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 8 Jul 2016 17:09:09 -0400 Subject: add PortManager::port_is_control_only() and use it in PortManager::get_ports() This allows us to avoid using "control-only" ports (e.g. Ableton Push 2 hardware ports) as inputs or outputs --- libs/ardour/port_manager.cc | 57 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'libs/ardour/port_manager.cc') diff --git a/libs/ardour/port_manager.cc b/libs/ardour/port_manager.cc index c6b2c0b47d..36b3d1ca46 100644 --- a/libs/ardour/port_manager.cc +++ b/libs/ardour/port_manager.cc @@ -17,6 +17,13 @@ */ +#ifdef COMPILER_MSVC +#include // Microsoft's nearest equivalent to +#include +#else +#include +#endif + #include "pbd/convert.h" #include "pbd/error.h" @@ -266,7 +273,23 @@ PortManager::get_ports (const string& port_name_pattern, DataType type, PortFlag return 0; } - return _backend->get_ports (port_name_pattern, type, flags, s); + int ret = _backend->get_ports (port_name_pattern, type, flags, s); + if (!ret) { + return ret; + } + + if (!(flags & ControlOnly)) { + /* remove all ports whose name indicates that they are for control only */ + for (vector::iterator si = s.begin(); si != s.end();) { + if (port_is_control_only (*si)) { + si = s.erase (si); + } else { + ++si; + } + } + } + + return 0; } void @@ -780,3 +803,35 @@ PortManager::port_engine() assert (_backend); return *_backend; } + +bool +PortManager::port_is_control_only (std::string const& name) +{ + static regex_t compiled_pattern; + static string pattern; + + if (pattern.empty()) { + + /* This is a list of regular expressions that match ports + * related to physical MIDI devices that we do not want to + * expose as normal physical ports. + */ + + const char * const control_only_ports[] = { + X_(".*Ableton Push.*"), + }; + + pattern = "("; + for (size_t n = 0; n < sizeof (control_only_ports)/sizeof (control_only_ports[0]); ++n) { + if (n > 0) { + pattern += '|'; + } + pattern += control_only_ports[n]; + } + pattern += ')'; + + regcomp (&compiled_pattern, pattern.c_str(), REG_EXTENDED|REG_NOSUB); + } + + return regexec (&compiled_pattern, name.c_str(), 0, 0, 0) == 0; +} -- cgit v1.2.3