diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2016-07-08 17:09:09 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2016-09-27 14:59:30 -0500 |
commit | 591e59dae4e82da5bf30f8fa9e8163d55c05d94c (patch) | |
tree | 770b87418ff864304ec70e5c7da4d9450f8c1ea2 /libs/ardour/port_manager.cc | |
parent | 0318d3cd64557156bfd9851a4dec53bf03395b17 (diff) |
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
Diffstat (limited to 'libs/ardour/port_manager.cc')
-rw-r--r-- | libs/ardour/port_manager.cc | 57 |
1 files changed, 56 insertions, 1 deletions
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 <io.h> // Microsoft's nearest equivalent to <unistd.h> +#include <ardourext/misc.h> +#else +#include <regex.h> +#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<string>::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; +} |