summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/AlsaDriver.cpp33
-rw-r--r--src/Event.hpp45
-rw-r--r--src/JackLibDriver.cpp28
-rw-r--r--src/event_to_string.cpp16
-rw-r--r--src/handle_event.cpp16
5 files changed, 71 insertions, 67 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp
index fcf5e2e..cea4fa0 100644
--- a/src/AlsaDriver.cpp
+++ b/src/AlsaDriver.cpp
@@ -164,7 +164,7 @@ AlsaDriver::attach(bool /*launch_daemon*/)
_log.error("[ALSA] Unable to attach");
_seq = nullptr;
} else {
- _emit_event(DriverAttachmentEvent{ClientType::alsa});
+ _emit_event(event::DriverAttached{ClientType::alsa});
snd_seq_set_client_name(_seq, "Patchage");
@@ -188,7 +188,7 @@ AlsaDriver::detach()
pthread_join(_refresh_thread, nullptr);
snd_seq_close(_seq);
_seq = nullptr;
- _emit_event(DriverDetachmentEvent{ClientType::alsa});
+ _emit_event(event::DriverDetached{ClientType::alsa});
}
}
@@ -214,8 +214,8 @@ AlsaDriver::refresh(const EventSink& sink)
const auto client_id = snd_seq_client_info_get_client(cinfo);
assert(client_id < std::numeric_limits<uint8_t>::max());
- sink({ClientCreationEvent{ClientID::alsa(static_cast<uint8_t>(client_id)),
- client_info(cinfo)}});
+ sink({event::ClientCreated{ClientID::alsa(static_cast<uint8_t>(client_id)),
+ client_info(cinfo)}});
}
// Emit all ports
@@ -233,12 +233,12 @@ AlsaDriver::refresh(const EventSink& sink)
if (caps & SND_SEQ_PORT_CAP_READ) {
info.direction = SignalDirection::output;
- sink({PortCreationEvent{addr_to_id(addr, false), info}});
+ sink({event::PortCreated{addr_to_id(addr, false), info}});
}
if (caps & SND_SEQ_PORT_CAP_WRITE) {
info.direction = SignalDirection::input;
- sink({PortCreationEvent{addr_to_id(addr, true), info}});
+ sink({event::PortCreated{addr_to_id(addr, true), info}});
}
}
}
@@ -267,7 +267,7 @@ AlsaDriver::refresh(const EventSink& sink)
const auto head_addr = *snd_seq_query_subscribe_get_addr(sinfo);
const auto head_id = addr_to_id(head_addr, true);
- sink({ConnectionEvent{tail_id, head_id}});
+ sink({event::PortsConnected{tail_id, head_id}});
snd_seq_query_subscribe_set_index(
sinfo, snd_seq_query_subscribe_get_index(sinfo) + 1);
@@ -477,14 +477,14 @@ AlsaDriver::_refresh_main()
switch (ev->type) {
case SND_SEQ_EVENT_CLIENT_START:
snd_seq_get_any_client_info(_seq, ev->data.addr.client, cinfo);
- _emit_event(ClientCreationEvent{
+ _emit_event(event::ClientCreated{
ClientID::alsa(ev->data.addr.client),
client_info(cinfo),
});
break;
case SND_SEQ_EVENT_CLIENT_EXIT:
- _emit_event(ClientDestructionEvent{
+ _emit_event(event::ClientDestroyed{
ClientID::alsa(ev->data.addr.client),
});
break;
@@ -499,7 +499,7 @@ AlsaDriver::_refresh_main()
caps = snd_seq_port_info_get_capability(pinfo);
if (!ignore(ev->data.addr)) {
- _emit_event(PortCreationEvent{
+ _emit_event(event::PortCreated{
addr_to_id(ev->data.addr, (caps & SND_SEQ_PORT_CAP_WRITE)),
port_info(pinfo),
});
@@ -510,8 +510,8 @@ AlsaDriver::_refresh_main()
if (!ignore(ev->data.addr, false)) {
// Note: getting caps at this point does not work
// Delete both inputs and outputs (to handle duplex ports)
- _emit_event(PortDestructionEvent{addr_to_id(ev->data.addr, true)});
- _emit_event(PortDestructionEvent{addr_to_id(ev->data.addr, false)});
+ _emit_event(event::PortDestroyed{addr_to_id(ev->data.addr, true)});
+ _emit_event(event::PortDestroyed{addr_to_id(ev->data.addr, false)});
}
break;
@@ -520,16 +520,17 @@ AlsaDriver::_refresh_main()
case SND_SEQ_EVENT_PORT_SUBSCRIBED:
if (!ignore(ev->data.connect.sender) && !ignore(ev->data.connect.dest)) {
- _emit_event(ConnectionEvent{addr_to_id(ev->data.connect.sender, false),
- addr_to_id(ev->data.connect.dest, true)});
+ _emit_event(
+ event::PortsConnected{addr_to_id(ev->data.connect.sender, false),
+ addr_to_id(ev->data.connect.dest, true)});
}
break;
case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
if (!ignore(ev->data.connect.sender) && !ignore(ev->data.connect.dest)) {
_emit_event(
- DisconnectionEvent{addr_to_id(ev->data.connect.sender, false),
- addr_to_id(ev->data.connect.dest, true)});
+ event::PortsDisconnected{addr_to_id(ev->data.connect.sender, false),
+ addr_to_id(ev->data.connect.dest, true)});
}
break;
diff --git a/src/Event.hpp b/src/Event.hpp
index 3cb5bba..46fdb1e 100644
--- a/src/Event.hpp
+++ b/src/Event.hpp
@@ -26,52 +26,55 @@
#include <boost/variant/variant.hpp>
namespace patchage {
+namespace event {
-struct DriverAttachmentEvent {
- ClientType type;
+struct ClientCreated {
+ ClientID id;
+ ClientInfo info;
};
-struct DriverDetachmentEvent {
- ClientType type;
+struct ClientDestroyed {
+ ClientID id;
};
-struct ClientCreationEvent {
- ClientID id;
- ClientInfo info;
+struct DriverAttached {
+ ClientType type;
};
-struct ClientDestructionEvent {
- ClientID id;
+struct DriverDetached {
+ ClientType type;
};
-struct PortCreationEvent {
+struct PortCreated {
PortID id;
PortInfo info;
};
-struct PortDestructionEvent {
+struct PortDestroyed {
PortID id;
};
-struct ConnectionEvent {
+struct PortsConnected {
PortID tail;
PortID head;
};
-struct DisconnectionEvent {
+struct PortsDisconnected {
PortID tail;
PortID head;
};
+} // namespace event
+
/// An event from drivers that is processed by the GUI
-using Event = boost::variant<DriverAttachmentEvent,
- DriverDetachmentEvent,
- ClientCreationEvent,
- ClientDestructionEvent,
- PortCreationEvent,
- PortDestructionEvent,
- ConnectionEvent,
- DisconnectionEvent>;
+using Event = boost::variant<event::ClientCreated,
+ event::ClientDestroyed,
+ event::DriverAttached,
+ event::DriverDetached,
+ event::PortCreated,
+ event::PortDestroyed,
+ event::PortsConnected,
+ event::PortsDisconnected>;
} // namespace patchage
diff --git a/src/JackLibDriver.cpp b/src/JackLibDriver.cpp
index feb8e8c..d0fd88e 100644
--- a/src/JackLibDriver.cpp
+++ b/src/JackLibDriver.cpp
@@ -153,7 +153,7 @@ JackLibDriver::attach(const bool launch_daemon)
_is_activated = true;
_buffer_size = jack_get_buffer_size(_client);
- _emit_event(DriverAttachmentEvent{ClientType::jack});
+ _emit_event(event::DriverAttached{ClientType::jack});
}
void
@@ -168,7 +168,7 @@ JackLibDriver::detach()
}
_is_activated = false;
- _emit_event(DriverDetachmentEvent{ClientType::jack});
+ _emit_event(event::DriverDetached{ClientType::jack});
}
bool
@@ -275,15 +275,15 @@ JackLibDriver::refresh(const EventSink& sink)
// Emit all clients
for (const auto& client_name : client_names) {
- sink({ClientCreationEvent{ClientID::jack(client_name),
- get_client_info(client_name.c_str())}});
+ sink({event::ClientCreated{ClientID::jack(client_name),
+ get_client_info(client_name.c_str())}});
}
// Emit all ports
for (auto i = 0u; ports[i]; ++i) {
const jack_port_t* const port = jack_port_by_name(_client, ports[i]);
- sink({PortCreationEvent{PortID::jack(ports[i]), get_port_info(port)}});
+ sink({event::PortCreated{PortID::jack(ports[i]), get_port_info(port)}});
}
// Get all connections (again to only create them once)
@@ -309,8 +309,8 @@ JackLibDriver::refresh(const EventSink& sink)
// Emit all connections
for (const auto& connection : connections) {
- sink({ConnectionEvent{PortID::jack(connection.first),
- PortID::jack(connection.second)}});
+ sink({event::PortsConnected{PortID::jack(connection.first),
+ PortID::jack(connection.second)}});
}
jack_free(ports);
@@ -414,9 +414,9 @@ JackLibDriver::on_client(const char* const name,
auto* const me = static_cast<JackLibDriver*>(driver);
if (registered) {
- me->_emit_event(ClientCreationEvent{ClientID::jack(name), {name}});
+ me->_emit_event(event::ClientCreated{ClientID::jack(name), {name}});
} else {
- me->_emit_event(ClientDestructionEvent{ClientID::jack(name)});
+ me->_emit_event(event::ClientDestroyed{ClientID::jack(name)});
}
}
@@ -432,9 +432,9 @@ JackLibDriver::on_port(const jack_port_id_t port_id,
const auto id = PortID::jack(name);
if (registered) {
- me->_emit_event(PortCreationEvent{id, me->get_port_info(port)});
+ me->_emit_event(event::PortCreated{id, me->get_port_info(port)});
} else {
- me->_emit_event(PortDestructionEvent{id});
+ me->_emit_event(event::PortDestroyed{id});
}
}
@@ -453,10 +453,10 @@ JackLibDriver::on_connection(const jack_port_id_t src,
if (connect) {
me->_emit_event(
- ConnectionEvent{PortID::jack(src_name), PortID::jack(dst_name)});
+ event::PortsConnected{PortID::jack(src_name), PortID::jack(dst_name)});
} else {
me->_emit_event(
- DisconnectionEvent{PortID::jack(src_name), PortID::jack(dst_name)});
+ event::PortsDisconnected{PortID::jack(src_name), PortID::jack(dst_name)});
}
}
@@ -489,7 +489,7 @@ JackLibDriver::on_shutdown(void* const driver)
me->_client = nullptr;
me->_is_activated = false;
- me->_emit_event(DriverDetachmentEvent{ClientType::jack});
+ me->_emit_event(event::DriverDetached{ClientType::jack});
}
} // namespace
diff --git a/src/event_to_string.cpp b/src/event_to_string.cpp
index 43c4eb6..4b23875 100644
--- a/src/event_to_string.cpp
+++ b/src/event_to_string.cpp
@@ -56,22 +56,22 @@ struct EventPrinter {
PATCHAGE_UNREACHABLE();
}
- std::string operator()(const DriverAttachmentEvent& event)
+ std::string operator()(const event::DriverAttached& event)
{
return fmt::format("Attached to {}", (*this)(event.type));
}
- std::string operator()(const DriverDetachmentEvent& event)
+ std::string operator()(const event::DriverDetached& event)
{
return fmt::format("Detached from {}", (*this)(event.type));
}
- std::string operator()(const ClientCreationEvent& event)
+ std::string operator()(const event::ClientCreated& event)
{
return fmt::format(R"(Add client "{}" ("{}"))", event.id, event.info.label);
}
- std::string operator()(const ClientDestructionEvent& event)
+ std::string operator()(const event::ClientDestroyed& event)
{
return fmt::format(R"(Remove client "{}")", event.id);
}
@@ -108,7 +108,7 @@ struct EventPrinter {
PATCHAGE_UNREACHABLE();
}
- std::string operator()(const PortCreationEvent& event)
+ std::string operator()(const event::PortCreated& event)
{
auto result = fmt::format(R"(Add{} {} {} port "{}" ("{}"))",
event.info.is_terminal ? " terminal" : "",
@@ -124,17 +124,17 @@ struct EventPrinter {
return result;
}
- std::string operator()(const PortDestructionEvent& event)
+ std::string operator()(const event::PortDestroyed& event)
{
return fmt::format(R"("Remove port "{}")", event.id);
}
- std::string operator()(const ConnectionEvent& event)
+ std::string operator()(const event::PortsConnected& event)
{
return fmt::format(R"(Connect "{}" to "{}")", event.tail, event.head);
}
- std::string operator()(const DisconnectionEvent& event)
+ std::string operator()(const event::PortsDisconnected& event)
{
return fmt::format(R"(Disconnect "{}" from "{}")", event.tail, event.head);
}
diff --git a/src/handle_event.cpp b/src/handle_event.cpp
index bbe86fc..fa11ec3 100644
--- a/src/handle_event.cpp
+++ b/src/handle_event.cpp
@@ -48,29 +48,29 @@ public:
: _patchage{patchage}
{}
- void operator()(const DriverAttachmentEvent& event)
+ void operator()(const event::DriverAttached& event)
{
_patchage.driver_attached(event.type);
}
- void operator()(const DriverDetachmentEvent& event)
+ void operator()(const event::DriverDetached& event)
{
_patchage.driver_detached(event.type);
}
- void operator()(const ClientCreationEvent& event)
+ void operator()(const event::ClientCreated& event)
{
// Don't create empty modules, they will be created when ports are added
_patchage.metadata().set_client(event.id, event.info);
}
- void operator()(const ClientDestructionEvent& event)
+ void operator()(const event::ClientDestroyed& event)
{
_patchage.canvas()->remove_module(event.id);
_patchage.metadata().erase_client(event.id);
}
- void operator()(const PortCreationEvent& event)
+ void operator()(const event::PortCreated& event)
{
_patchage.metadata().set_port(event.id, event.info);
@@ -83,13 +83,13 @@ public:
}
}
- void operator()(const PortDestructionEvent& event)
+ void operator()(const event::PortDestroyed& event)
{
_patchage.canvas()->remove_port(event.id);
_patchage.metadata().erase_port(event.id);
}
- void operator()(const ConnectionEvent& event)
+ void operator()(const event::PortsConnected& event)
{
CanvasPort* port_1 = _patchage.canvas()->find_port(event.tail);
CanvasPort* port_2 = _patchage.canvas()->find_port(event.head);
@@ -105,7 +105,7 @@ public:
}
}
- void operator()(const DisconnectionEvent& event)
+ void operator()(const event::PortsDisconnected& event)
{
CanvasPort* port_1 = _patchage.canvas()->find_port(event.tail);
CanvasPort* port_2 = _patchage.canvas()->find_port(event.head);