summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/AlsaDriver.cpp85
-rw-r--r--src/AlsaDriver.hpp16
-rw-r--r--src/Driver.hpp18
-rw-r--r--src/JackDbusDriver.cpp48
-rw-r--r--src/JackDbusDriver.hpp16
-rw-r--r--src/JackDriver.cpp63
-rw-r--r--src/JackDriver.hpp16
-rw-r--r--src/PatchageCanvas.cpp29
-rw-r--r--src/PatchagePort.hpp7
9 files changed, 204 insertions, 94 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp
index dc07d48..65a2a64 100644
--- a/src/AlsaDriver.cpp
+++ b/src/AlsaDriver.cpp
@@ -392,21 +392,23 @@ AlsaDriver::ignore(const snd_seq_addr_t& addr, bool add)
* \return Whether connection succeeded.
*/
bool
-AlsaDriver::connect(PatchagePort* src_port, PatchagePort* dst_port)
+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)
{
- PortAddrs::const_iterator s = _port_addrs.find(src_port);
- PortAddrs::const_iterator d = _port_addrs.find(dst_port);
-
- if (s == _port_addrs.end() || d == _port_addrs.end()) {
- _log.error("[ALSA] Attempt to connect port with no address");
+ if (tail_id.type != PortID::Type::alsa_addr ||
+ head_id.type != PortID::Type::alsa_addr) {
+ _log.error("[ALSA] Attempt to connect non-ALSA ports");
return false;
}
- const PortID src = s->second;
- const PortID dst = d->second;
-
- if (src.id.alsa_addr.client == dst.id.alsa_addr.client &&
- src.id.alsa_addr.port == dst.id.alsa_addr.port) {
+ const auto& tail_addr = tail_id.id.alsa_addr;
+ const auto& head_addr = head_id.id.alsa_addr;
+ if (tail_addr.client == head_addr.client &&
+ tail_addr.port == head_addr.port) {
_log.warning("[ALSA] Refusing to connect port to itself");
return false;
}
@@ -415,8 +417,8 @@ AlsaDriver::connect(PatchagePort* src_port, PatchagePort* dst_port)
snd_seq_port_subscribe_t* subs = nullptr;
snd_seq_port_subscribe_malloc(&subs);
- snd_seq_port_subscribe_set_sender(subs, &src.id.alsa_addr);
- snd_seq_port_subscribe_set_dest(subs, &dst.id.alsa_addr);
+ snd_seq_port_subscribe_set_sender(subs, &tail_addr);
+ snd_seq_port_subscribe_set_dest(subs, &head_addr);
snd_seq_port_subscribe_set_exclusive(subs, 0);
snd_seq_port_subscribe_set_time_update(subs, 0);
snd_seq_port_subscribe_set_time_real(subs, 0);
@@ -435,13 +437,17 @@ AlsaDriver::connect(PatchagePort* src_port, PatchagePort* dst_port)
}
if (result) {
- _log.info(fmt::format("[ALSA] Connected {} => {}",
- src_port->full_name(),
- dst_port->full_name()));
+ _log.info(fmt::format("[ALSA] Connected {}:{} => {}:{}",
+ tail_client_name,
+ tail_port_name,
+ head_client_name,
+ head_port_name));
} else {
- _log.error(fmt::format("[ALSA] Unable to connect {} => {}",
- src_port->full_name(),
- dst_port->full_name()));
+ _log.error(fmt::format("[ALSA] Failed to connect {}:{} => {}:{}",
+ tail_client_name,
+ tail_port_name,
+ head_client_name,
+ head_port_name));
}
return (!result);
@@ -452,23 +458,26 @@ AlsaDriver::connect(PatchagePort* src_port, PatchagePort* dst_port)
* \return Whether disconnection succeeded.
*/
bool
-AlsaDriver::disconnect(PatchagePort* src_port, PatchagePort* dst_port)
+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)
{
- PortAddrs::const_iterator s = _port_addrs.find(src_port);
- PortAddrs::const_iterator d = _port_addrs.find(dst_port);
-
- if (s == _port_addrs.end() || d == _port_addrs.end()) {
- _log.error("[ALSA] Attempt to connect port with no address");
+ if (tail_id.type != PortID::Type::alsa_addr ||
+ head_id.type != PortID::Type::alsa_addr) {
+ _log.error("[ALSA] Attempt to disconnect non-ALSA ports");
return false;
}
- const PortID src = s->second;
- const PortID dst = d->second;
+ const auto& tail_addr = tail_id.id.alsa_addr;
+ const auto& head_addr = head_id.id.alsa_addr;
snd_seq_port_subscribe_t* subs = nullptr;
snd_seq_port_subscribe_malloc(&subs);
- snd_seq_port_subscribe_set_sender(subs, &src.id.alsa_addr);
- snd_seq_port_subscribe_set_dest(subs, &dst.id.alsa_addr);
+ snd_seq_port_subscribe_set_sender(subs, &tail_addr);
+ snd_seq_port_subscribe_set_dest(subs, &head_addr);
snd_seq_port_subscribe_set_exclusive(subs, 0);
snd_seq_port_subscribe_set_time_update(subs, 0);
snd_seq_port_subscribe_set_time_real(subs, 0);
@@ -482,15 +491,21 @@ AlsaDriver::disconnect(PatchagePort* src_port, PatchagePort* dst_port)
int ret = snd_seq_unsubscribe_port(_seq, subs);
if (ret < 0) {
- _log.error(fmt::format("[ALSA] Unable to disconnect {} => {} ({})",
- src_port->full_name(),
- dst_port->full_name(),
- snd_strerror(ret)));
+ _log.error(
+ fmt::format("[ALSA] Failed to disconnect {}:{} => {}:{} ({})",
+ tail_client_name,
+ tail_port_name,
+ head_client_name,
+ head_port_name,
+ snd_strerror(ret)));
return false;
}
- _log.info(std::string("[ALSA] Disconnected ") + src_port->full_name() +
- " => " + dst_port->full_name());
+ _log.info(fmt::format("[ALSA] Disconnected {}:{} => {}:{}",
+ tail_client_name,
+ tail_port_name,
+ head_client_name,
+ head_port_name));
return true;
}
diff --git a/src/AlsaDriver.hpp b/src/AlsaDriver.hpp
index a953b7b..49acf51 100644
--- a/src/AlsaDriver.hpp
+++ b/src/AlsaDriver.hpp
@@ -59,9 +59,19 @@ public:
PatchagePort*
create_port_view(Patchage* patchage, const PortID& id) override;
- bool connect(PatchagePort* src_port, PatchagePort* dst_port) override;
-
- bool disconnect(PatchagePort* src_port, PatchagePort* dst_port) 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;
void print_addr(snd_seq_addr_t addr);
diff --git a/src/Driver.hpp b/src/Driver.hpp
index b0373af..1144df5 100644
--- a/src/Driver.hpp
+++ b/src/Driver.hpp
@@ -21,6 +21,8 @@
#include <sigc++/sigc++.h>
+#include <string>
+
class PatchagePort;
class PatchageCanvas;
@@ -50,9 +52,19 @@ public:
virtual PatchagePort*
create_port_view(Patchage* patchage, const PortID& id) = 0;
- virtual bool connect(PatchagePort* src_port, PatchagePort* dst_port) = 0;
-
- virtual bool disconnect(PatchagePort* src_port, PatchagePort* dst_port) = 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;
sigc::signal<void> signal_attached;
sigc::signal<void> signal_detached;
diff --git a/src/JackDbusDriver.cpp b/src/JackDbusDriver.cpp
index b2acc69..fbd8bf4 100644
--- a/src/JackDbusDriver.cpp
+++ b/src/JackDbusDriver.cpp
@@ -913,26 +913,30 @@ JackDriver::refresh()
}
bool
-JackDriver::connect(PatchagePort* src, PatchagePort* dst)
+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)
{
- const char* client1_name = src->get_module()->get_label();
- const char* port1_name = src->get_label();
- const char* client2_name = dst->get_module()->get_label();
- const char* port2_name = dst->get_label();
- DBusMessage* reply_ptr = nullptr;
+ (void)tail_id;
+ (void)head_id;
+
+ DBusMessage* reply_ptr = nullptr;
if (!call(true,
JACKDBUS_IFACE_PATCHBAY,
"ConnectPortsByName",
&reply_ptr,
DBUS_TYPE_STRING,
- &client1_name,
+ &tail_client_name,
DBUS_TYPE_STRING,
- &port1_name,
+ &tail_port_name,
DBUS_TYPE_STRING,
- &client2_name,
+ &head_client_name,
DBUS_TYPE_STRING,
- &port2_name,
+ &head_port_name,
DBUS_TYPE_INVALID)) {
error_msg("ConnectPortsByName() failed");
return false;
@@ -942,26 +946,30 @@ JackDriver::connect(PatchagePort* src, PatchagePort* dst)
}
bool
-JackDriver::disconnect(PatchagePort* src, PatchagePort* dst)
+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)
{
- const char* client1_name = src->get_module()->get_label();
- const char* port1_name = src->get_label();
- const char* client2_name = dst->get_module()->get_label();
- const char* port2_name = dst->get_label();
- DBusMessage* reply_ptr = nullptr;
+ (void)tail_id;
+ (void)head_id;
+
+ DBusMessage* reply_ptr = nullptr;
if (!call(true,
JACKDBUS_IFACE_PATCHBAY,
"DisconnectPortsByName",
&reply_ptr,
DBUS_TYPE_STRING,
- &client1_name,
+ &tail_client_name,
DBUS_TYPE_STRING,
- &port1_name,
+ &tail_port_name,
DBUS_TYPE_STRING,
- &client2_name,
+ &head_client_name,
DBUS_TYPE_STRING,
- &port2_name,
+ &head_port_name,
DBUS_TYPE_INVALID)) {
error_msg("DisconnectPortsByName() failed");
return false;
diff --git a/src/JackDbusDriver.hpp b/src/JackDbusDriver.hpp
index 5b443b0..1ba581c 100644
--- a/src/JackDbusDriver.hpp
+++ b/src/JackDbusDriver.hpp
@@ -56,9 +56,19 @@ public:
void refresh() override;
void destroy_all() override;
- bool connect(PatchagePort* src, PatchagePort* dst) override;
-
- bool disconnect(PatchagePort* src, PatchagePort* dst) 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;
uint32_t get_xruns();
void reset_xruns();
diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp
index 5c08144..b3f4be0 100644
--- a/src/JackDriver.cpp
+++ b/src/JackDriver.cpp
@@ -429,26 +429,35 @@ JackDriver::port_names(const PortID& id,
* \return Whether connection succeeded.
*/
bool
-JackDriver::connect(PatchagePort* src_port, PatchagePort* dst_port)
+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)
{
- if (_client == nullptr) {
+ (void)tail_id;
+ (void)head_id;
+
+ if (!_client) {
return false;
}
- int result = jack_connect(
- _client, src_port->full_name().c_str(), dst_port->full_name().c_str());
+ const auto tail_name = tail_client_name + ":" + tail_port_name;
+ const auto head_name = head_client_name + ":" + head_port_name;
+
+ const int result =
+ jack_connect(_client, tail_name.c_str(), head_name.c_str());
if (result == 0) {
- _log.info(fmt::format("[JACK] Connected {} => {}",
- src_port->full_name(),
- dst_port->full_name()));
+ _log.info(
+ fmt::format("[JACK] Connected {} => {}", tail_name, head_name));
} else {
- _log.error(fmt::format("[JACK] Unable to connect {} => {}",
- src_port->full_name(),
- dst_port->full_name()));
+ _log.error(fmt::format(
+ "[JACK] Failed to connect {} => {}", tail_name, head_name));
}
- return (!result);
+ return !result;
}
/** Disconnects two Jack audio ports.
@@ -456,27 +465,35 @@ JackDriver::connect(PatchagePort* src_port, PatchagePort* dst_port)
* \return Whether disconnection succeeded.
*/
bool
-JackDriver::disconnect(PatchagePort* const src_port,
- PatchagePort* const dst_port)
+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)
{
- if (_client == nullptr) {
+ (void)tail_id;
+ (void)head_id;
+
+ if (!_client) {
return false;
}
- int result = jack_disconnect(
- _client, src_port->full_name().c_str(), dst_port->full_name().c_str());
+ const auto tail_name = tail_client_name + ":" + tail_port_name;
+ const auto head_name = head_client_name + ":" + head_port_name;
+
+ const int result =
+ jack_disconnect(_client, tail_name.c_str(), head_name.c_str());
if (result == 0) {
- _log.info(fmt::format("[JACK] Disconnected {} => {}",
- src_port->full_name(),
- dst_port->full_name()));
+ _log.info(
+ fmt::format("[JACK] Disconnected {} => {}", tail_name, head_name));
} else {
- _log.error(fmt::format("[JACK] Unable to disconnect {} => {}",
- src_port->full_name(),
- dst_port->full_name()));
+ _log.error(fmt::format(
+ "[JACK] Failed to disconnect {} => {}", tail_name, head_name));
}
- return (!result);
+ return !result;
}
void
diff --git a/src/JackDriver.hpp b/src/JackDriver.hpp
index 0875703..ede1c9d 100644
--- a/src/JackDriver.hpp
+++ b/src/JackDriver.hpp
@@ -68,9 +68,19 @@ public:
PatchagePort*
create_port_view(Patchage* patchage, const PortID& id) override;
- bool connect(PatchagePort* src, PatchagePort* dst) override;
-
- bool disconnect(PatchagePort* src, PatchagePort* dst) 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;
uint32_t get_xruns() { return _xruns; }
void reset_xruns();
diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp
index fb48bff..16a85ef 100644
--- a/src/PatchageCanvas.cpp
+++ b/src/PatchageCanvas.cpp
@@ -238,12 +238,22 @@ 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, p2);
+ _app->jack_driver()->connect(p1->id(),
+ p1->module_name(),
+ p1->name(),
+ p2->id(),
+ p2->module_name(),
+ p2->name());
#endif
#ifdef HAVE_ALSA
} else if (p1->type() == PortType::alsa_midi &&
p2->type() == PortType::alsa_midi) {
- _app->alsa_driver()->connect(p1, p2);
+ _app->alsa_driver()->connect(p1->id(),
+ p1->module_name(),
+ p1->name(),
+ p2->id(),
+ p2->module_name(),
+ p2->name());
#endif
} else {
_app->log().warning("Cannot make connection, incompatible port types");
@@ -276,11 +286,22 @@ 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, input);
+ _app->jack_driver()->disconnect(output->id(),
+ output->module_name(),
+ output->name(),
+ input->id(),
+ input->module_name(),
+ input->name());
+
#endif
#ifdef HAVE_ALSA
} else if (input->type() == PortType::alsa_midi) {
- _app->alsa_driver()->disconnect(output, input);
+ _app->alsa_driver()->disconnect(output->id(),
+ output->module_name(),
+ output->name(),
+ input->id(),
+ input->module_name(),
+ input->name());
#endif
} else {
_app->log().error("Attempt to disconnect ports with strange types");
diff --git a/src/PatchagePort.hpp b/src/PatchagePort.hpp
index 8a96f20..03a6f83 100644
--- a/src/PatchagePort.hpp
+++ b/src/PatchagePort.hpp
@@ -70,6 +70,13 @@ public:
~PatchagePort() override = default;
+ /** Returns the name of the module/client this port is one */
+ std::string module_name() const
+ {
+ auto* pmod = dynamic_cast<PatchageModule*>(get_module());
+ return std::string(pmod->name());
+ }
+
/** Returns the full name of this port, as "modulename:portname" */
std::string full_name() const
{