From 96d0428d56192db49cab3dd5b835dda1e025b7bd Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 9 Mar 2020 21:44:44 +0100 Subject: [PATCH] Factor out the serializer for event payloads --- src/common/serialization.h | 31 +++++++++++++++++-------------- src/plugin/host-bridge.cpp | 1 + 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/common/serialization.h b/src/common/serialization.h index 51bcd9d6..917178e0 100644 --- a/src/common/serialization.h +++ b/src/common/serialization.h @@ -138,6 +138,22 @@ struct NeedsBuffer {}; using EventPayload = std::variant; +template +void serialize(S& s, EventPayload& payload) { + s.ext(payload, bitsery::ext::StdVariant{ + [](S&, std::nullptr_t&) {}, + [](S& s, std::string& string) { + s.text1b(string, max_string_length); + }, + [](S& s, DynamicVstEvents& events) { + s.container(events.events, max_midi_events, + [](S& s, VstEvent& event) { + s.container1b(event.dump); + }); + }, + [](S&, NeedsBuffer&) {}}); +} + /** * An event as dispatched by the VST host. These events will get forwarded to * the VST host process running under Wine. The fields here mirror those @@ -173,20 +189,7 @@ struct Event { s.value8b(value); s.value4b(option); - // I couldn't get this serializer to work seperately without - // `EventPayload` in a struct - s.ext(payload, bitsery::ext::StdVariant{ - [](S&, std::nullptr_t&) {}, - [](S& s, std::string& string) { - s.text1b(string, max_string_length); - }, - [](S& s, DynamicVstEvents& events) { - s.container(events.events, max_midi_events, - [](S& s, VstEvent& event) { - s.container1b(event.dump); - }); - }, - [](S&, NeedsBuffer&) {}}); + s.object(payload); } }; diff --git a/src/plugin/host-bridge.cpp b/src/plugin/host-bridge.cpp index 0fec8cbc..476f3631 100644 --- a/src/plugin/host-bridge.cpp +++ b/src/plugin/host-bridge.cpp @@ -182,6 +182,7 @@ intptr_t HostBridge::dispatch(AEffect* /*plugin*/, break; } + // TODO: Maybe reuse buffers here when dealing with chunk data return send_event( host_vst_dispatch, opcode, index, value, data, option, std::pair(logger, true));