Factor out the serializer for event payloads

This commit is contained in:
Robbert van der Helm
2020-03-09 21:44:44 +01:00
parent 8dad15b597
commit 96d0428d56
2 changed files with 18 additions and 14 deletions
+17 -14
View File
@@ -138,6 +138,22 @@ struct NeedsBuffer {};
using EventPayload = using EventPayload =
std::variant<std::nullptr_t, std::string, DynamicVstEvents, NeedsBuffer>; std::variant<std::nullptr_t, std::string, DynamicVstEvents, NeedsBuffer>;
template <typename S>
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 * 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 * the VST host process running under Wine. The fields here mirror those
@@ -173,20 +189,7 @@ struct Event {
s.value8b(value); s.value8b(value);
s.value4b(option); s.value4b(option);
// I couldn't get this serializer to work seperately without s.object(payload);
// `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&) {}});
} }
}; };
+1
View File
@@ -182,6 +182,7 @@ intptr_t HostBridge::dispatch(AEffect* /*plugin*/,
break; break;
} }
// TODO: Maybe reuse buffers here when dealing with chunk data
return send_event<DispatchDataConverter>( return send_event<DispatchDataConverter>(
host_vst_dispatch, opcode, index, value, data, option, host_vst_dispatch, opcode, index, value, data, option,
std::pair<Logger&, bool>(logger, true)); std::pair<Logger&, bool>(logger, true));