summaryrefslogtreecommitdiffstats
path: root/src/libs/engine/EventSink.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/engine/EventSink.cpp')
-rw-r--r--src/libs/engine/EventSink.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/libs/engine/EventSink.cpp b/src/libs/engine/EventSink.cpp
index 441e7aac..7fc7b157 100644
--- a/src/libs/engine/EventSink.cpp
+++ b/src/libs/engine/EventSink.cpp
@@ -24,7 +24,7 @@ using namespace std;
namespace Ingen {
-
+#if 0
void
EventSink::control_change(Port* port, FrameTime time, float val)
{
@@ -32,12 +32,42 @@ EventSink::control_change(Port* port, FrameTime time, float val)
SendPortValueEvent ev(_engine, time, port, false, 0, val);
_events.write(sizeof(ev), (uchar*)&ev);
}
-
+#endif
+
+/** \a size is not size_t because an event will never be even remotely close
+ * to UINT32_MAX in size, so uint32_t saves wasted space on 64-bit.
+ */
+bool
+EventSink::write(uint32_t size, const Event* ev)
+{
+ if (size > _events.write_space())
+ return false;
+ _events.write(sizeof(uint32_t), (uint8_t*)&size);
+ _events.write(size, (uint8_t*)ev);
+
+ return true;
+}
+
+
+/** Read the next event into event_buffer.
+ *
+ * \a event_buffer can be casted to Event* and virtual methods called.
+ */
bool
-EventSink::read_control_change(SendPortValueEvent& ev)
+EventSink::read(uint32_t event_buffer_size, uint8_t* event_buffer)
{
- return _events.full_read(sizeof(SendPortValueEvent), (uchar*)&ev);
+ uint32_t read_size;
+ bool success = _events.full_read(sizeof(uint32_t), (uint8_t*)&read_size);
+ if (!success)
+ return false;
+
+ assert(read_size <= event_buffer_size);
+
+ if (read_size > 0)
+ return _events.full_read(read_size, event_buffer);
+ else
+ return false;
}