summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-28 12:02:55 +0100
committerDavid Robillard <d@drobilla.net>2020-11-28 12:45:57 +0100
commit0ae4276ac187a9a361950f26bd67eb2d54636aff (patch)
treecc46c2ff5df75d426de5e80b891042ae1ebb7bf3
parent4ac8e622bb4ef5841435fc0815efb6bb756f76da (diff)
downloadpatchage-0ae4276ac187a9a361950f26bd67eb2d54636aff.tar.gz
patchage-0ae4276ac187a9a361950f26bd67eb2d54636aff.tar.bz2
patchage-0ae4276ac187a9a361950f26bd67eb2d54636aff.zip
Simplify driver connection interface
-rw-r--r--src/AlsaDriver.cpp45
-rw-r--r--src/AlsaDriver.hpp15
-rw-r--r--src/Driver.hpp15
-rw-r--r--src/JackDbusDriver.cpp33
-rw-r--r--src/JackDbusDriver.hpp15
-rw-r--r--src/JackDriver.cpp37
-rw-r--r--src/JackDriver.hpp15
-rw-r--r--src/PatchageCanvas.cpp28
-rw-r--r--src/PortID.hpp1
-rw-r--r--src/PortNames.hpp44
10 files changed, 91 insertions, 157 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp
index b8dcdc6..a132d54 100644
--- a/src/AlsaDriver.cpp
+++ b/src/AlsaDriver.cpp
@@ -24,6 +24,7 @@
PATCHAGE_DISABLE_FMT_WARNINGS
#include <fmt/core.h>
+#include <fmt/ostream.h>
PATCHAGE_RESTORE_WARNINGS
#include <cassert>
@@ -406,12 +407,7 @@ AlsaDriver::ignore(const snd_seq_addr_t& addr, bool add)
* \return Whether connection succeeded.
*/
bool
-AlsaDriver::connect(const PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- const PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name)
+AlsaDriver::connect(const PortID tail_id, const PortID head_id)
{
if (tail_id.type() != PortID::Type::alsa ||
head_id.type() != PortID::Type::alsa) {
@@ -455,17 +451,10 @@ AlsaDriver::connect(const PortID tail_id,
}
if (result) {
- _log.info(fmt::format("[ALSA] Connected {}:{} => {}:{}",
- tail_client_name,
- tail_port_name,
- head_client_name,
- head_port_name));
+ _log.info(fmt::format("[ALSA] Connected {} => {}", tail_id, head_id));
} else {
- _log.error(fmt::format("[ALSA] Failed to connect {}:{} => {}:{}",
- tail_client_name,
- tail_port_name,
- head_client_name,
- head_port_name));
+ _log.error(
+ fmt::format("[ALSA] Failed to connect {} => {}", tail_id, head_id));
}
return (!result);
@@ -476,12 +465,7 @@ AlsaDriver::connect(const PortID tail_id,
* \return Whether disconnection succeeded.
*/
bool
-AlsaDriver::disconnect(const PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- const PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name)
+AlsaDriver::disconnect(const PortID tail_id, const PortID head_id)
{
if (tail_id.type() != PortID::Type::alsa ||
head_id.type() != PortID::Type::alsa) {
@@ -512,21 +496,14 @@ AlsaDriver::disconnect(const PortID tail_id,
int ret = snd_seq_unsubscribe_port(_seq, subs);
if (ret < 0) {
- _log.error(
- fmt::format("[ALSA] Failed to disconnect {}:{} => {}:{} ({})",
- tail_client_name,
- tail_port_name,
- head_client_name,
- head_port_name,
- snd_strerror(ret)));
+ _log.error(fmt::format("[ALSA] Failed to disconnect {} => {} ({})",
+ tail_id,
+ head_id,
+ snd_strerror(ret)));
return false;
}
- _log.info(fmt::format("[ALSA] Disconnected {}:{} => {}:{}",
- tail_client_name,
- tail_port_name,
- head_client_name,
- head_port_name));
+ _log.info(fmt::format("[ALSA] Disconnected {} => {}", tail_id, head_id));
return true;
}
diff --git a/src/AlsaDriver.hpp b/src/AlsaDriver.hpp
index 49acf51..2680509 100644
--- a/src/AlsaDriver.hpp
+++ b/src/AlsaDriver.hpp
@@ -59,19 +59,8 @@ public:
PatchagePort*
create_port_view(Patchage* patchage, const PortID& id) override;
- bool connect(PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name) override;
-
- bool disconnect(PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name) override;
+ bool connect(PortID tail_id, PortID head_id) override;
+ bool disconnect(PortID tail_id, PortID head_id) override;
void print_addr(snd_seq_addr_t addr);
diff --git a/src/Driver.hpp b/src/Driver.hpp
index 1144df5..5a9883c 100644
--- a/src/Driver.hpp
+++ b/src/Driver.hpp
@@ -52,19 +52,8 @@ public:
virtual PatchagePort*
create_port_view(Patchage* patchage, const PortID& id) = 0;
- virtual bool connect(PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name) = 0;
-
- virtual bool disconnect(PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name) = 0;
+ virtual bool connect(PortID tail_id, PortID head_id) = 0;
+ virtual bool disconnect(PortID tail_id, PortID head_id) = 0;
sigc::signal<void> signal_attached;
sigc::signal<void> signal_detached;
diff --git a/src/JackDbusDriver.cpp b/src/JackDbusDriver.cpp
index 7d3a532..855acf8 100644
--- a/src/JackDbusDriver.cpp
+++ b/src/JackDbusDriver.cpp
@@ -24,6 +24,7 @@
#include "PatchageCanvas.hpp"
#include "PatchageEvent.hpp"
#include "PatchageModule.hpp"
+#include "PortNames.hpp"
PATCHAGE_DISABLE_FMT_WARNINGS
#include <fmt/core.h>
@@ -620,7 +621,7 @@ JackDriver::add_port(PatchageModule* module,
void
JackDriver::add_port(dbus_uint64_t /*client_id*/,
- const char* client_name,
+ const char* client_name,
dbus_uint64_t /*port_id*/,
const char* port_name,
dbus_uint32_t port_flags,
@@ -925,15 +926,14 @@ JackDriver::refresh()
}
bool
-JackDriver::connect(const PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- const PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name)
+JackDriver::connect(const PortID tail_id, const PortID head_id)
{
- (void)tail_id;
- (void)head_id;
+ const auto tail_names = PortNames(tail_id);
+ const auto head_names = PortNames(head_id);
+ const char* const tail_client_name = tail_names.client().c_str();
+ const char* const tail_port_name = tail_names.port().c_str();
+ const char* const head_client_name = head_names.client().c_str();
+ const char* const head_port_name = head_names.port().c_str();
DBusMessage* reply_ptr = nullptr;
@@ -958,15 +958,14 @@ JackDriver::connect(const PortID tail_id,
}
bool
-JackDriver::disconnect(const PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- const PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name)
+JackDriver::disconnect(const PortID tail_id, const PortID head_id)
{
- (void)tail_id;
- (void)head_id;
+ const auto tail_names = PortNames(tail_id);
+ const auto head_names = PortNames(head_id);
+ const char* const tail_client_name = tail_names.client().c_str();
+ const char* const tail_port_name = tail_names.port().c_str();
+ const char* const head_client_name = head_names.client().c_str();
+ const char* const head_port_name = head_names.port().c_str();
DBusMessage* reply_ptr = nullptr;
diff --git a/src/JackDbusDriver.hpp b/src/JackDbusDriver.hpp
index 1ba581c..ac1137d 100644
--- a/src/JackDbusDriver.hpp
+++ b/src/JackDbusDriver.hpp
@@ -56,19 +56,8 @@ public:
void refresh() override;
void destroy_all() override;
- bool connect(PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name) override;
-
- bool disconnect(PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name) override;
+ bool connect(PortID tail_id, PortID head_id) override;
+ bool disconnect(PortID tail_id, PortID head_id) override;
uint32_t get_xruns();
void reset_xruns();
diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp
index e0b01ff..8127f42 100644
--- a/src/JackDriver.cpp
+++ b/src/JackDriver.cpp
@@ -22,6 +22,7 @@
#include "PatchageCanvas.hpp"
#include "PatchageEvent.hpp"
#include "PatchageModule.hpp"
+#include "PortNames.hpp"
#include "patchage_config.h"
#ifdef HAVE_JACK_METADATA
@@ -425,27 +426,15 @@ JackDriver::port_names(const PortID& id,
return true;
}
-/** Connects two Jack audio ports.
- * To be called from GTK thread only.
- * \return Whether connection succeeded.
- */
bool
-JackDriver::connect(const PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- const PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name)
+JackDriver::connect(const PortID tail_id, const PortID head_id)
{
- (void)tail_id;
- (void)head_id;
-
if (!_client) {
return false;
}
- const auto tail_name = tail_client_name + ":" + tail_port_name;
- const auto head_name = head_client_name + ":" + head_port_name;
+ const auto& tail_name = tail_id.jack_name();
+ const auto& head_name = head_id.jack_name();
const int result =
jack_connect(_client, tail_name.c_str(), head_name.c_str());
@@ -461,27 +450,15 @@ JackDriver::connect(const PortID tail_id,
return !result;
}
-/** Disconnects two Jack audio ports.
- * To be called from GTK thread only.
- * \return Whether disconnection succeeded.
- */
bool
-JackDriver::disconnect(const PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- const PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name)
+JackDriver::disconnect(const PortID tail_id, const PortID head_id)
{
- (void)tail_id;
- (void)head_id;
-
if (!_client) {
return false;
}
- const auto tail_name = tail_client_name + ":" + tail_port_name;
- const auto head_name = head_client_name + ":" + head_port_name;
+ const auto& tail_name = tail_id.jack_name();
+ const auto& head_name = head_id.jack_name();
const int result =
jack_disconnect(_client, tail_name.c_str(), head_name.c_str());
diff --git a/src/JackDriver.hpp b/src/JackDriver.hpp
index abf9008..7500f6e 100644
--- a/src/JackDriver.hpp
+++ b/src/JackDriver.hpp
@@ -68,19 +68,8 @@ public:
PatchagePort*
create_port_view(Patchage* patchage, const PortID& id) override;
- bool connect(PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name) override;
-
- bool disconnect(PortID tail_id,
- const std::string& tail_client_name,
- const std::string& tail_port_name,
- PortID head_id,
- const std::string& head_client_name,
- const std::string& head_port_name) override;
+ bool connect(PortID tail_id, PortID head_id) override;
+ bool disconnect(PortID tail_id, PortID head_id) override;
uint32_t get_xruns() const { return _xruns; }
void reset_xruns();
diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp
index 1433244..6bae432 100644
--- a/src/PatchageCanvas.cpp
+++ b/src/PatchageCanvas.cpp
@@ -207,22 +207,12 @@ PatchageCanvas::connect(Ganv::Node* port1, Ganv::Node* port2)
(p1->type() == PortType::jack_osc &&
p2->type() == PortType::jack_osc)) {
#if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS)
- _app->jack_driver()->connect(p1->id(),
- p1->module_name(),
- p1->name(),
- p2->id(),
- p2->module_name(),
- p2->name());
+ _app->jack_driver()->connect(p1->id(), p2->id());
#endif
#ifdef HAVE_ALSA
} else if (p1->type() == PortType::alsa_midi &&
p2->type() == PortType::alsa_midi) {
- _app->alsa_driver()->connect(p1->id(),
- p1->module_name(),
- p1->name(),
- p2->id(),
- p2->module_name(),
- p2->name());
+ _app->alsa_driver()->connect(p1->id(), p2->id());
#endif
} else {
_app->log().warning("Cannot make connection, incompatible port types");
@@ -255,22 +245,12 @@ PatchageCanvas::disconnect(Ganv::Node* port1, Ganv::Node* port2)
input->type() == PortType::jack_cv ||
input->type() == PortType::jack_osc) {
#if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS)
- _app->jack_driver()->disconnect(output->id(),
- output->module_name(),
- output->name(),
- input->id(),
- input->module_name(),
- input->name());
+ _app->jack_driver()->disconnect(output->id(), input->id());
#endif
#ifdef HAVE_ALSA
} else if (input->type() == PortType::alsa_midi) {
- _app->alsa_driver()->disconnect(output->id(),
- output->module_name(),
- output->name(),
- input->id(),
- input->module_name(),
- input->name());
+ _app->alsa_driver()->disconnect(output->id(), input->id());
#endif
} else {
_app->log().error("Attempt to disconnect ports with strange types");
diff --git a/src/PortID.hpp b/src/PortID.hpp
index 2a53881..efdd78d 100644
--- a/src/PortID.hpp
+++ b/src/PortID.hpp
@@ -70,6 +70,7 @@ private:
, _jack_name{std::move(jack_name)}
{
assert(_type == Type::jack);
+ assert(_jack_name.find(':') != std::string::npos);
}
PortID(const Type type,
diff --git a/src/PortNames.hpp b/src/PortNames.hpp
new file mode 100644
index 0000000..e976e34
--- /dev/null
+++ b/src/PortNames.hpp
@@ -0,0 +1,44 @@
+/* This file is part of Patchage.
+ * Copyright 2008-2020 David Robillard <d@drobilla.net>
+ *
+ * Patchage is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * Patchage is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Patchage. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PATCHAGE_PORTNAMES_HPP
+#define PATCHAGE_PORTNAMES_HPP
+
+#include <cassert>
+#include <string>
+
+/// Utility class that splits a Jack port ID into client and client names
+class PortNames
+{
+public:
+ explicit PortNames(const PortID& id)
+ {
+ assert(id.type() == PortID::Type::jack);
+
+ const auto colon = id.jack_name().find(':');
+ _client_name = id.jack_name().substr(0, colon);
+ _port_name = id.jack_name().substr(colon + 1);
+ }
+
+ const std::string& client() const { return _client_name; }
+ const std::string& port() const { return _port_name; }
+
+private:
+ std::string _client_name;
+ std::string _port_name;
+};
+
+#endif // PATCHAGE_PORTNAMES_HPP