mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-06 19:40:10 +02:00
Add serialization for midi events
This commit is contained in:
@@ -57,9 +57,11 @@ template <typename T, typename Socket>
|
||||
inline void write_object(Socket& socket,
|
||||
const T& object,
|
||||
typename buffer_t<T>::type& buffer) {
|
||||
bitsery::ext::PointerLinkingContext serializer_context{};
|
||||
auto length =
|
||||
bitsery::quickSerialization<OutputAdapter<typename buffer_t<T>::type>>(
|
||||
buffer, object);
|
||||
bitsery::quickSerialization<bitsery::ext::PointerLinkingContext,
|
||||
OutputAdapter<typename buffer_t<T>::type>>(
|
||||
serializer_context, buffer, object);
|
||||
|
||||
socket.send(boost::asio::buffer(buffer, length));
|
||||
}
|
||||
@@ -91,9 +93,11 @@ inline T& read_object(Socket& socket,
|
||||
typename buffer_t<T>::type& buffer) {
|
||||
auto message_length = socket.receive(boost::asio::buffer(buffer));
|
||||
|
||||
bitsery::ext::PointerLinkingContext serializer_context{};
|
||||
auto [_, success] =
|
||||
bitsery::quickDeserialization<InputAdapter<typename buffer_t<T>::type>>(
|
||||
{buffer.begin(), message_length}, object);
|
||||
bitsery::quickDeserialization<bitsery::ext::PointerLinkingContext,
|
||||
InputAdapter<typename buffer_t<T>::type>>(
|
||||
serializer_context, {buffer.begin(), message_length}, object);
|
||||
|
||||
if (!success) {
|
||||
throw std::runtime_error("Deserialization failure in call:" +
|
||||
@@ -172,6 +176,7 @@ void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
|
||||
[&](const std::string& s) -> void* {
|
||||
return const_cast<char*>(s.c_str());
|
||||
},
|
||||
[&](VstEvents& events) -> void* { return &events; },
|
||||
[&](NeedsBuffer&) -> void* { return buffer.data(); }},
|
||||
event.payload);
|
||||
const intptr_t return_value = callback(plugin, event.opcode, event.index,
|
||||
|
||||
@@ -145,6 +145,9 @@ void Logger::log_event(bool is_dispatch,
|
||||
overload{
|
||||
[&](const std::nullptr_t&) { message << "<nullptr>"; },
|
||||
[&](const std::string& s) { message << "\"" << s << "\""; },
|
||||
[&](const VstEvents& events) {
|
||||
message << "<" << events.numEvents << " midi_events>";
|
||||
},
|
||||
[&](const NeedsBuffer&) { message << "<writable_buffer>"; }},
|
||||
payload);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <bitsery/adapter/buffer.h>
|
||||
#include <bitsery/ext/pointer.h>
|
||||
#include <bitsery/ext/std_optional.h>
|
||||
#include <bitsery/ext/std_variant.h>
|
||||
#include <bitsery/traits/array.h>
|
||||
@@ -71,13 +72,14 @@ struct NeedsBuffer {};
|
||||
* opcode `effProcessEvents` comes with a struct containing a list of midi
|
||||
* events.
|
||||
*
|
||||
* TODO: A lot of these are still missing, beginning with `VstEvents`.
|
||||
* TODO: A lot of these are still missing
|
||||
*
|
||||
* - Some empty buffer for the plugin to write its own data to, for instance for
|
||||
* a plugin to report its name or the label for a certain parameter. We'll
|
||||
* assume that this is the default if none of the above options apply.
|
||||
*/
|
||||
using EventPayload = std::variant<std::nullptr_t, std::string, NeedsBuffer>;
|
||||
using EventPayload =
|
||||
std::variant<std::nullptr_t, std::string, VstEvents, NeedsBuffer>;
|
||||
|
||||
/**
|
||||
* An event as dispatched by the VST host. These events will get forwarded to
|
||||
@@ -121,12 +123,27 @@ struct Event {
|
||||
// `EventPayload` in a struct
|
||||
s.ext(payload,
|
||||
bitsery::ext::StdVariant{
|
||||
// TODO: Some of these oerlaods might not be necessary, check
|
||||
// if this is the case
|
||||
[](S&, std::nullptr_t&) {},
|
||||
[](S& s, std::string& string) {
|
||||
s.text1b(string, max_string_length);
|
||||
},
|
||||
[](S& s, VstEvents& events) {
|
||||
s.value4b(events.numEvents);
|
||||
|
||||
// This will only ever read a single event since
|
||||
// that's how the `VstEvents` struct is defined,
|
||||
// hence the assertion. If multiple events can be
|
||||
// passed at once then `VstEvents` should be
|
||||
// modified.
|
||||
assert(events.numEvents <= 1);
|
||||
s.container(
|
||||
events.events, [](S& s, VstEvent*(&event_ptr)) {
|
||||
s.ext(event_ptr, bitsery::ext::PointerOwner(),
|
||||
[](S& s, VstEvent& event) {
|
||||
s.container1b(event.dump);
|
||||
});
|
||||
});
|
||||
},
|
||||
[](S&, NeedsBuffer&) {}});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -208,6 +208,7 @@ class VstMidiEvent {
|
||||
};
|
||||
|
||||
class VstEvent {
|
||||
public:
|
||||
char dump[sizeof(VstMidiEvent)];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user