Add a way to retrieve clap_event_header_t*s

This sets the correct pointer in the SysEx events just before returning
them.
This commit is contained in:
Robbert van der Helm
2022-10-01 15:57:06 +02:00
parent 72e2a9c9f7
commit 7e5bc6b07b
2 changed files with 42 additions and 13 deletions
+22
View File
@@ -16,6 +16,8 @@
#include "events.h"
#include "../../utils.h"
namespace clap {
namespace events {
@@ -106,5 +108,25 @@ std::optional<Event> Event::parse(const clap_event_header_t& generic_event) {
}
}
const clap_event_header_t* Event::get() const {
return std::visit(
overload{[](payload::MidiSysex& event) -> const clap_event_header_t* {
// These events contain heap data pointers. We store this
// data using an `std::string` alongside the event struct,
// but we can only set the pointer here just before
// returning the event in case it was moved inbetween
// deserialization and this function being called.
event.event.buffer =
reinterpret_cast<const uint8_t*>(event.buffer.data());
event.event.size = event.buffer.size();
return &event.event.header;
},
[](const auto& event) -> const clap_event_header_t* {
return &event.event.header;
}},
payload);
}
} // namespace events
} // namespace clap
+20 -13
View File
@@ -238,6 +238,12 @@ struct alignas(16) Event {
*/
static std::optional<Event> parse(const clap_event_header_t& generic_event);
/**
* Get the `clap_event_header_t*` representation for this event. The pointer
* is valid as long as this struct isn't moved.
*/
const clap_event_header_t* get() const;
/**
* The actual event data. These also contain the header because storing the
* entire `clap_event_*_t` struct is the only way to serialize the event
@@ -247,19 +253,20 @@ struct alignas(16) Event {
* `clap_input_events::get()`, but that would cause unexpected lifetime
* issues.
*/
std::variant<payload::Note,
payload::NoteExpression,
payload::ParamValue,
payload::ParamMod,
payload::ParamGesture,
// Most events are about the same length, but having the
// transport in here sadly doubles this struct's size
// TODO: Pack the events at some point, this will require
// special handling for SysEx events
payload::Transport,
payload::Midi,
payload::MidiSysex,
payload::Midi2>
mutable std::variant<
payload::Note,
payload::NoteExpression,
payload::ParamValue,
payload::ParamMod,
payload::ParamGesture,
// Most events are about the same length, but having the transport in
// here sadly doubles this struct's size
// TODO: Pack the events at some point, this will require special
// handling for SysEx events
payload::Transport,
payload::Midi,
payload::MidiSysex,
payload::Midi2>
payload;
template <typename S>