summaryrefslogtreecommitdiffstats
path: root/src/PortID.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-28 15:58:38 +0100
committerDavid Robillard <d@drobilla.net>2020-11-28 17:39:10 +0100
commit0f8bd14d3487c35280c33bbfd133dd9e37c8f07e (patch)
tree701cac49a1e6e34025a8352e53845859566106b3 /src/PortID.hpp
parenta872f8b07498c85f0f2eb8b55462ac9df9ce4677 (diff)
downloadpatchage-0f8bd14d3487c35280c33bbfd133dd9e37c8f07e.tar.gz
patchage-0f8bd14d3487c35280c33bbfd133dd9e37c8f07e.tar.bz2
patchage-0f8bd14d3487c35280c33bbfd133dd9e37c8f07e.zip
Index clients and ports by ID
Diffstat (limited to 'src/PortID.hpp')
-rw-r--r--src/PortID.hpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/PortID.hpp b/src/PortID.hpp
index 4887a27..e399220 100644
--- a/src/PortID.hpp
+++ b/src/PortID.hpp
@@ -17,6 +17,7 @@
#ifndef PATCHAGE_PORTID_HPP
#define PATCHAGE_PORTID_HPP
+#include "ClientID.hpp"
#include "ClientType.hpp"
#include <cassert>
@@ -44,6 +45,13 @@ struct PortID
return PortID{Type::jack, std::move(name)};
}
+ /// Return an ID for a JACK port by separate client and port name
+ static PortID
+ jack(const std::string& client_name, const std::string& port_name)
+ {
+ return PortID{Type::jack, client_name + ":" + port_name};
+ }
+
/// Return an ID for an ALSA Sequencer port by ID
static PortID
alsa(const uint8_t client_id, const uint8_t port, const bool is_input)
@@ -51,6 +59,17 @@ struct PortID
return PortID{Type::alsa, client_id, port, is_input};
}
+ /// Return the ID of the client that hosts this port
+ ClientID client() const
+ {
+ switch (_type) {
+ case Type::jack:
+ return ClientID::jack(_jack_name.substr(0, _jack_name.find(':')));
+ case Type::alsa:
+ return ClientID::alsa(_alsa_client);
+ }
+ }
+
Type type() const { return _type; }
const std::string& jack_name() const { return _jack_name; }
uint8_t alsa_client() const { return _alsa_client; }
@@ -64,6 +83,8 @@ private:
{
assert(_type == Type::jack);
assert(_jack_name.find(':') != std::string::npos);
+ assert(_jack_name.find(':') > 0);
+ assert(_jack_name.find(':') < _jack_name.length() - 1);
}
PortID(const Type type,
@@ -102,6 +123,27 @@ operator<<(std::ostream& os, const PortID& id)
}
static inline bool
+operator==(const PortID& lhs, const PortID& rhs)
+{
+ if (lhs.type() != rhs.type()) {
+ return false;
+ }
+
+ switch (lhs.type()) {
+ case PortID::Type::jack:
+ return lhs.jack_name() == rhs.jack_name();
+ case PortID::Type::alsa:
+ return std::make_tuple(
+ lhs.alsa_client(), lhs.alsa_port(), lhs.alsa_is_input()) ==
+ std::make_tuple(
+ rhs.alsa_client(), rhs.alsa_port(), rhs.alsa_is_input());
+ }
+
+ assert(false);
+ return false;
+}
+
+static inline bool
operator<(const PortID& lhs, const PortID& rhs)
{
if (lhs.type() != rhs.type()) {