From 10a9f00294c3a33477dee21980f91d1417b6ef21 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 27 Nov 2020 20:18:41 +0100 Subject: Ensure that ports always have an ID --- src/AlsaDriver.cpp | 10 ++++++---- src/JackDbusDriver.cpp | 7 +++++-- src/JackDbusDriver.hpp | 1 + src/JackDriver.cpp | 1 + src/PatchagePort.hpp | 4 ++++ src/PortID.hpp | 10 +++++----- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index fdda5e7..dc07d48 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -322,20 +322,22 @@ AlsaDriver::create_port(PatchageModule& parent, bool is_input, snd_seq_addr_t addr) { + const PortID id{addr, is_input}; + auto* ret = new PatchagePort(parent, PortType::alsa_midi, + id, name, "", is_input, _app->conf()->get_port_color(PortType::alsa_midi), _app->show_human_names()); - dynamic_cast(parent.canvas()) - ->index_port(PortID(addr, is_input), ret); + dynamic_cast(parent.canvas())->index_port(id, ret); - _app->canvas()->index_port(PortID(addr, is_input), ret); - _port_addrs.insert(std::make_pair(ret, PortID(addr, is_input))); + _app->canvas()->index_port(id, ret); + _port_addrs.insert(std::make_pair(ret, id)); return ret; } diff --git a/src/JackDbusDriver.cpp b/src/JackDbusDriver.cpp index 382ec3b..b2acc69 100644 --- a/src/JackDbusDriver.cpp +++ b/src/JackDbusDriver.cpp @@ -588,6 +588,7 @@ JackDriver::is_attached() const void JackDriver::add_port(PatchageModule* module, PortType type, + PortID id, const std::string& name, bool is_input) { @@ -597,6 +598,7 @@ JackDriver::add_port(PatchageModule* module, new PatchagePort(*module, type, + id, name, "", // TODO: pretty name is_input, @@ -606,8 +608,8 @@ JackDriver::add_port(PatchageModule* module, void JackDriver::add_port(dbus_uint64_t /*client_id*/, - const char* client_name, - dbus_uint64_t /*port_id*/, + const char* client_name, + dbus_uint64_t port_id, const char* port_name, dbus_uint32_t port_flags, dbus_uint32_t port_type) @@ -640,6 +642,7 @@ JackDriver::add_port(dbus_uint64_t /*client_id*/, add_port(module, local_port_type, + PortID{static_cast(port_id), false}, port_name, port_flags & JACKDBUS_PORT_FLAG_INPUT); } diff --git a/src/JackDbusDriver.hpp b/src/JackDbusDriver.hpp index 00c2a83..5b443b0 100644 --- a/src/JackDbusDriver.hpp +++ b/src/JackDbusDriver.hpp @@ -83,6 +83,7 @@ private: void add_port(PatchageModule* module, PortType type, + PortID id, const std::string& name, bool is_input); diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index a75aff4..5c08144 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -253,6 +253,7 @@ JackDriver::create_port(PatchageModule& parent, auto* ret = new PatchagePort(parent, port_type, + id, jack_port_short_name(port), label, (jack_port_flags(port) & JackPortIsInput), diff --git a/src/PatchagePort.hpp b/src/PatchagePort.hpp index b790f0d..8a96f20 100644 --- a/src/PatchagePort.hpp +++ b/src/PatchagePort.hpp @@ -42,6 +42,7 @@ class PatchagePort : public Ganv::Port public: PatchagePort(Ganv::Module& module, PortType type, + PortID id, const std::string& name, const std::string& human_name, bool is_input, @@ -53,6 +54,7 @@ public: is_input, color) , _type(type) + , _id(id) , _name(name) , _human_name(human_name) , _order(order) @@ -99,12 +101,14 @@ public: } PortType type() const { return _type; } + PortID id() const { return _id; } const std::string& name() const { return _name; } const std::string& human_name() const { return _human_name; } const boost::optional& order() const { return _order; } private: PortType _type; + PortID _id; std::string _name; std::string _human_name; boost::optional _order; diff --git a/src/PortID.hpp b/src/PortID.hpp index c29d662..2d41f92 100644 --- a/src/PortID.hpp +++ b/src/PortID.hpp @@ -42,8 +42,8 @@ struct PortID PortID() = default; -#ifdef PATCHAGE_LIBJACK - explicit PortID(jack_port_id_t jack_id, bool = false) +#if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) + explicit PortID(uint32_t jack_id, bool = false) : type(Type::jack_id) { id.jack_id = jack_id; @@ -71,8 +71,8 @@ struct PortID union { -#ifdef PATCHAGE_LIBJACK - jack_port_id_t jack_id; +#if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) + uint32_t jack_id; #endif #ifdef HAVE_ALSA struct @@ -118,7 +118,7 @@ operator<(const PortID& a, const PortID& b) case PortID::Type::nothing: return true; case PortID::Type::jack_id: -#ifdef PATCHAGE_LIBJACK +#if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) return a.id.jack_id < b.id.jack_id; #endif break; -- cgit v1.2.1