mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +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,
|
inline void write_object(Socket& socket,
|
||||||
const T& object,
|
const T& object,
|
||||||
typename buffer_t<T>::type& buffer) {
|
typename buffer_t<T>::type& buffer) {
|
||||||
|
bitsery::ext::PointerLinkingContext serializer_context{};
|
||||||
auto length =
|
auto length =
|
||||||
bitsery::quickSerialization<OutputAdapter<typename buffer_t<T>::type>>(
|
bitsery::quickSerialization<bitsery::ext::PointerLinkingContext,
|
||||||
buffer, object);
|
OutputAdapter<typename buffer_t<T>::type>>(
|
||||||
|
serializer_context, buffer, object);
|
||||||
|
|
||||||
socket.send(boost::asio::buffer(buffer, length));
|
socket.send(boost::asio::buffer(buffer, length));
|
||||||
}
|
}
|
||||||
@@ -91,9 +93,11 @@ inline T& read_object(Socket& socket,
|
|||||||
typename buffer_t<T>::type& buffer) {
|
typename buffer_t<T>::type& buffer) {
|
||||||
auto message_length = socket.receive(boost::asio::buffer(buffer));
|
auto message_length = socket.receive(boost::asio::buffer(buffer));
|
||||||
|
|
||||||
|
bitsery::ext::PointerLinkingContext serializer_context{};
|
||||||
auto [_, success] =
|
auto [_, success] =
|
||||||
bitsery::quickDeserialization<InputAdapter<typename buffer_t<T>::type>>(
|
bitsery::quickDeserialization<bitsery::ext::PointerLinkingContext,
|
||||||
{buffer.begin(), message_length}, object);
|
InputAdapter<typename buffer_t<T>::type>>(
|
||||||
|
serializer_context, {buffer.begin(), message_length}, object);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw std::runtime_error("Deserialization failure in call:" +
|
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* {
|
[&](const std::string& s) -> void* {
|
||||||
return const_cast<char*>(s.c_str());
|
return const_cast<char*>(s.c_str());
|
||||||
},
|
},
|
||||||
|
[&](VstEvents& events) -> void* { return &events; },
|
||||||
[&](NeedsBuffer&) -> void* { return buffer.data(); }},
|
[&](NeedsBuffer&) -> void* { return buffer.data(); }},
|
||||||
event.payload);
|
event.payload);
|
||||||
const intptr_t return_value = callback(plugin, event.opcode, event.index,
|
const intptr_t return_value = callback(plugin, event.opcode, event.index,
|
||||||
|
|||||||
@@ -145,6 +145,9 @@ void Logger::log_event(bool is_dispatch,
|
|||||||
overload{
|
overload{
|
||||||
[&](const std::nullptr_t&) { message << "<nullptr>"; },
|
[&](const std::nullptr_t&) { message << "<nullptr>"; },
|
||||||
[&](const std::string& s) { message << "\"" << s << "\""; },
|
[&](const std::string& s) { message << "\"" << s << "\""; },
|
||||||
|
[&](const VstEvents& events) {
|
||||||
|
message << "<" << events.numEvents << " midi_events>";
|
||||||
|
},
|
||||||
[&](const NeedsBuffer&) { message << "<writable_buffer>"; }},
|
[&](const NeedsBuffer&) { message << "<writable_buffer>"; }},
|
||||||
payload);
|
payload);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <bitsery/adapter/buffer.h>
|
#include <bitsery/adapter/buffer.h>
|
||||||
|
#include <bitsery/ext/pointer.h>
|
||||||
#include <bitsery/ext/std_optional.h>
|
#include <bitsery/ext/std_optional.h>
|
||||||
#include <bitsery/ext/std_variant.h>
|
#include <bitsery/ext/std_variant.h>
|
||||||
#include <bitsery/traits/array.h>
|
#include <bitsery/traits/array.h>
|
||||||
@@ -71,13 +72,14 @@ struct NeedsBuffer {};
|
|||||||
* opcode `effProcessEvents` comes with a struct containing a list of midi
|
* opcode `effProcessEvents` comes with a struct containing a list of midi
|
||||||
* events.
|
* 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
|
* - 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
|
* 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.
|
* 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
|
* An event as dispatched by the VST host. These events will get forwarded to
|
||||||
@@ -121,12 +123,27 @@ struct Event {
|
|||||||
// `EventPayload` in a struct
|
// `EventPayload` in a struct
|
||||||
s.ext(payload,
|
s.ext(payload,
|
||||||
bitsery::ext::StdVariant{
|
bitsery::ext::StdVariant{
|
||||||
// TODO: Some of these oerlaods might not be necessary, check
|
|
||||||
// if this is the case
|
|
||||||
[](S&, std::nullptr_t&) {},
|
[](S&, std::nullptr_t&) {},
|
||||||
[](S& s, std::string& string) {
|
[](S& s, std::string& string) {
|
||||||
s.text1b(string, max_string_length);
|
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&) {}});
|
[](S&, NeedsBuffer&) {}});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ class VstMidiEvent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class VstEvent {
|
class VstEvent {
|
||||||
|
public:
|
||||||
char dump[sizeof(VstMidiEvent)];
|
char dump[sizeof(VstMidiEvent)];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user