mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
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:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
|
|
||||||
|
#include "../../utils.h"
|
||||||
|
|
||||||
namespace clap {
|
namespace clap {
|
||||||
namespace events {
|
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 events
|
||||||
} // namespace clap
|
} // namespace clap
|
||||||
|
|||||||
@@ -238,6 +238,12 @@ struct alignas(16) Event {
|
|||||||
*/
|
*/
|
||||||
static std::optional<Event> parse(const clap_event_header_t& generic_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
|
* 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
|
* 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
|
* `clap_input_events::get()`, but that would cause unexpected lifetime
|
||||||
* issues.
|
* issues.
|
||||||
*/
|
*/
|
||||||
std::variant<payload::Note,
|
mutable std::variant<
|
||||||
payload::NoteExpression,
|
payload::Note,
|
||||||
payload::ParamValue,
|
payload::NoteExpression,
|
||||||
payload::ParamMod,
|
payload::ParamValue,
|
||||||
payload::ParamGesture,
|
payload::ParamMod,
|
||||||
// Most events are about the same length, but having the
|
payload::ParamGesture,
|
||||||
// transport in here sadly doubles this struct's size
|
// Most events are about the same length, but having the transport in
|
||||||
// TODO: Pack the events at some point, this will require
|
// here sadly doubles this struct's size
|
||||||
// special handling for SysEx events
|
// TODO: Pack the events at some point, this will require special
|
||||||
payload::Transport,
|
// handling for SysEx events
|
||||||
payload::Midi,
|
payload::Transport,
|
||||||
payload::MidiSysex,
|
payload::Midi,
|
||||||
payload::Midi2>
|
payload::MidiSysex,
|
||||||
|
payload::Midi2>
|
||||||
payload;
|
payload;
|
||||||
|
|
||||||
template <typename S>
|
template <typename S>
|
||||||
|
|||||||
Reference in New Issue
Block a user