summaryrefslogtreecommitdiffstats
path: root/src/PatchageEvent.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-28 14:54:25 +0100
committerDavid Robillard <d@drobilla.net>2020-11-28 14:54:25 +0100
commite3f3f3586411136e5b7f61cc1726bbc0635deddd (patch)
tree3c75bfc269d665f4d4e8247a30a5c0cee277d58a /src/PatchageEvent.hpp
parent445702fdd90f83abfb1ea7bcdbb1d3605c2236c3 (diff)
downloadpatchage-e3f3f3586411136e5b7f61cc1726bbc0635deddd.tar.gz
patchage-e3f3f3586411136e5b7f61cc1726bbc0635deddd.tar.bz2
patchage-e3f3f3586411136e5b7f61cc1726bbc0635deddd.zip
Make PatchageEvent a variant
Diffstat (limited to 'src/PatchageEvent.hpp')
-rw-r--r--src/PatchageEvent.hpp85
1 files changed, 44 insertions, 41 deletions
diff --git a/src/PatchageEvent.hpp b/src/PatchageEvent.hpp
index dca4dbd..b4aa640 100644
--- a/src/PatchageEvent.hpp
+++ b/src/PatchageEvent.hpp
@@ -17,59 +17,62 @@
#ifndef PATCHAGE_PATCHAGEEVENT_HPP
#define PATCHAGE_PATCHAGEEVENT_HPP
-#include "patchage_config.h"
-
#include "PatchagePort.hpp"
#include "PortID.hpp"
-#include <cstring>
+#include <boost/variant/variant.hpp>
+
+#include <string>
+#include <utility>
class Patchage;
-/// An event from drivers that is processed by the GUI
-class PatchageEvent
-{
-public:
- enum class Type : uint8_t
- {
- noop,
- refresh,
- client_creation,
- client_destruction,
- port_creation,
- port_destruction,
- connection,
- disconnection,
- };
+struct NoopEvent
+{};
- PatchageEvent(Type type, const char* str)
- : _str(g_strdup(str))
- , _port_1(PortID::nothing())
- , _port_2(PortID::nothing())
- , _type(type)
- {}
+struct ClientCreationEvent
+{
+ std::string name;
+};
- PatchageEvent(Type type, PortID port)
- : _port_1(std::move(port))
- , _port_2(PortID::nothing())
- , _type(type)
- {}
+struct ClientDestructionEvent
+{
+ std::string name;
+};
- PatchageEvent(Type type, PortID tail, PortID head)
- : _port_1(std::move(tail))
- , _port_2(std::move(head))
- , _type(type)
- {}
+struct PortCreationEvent
+{
+ PortID id;
+};
- void execute(Patchage* patchage);
+struct PortDestructionEvent
+{
+ PortID id;
+};
- inline Type type() const { return _type; }
+struct ConnectionEvent
+{
+ PortID tail;
+ PortID head;
+};
-private:
- char* _str{nullptr};
- PortID _port_1;
- PortID _port_2;
- Type _type;
+struct DisconnectionEvent
+{
+ PortID tail;
+ PortID head;
};
+/// An event from drivers that is processed by the GUI
+using PatchageEvent = boost::variant<NoopEvent,
+ ClientCreationEvent,
+ ClientDestructionEvent,
+ PortCreationEvent,
+ PortDestructionEvent,
+ ConnectionEvent,
+ DisconnectionEvent>;
+
+/// Handle an event in the GUI
+void
+handle_event(Patchage& patchage, const PatchageEvent& event);
+
#endif // PATCHAGE_PATCHAGEEVENT_HPP