diff --git a/src/common/communication/vst2.h b/src/common/communication/vst2.h index 79209208..d78e3307 100644 --- a/src/common/communication/vst2.h +++ b/src/common/communication/vst2.h @@ -230,7 +230,7 @@ class Vst2EventHandler : public AdHocSocketHandler { * an `Vst2Event`. This is almost always uses `passthrough_event()`, which * converts a `Vst2Event::Payload` into the format used by VST2, calls * either `dispatch()` or `audioMaster()` depending on the context, and then - * serializes the result back into an `EventResultPayload`. + * serializes the result back into an `Vst2EventResult::Payload`. * * @param logging A pair containing a logger instance and whether or not * this is for sending `dispatch()` events or host callbacks. Optional @@ -478,8 +478,8 @@ Vst2EventResult passthrough_event(AEffect* plugin, // For some payload types we need to write back a value to the data pointer auto write_payload_fn = overload{ - [&](auto) -> EventResultPayload { return nullptr; }, - [&](const AEffect& updated_plugin) -> EventResultPayload { + [&](auto) -> Vst2EventResult::Payload { return nullptr; }, + [&](const AEffect& updated_plugin) -> Vst2EventResult::Payload { // This is a bit of a special case! Instead of writing some return // value, we will update values on the native VST plugin's `AEffect` // object. This is triggered by the `audioMasterIOChanged` callback @@ -489,9 +489,11 @@ Vst2EventResult passthrough_event(AEffect* plugin, return nullptr; }, [&](DynamicSpeakerArrangement& speaker_arrangement) - -> EventResultPayload { return speaker_arrangement; }, - [&](WantsAEffectUpdate&) -> EventResultPayload { return *plugin; }, - [&](WantsChunkBuffer&) -> EventResultPayload { + -> Vst2EventResult::Payload { return speaker_arrangement; }, + [&](WantsAEffectUpdate&) -> Vst2EventResult::Payload { + return *plugin; + }, + [&](WantsChunkBuffer&) -> Vst2EventResult::Payload { // In this case the plugin will have written its data stored in an // array to which a pointer is stored in `data`, with the return // value from the event determines how much data the plugin has @@ -500,7 +502,7 @@ Vst2EventResult passthrough_event(AEffect* plugin, return ChunkData{ std::vector(chunk_data, chunk_data + return_value)}; }, - [&](WantsVstRect&) -> EventResultPayload { + [&](WantsVstRect&) -> Vst2EventResult::Payload { // The plugin should have written a pointer to a VstRect struct into // the data pointer. I haven't seen this fail yet, but since some // hosts will call `effEditGetRect()` before `effEditOpen()` I can @@ -512,7 +514,7 @@ Vst2EventResult passthrough_event(AEffect* plugin, return *editor_rect; }, - [&](WantsVstTimeInfo&) -> EventResultPayload { + [&](WantsVstTimeInfo&) -> Vst2EventResult::Payload { // Not sure why the VST API has twenty different ways of // returning structs, but in this case the value returned from // the callback function is actually a pointer to a @@ -526,14 +528,16 @@ Vst2EventResult passthrough_event(AEffect* plugin, return *time_info; } }, - [&](WantsString&) -> EventResultPayload { + [&](WantsString&) -> Vst2EventResult::Payload { return std::string(static_cast(data)); }, - [&](VstIOProperties& props) -> EventResultPayload { return props; }, - [&](VstMidiKeyName& key_name) -> EventResultPayload { + [&](VstIOProperties& props) -> Vst2EventResult::Payload { + return props; + }, + [&](VstMidiKeyName& key_name) -> Vst2EventResult::Payload { return key_name; }, - [&](VstParameterProperties& props) -> EventResultPayload { + [&](VstParameterProperties& props) -> Vst2EventResult::Payload { return props; }}; @@ -541,9 +545,9 @@ Vst2EventResult passthrough_event(AEffect* plugin, // And as mentioned above, `effGetSpeakerArrangement()` wants the plugin's // speaker arrangement to be the data pointer, so we need to do this same // serialization step just for that function. - const EventResultPayload response_data = + const Vst2EventResult::Payload response_data = std::visit(write_payload_fn, event.payload); - std::optional value_response_data = std::nullopt; + std::optional value_response_data = std::nullopt; if (event.value_payload) { value_response_data = std::visit(write_payload_fn, *event.value_payload); diff --git a/src/common/logging/vst2.cpp b/src/common/logging/vst2.cpp index f8ef2311..a188b80d 100644 --- a/src/common/logging/vst2.cpp +++ b/src/common/logging/vst2.cpp @@ -448,8 +448,8 @@ void Vst2Logger::log_event_response( bool is_dispatch, int opcode, intptr_t return_value, - const EventResultPayload& payload, - const std::optional& value_payload, + const Vst2EventResult::Payload& payload, + const std::optional& value_payload, bool from_cache) { if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) { if (should_filter_event(is_dispatch, opcode)) { diff --git a/src/common/logging/vst2.h b/src/common/logging/vst2.h index c3e3db4e..9732b726 100644 --- a/src/common/logging/vst2.h +++ b/src/common/logging/vst2.h @@ -73,8 +73,8 @@ class Vst2Logger { bool is_dispatch, int opcode, intptr_t return_value, - const EventResultPayload& payload, - const std::optional& value_payload, + const Vst2EventResult::Payload& payload, + const std::optional& value_payload, bool from_cache = false); /** diff --git a/src/common/serialization/vst2.h b/src/common/serialization/vst2.h index 0194d6ed..e01a8c0a 100644 --- a/src/common/serialization/vst2.h +++ b/src/common/serialization/vst2.h @@ -427,33 +427,64 @@ void serialize(S& s, Vst2Event::Payload& payload) { } /** - * The response for an event. This is usually either: - * - * - Nothing, on which case only the return value from the callback function - * gets passed along. - * - A (short) string. - * - Some binary blob stored as a byte vector. During `effGetChunk` this will - * contain some chunk data that should be written to - * `Vst2PluginBridge::chunk_data`. - * - A specific struct in response to an event such as `audioMasterGetTime` or - * `audioMasterIOChanged`. - * - An X11 window pointer for the editor window. - * - * @relates passthrough_event + * AN instance of this should be sent back as a response to an incoming event. */ -using EventResultPayload = std::variant; +struct Vst2EventResult { + /** + * The response for an event. This is usually either: + * + * - Nothing, on which case only the return value from the callback function + * gets passed along. + * - A (short) string. + * - Some binary blob stored as a byte vector. During `effGetChunk` this + * will contain some chunk data that should be written to + * `Vst2PluginBridge::chunk_data`. + * - A specific struct in response to an event such as `audioMasterGetTime` + * or `audioMasterIOChanged`. + * - An X11 window pointer for the editor window. + * + * @relates passthrough_event + */ + using Payload = std::variant; + + /** + * The result that should be returned from the dispatch function. + */ + native_intptr_t return_value; + /** + * Events typically either just return their return value or write a string + * into the void pointer, but sometimes an event response should forward + * some kind of special struct. + */ + Payload payload; + /** + * The same as the above value, but for returning values written to the + * `intptr_t` value parameter. This is only used during + * `effGetSpeakerArrangement`. + */ + std::optional value_payload; + + template + void serialize(S& s) { + s.value8b(return_value); + + s.object(payload); + s.ext(value_payload, bitsery::ext::StdOptional(), + [](S& s, auto& v) { s.object(v); }); + } +}; template -void serialize(S& s, EventResultPayload& payload) { +void serialize(S& s, Vst2EventResult::Payload& payload) { s.ext(payload, bitsery::ext::StdVariant{ [](S&, std::nullptr_t&) {}, @@ -474,37 +505,6 @@ void serialize(S& s, EventResultPayload& payload) { [](S& s, VstTimeInfo& time_info) { s.object(time_info); }}); } -/** - * AN instance of this should be sent back as a response to an incoming event. - */ -struct Vst2EventResult { - /** - * The result that should be returned from the dispatch function. - */ - native_intptr_t return_value; - /** - * Events typically either just return their return value or write a string - * into the void pointer, but sometimes an event response should forward - * some kind of special struct. - */ - EventResultPayload payload; - /** - * The same as the above value, but for returning values written to the - * `intptr_t` value parameter. This is only used during - * `effGetSpeakerArrangement`. - */ - std::optional value_payload; - - template - void serialize(S& s) { - s.value8b(return_value); - - s.object(payload); - s.ext(value_payload, bitsery::ext::StdOptional(), - [](S& s, auto& v) { s.object(v); }); - } -}; - /** * Represents a call to either `getParameter` or `setParameter`, depending on * whether `value` contains a value or not.