diff --git a/src/common/communication.h b/src/common/communication.h index ddaa80ca..b9332ba3 100644 --- a/src/common/communication.h +++ b/src/common/communication.h @@ -931,8 +931,8 @@ EventResult passthrough_event(AEffect* plugin, F callback, Event& event) { [&](const std::string& s) -> void* { return const_cast(s.c_str()); }, - [&](const std::vector& buffer) -> void* { - return const_cast(buffer.data()); + [&](const ChunkData& chunk) -> void* { + return const_cast(chunk.buffer.data()); }, [&](native_size_t& window_handle) -> void* { // This is the X11 window handle that the editor should reparent @@ -982,32 +982,26 @@ EventResult passthrough_event(AEffect* plugin, F callback, Event& event) { auto write_payload_fn = overload{ [&](auto) -> EventResultPayload { return nullptr; }, [&](const AEffect& updated_plugin) -> EventResultPayload { - // 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 from the hosted VST plugin. + // 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 + // from the hosted VST plugin. update_aeffect(*plugin, updated_plugin); return nullptr; }, [&](DynamicSpeakerArrangement& speaker_arrangement) -> EventResultPayload { return speaker_arrangement; }, - [&](WantsChunkBuffer&) -> EventResultPayload { - // 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 written - const uint8_t* chunk_data = *static_cast(data); - return std::vector(chunk_data, chunk_data + return_value); - }, - [&](VstIOProperties& props) -> EventResultPayload { return props; }, - [&](VstMidiKeyName& key_name) -> EventResultPayload { - return key_name; - }, - [&](VstParameterProperties& props) -> EventResultPayload { - return props; - }, [&](WantsAEffectUpdate&) -> EventResultPayload { return *plugin; }, + [&](WantsChunkBuffer&) -> EventResultPayload { + // 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 + // written + const uint8_t* chunk_data = *static_cast(data); + return ChunkData{ + std::vector(chunk_data, chunk_data + return_value)}; + }, [&](WantsVstRect&) -> EventResultPayload { // 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 @@ -1021,10 +1015,11 @@ EventResult passthrough_event(AEffect* plugin, F callback, Event& event) { return *editor_rect; }, [&](WantsVstTimeInfo&) -> EventResultPayload { - // 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 `VstTimeInfo` struct! It can - // also be a null pointer if the host doesn't support this. + // 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 + // `VstTimeInfo` struct! It can also be a null pointer if the + // host doesn't support this. const auto time_info = reinterpret_cast(return_value); if (!time_info) { @@ -1035,6 +1030,13 @@ EventResult passthrough_event(AEffect* plugin, F callback, Event& event) { }, [&](WantsString&) -> EventResultPayload { return std::string(static_cast(data)); + }, + [&](VstIOProperties& props) -> EventResultPayload { return props; }, + [&](VstMidiKeyName& key_name) -> EventResultPayload { + return key_name; + }, + [&](VstParameterProperties& props) -> EventResultPayload { + return props; }}; // As mentioned about, the `effSetSpeakerArrangement` and diff --git a/src/common/logging.cpp b/src/common/logging.cpp index 6d57feaa..98aa8300 100644 --- a/src/common/logging.cpp +++ b/src/common/logging.cpp @@ -198,8 +198,8 @@ void Logger::log_event(bool is_dispatch, message << "<" << s.size() << " bytes>"; } }, - [&](const std::vector& buffer) { - message << "<" << buffer.size() << " byte chunk>"; + [&](const ChunkData& chunk) { + message << "<" << chunk.buffer.size() << " byte chunk>"; }, [&](const native_size_t& window_id) { message << ""; @@ -277,8 +277,8 @@ void Logger::log_event_response( message << ", <" << s.size() << " bytes>"; } }, - [&](const std::vector& buffer) { - message << ", <" << buffer.size() << " byte chunk>"; + [&](const ChunkData& chunk) { + message << ", <" << chunk.buffer.size() << " byte chunk>"; }, [&](const AEffect&) { message << ", "; }, [&](const DynamicSpeakerArrangement& speaker_arrangement) { diff --git a/src/common/serialization.h b/src/common/serialization.h index 163619ca..8f0e9823 100644 --- a/src/common/serialization.h +++ b/src/common/serialization.h @@ -172,6 +172,13 @@ void serialize(S& s, VstTimeInfo& time_info) { s.value4b(time_info.flags); } +/** + * Wrapper for chunk data. + */ +struct ChunkData { + std::vector buffer; +}; + /** * A wrapper around `VstEvents` that stores the data in a vector instead of a * C-style array. Needed until bitsery supports C-style arrays @@ -361,9 +368,9 @@ struct WantsString {}; */ using EventPayload = std::variant, native_size_t, AEffect, + ChunkData, DynamicVstEvents, DynamicSpeakerArrangement, WantsAEffectUpdate, @@ -383,8 +390,8 @@ void serialize(S& s, EventPayload& payload) { [](S& s, std::string& string) { s.text1b(string, max_string_length); }, - [](S& s, std::vector& buffer) { - s.container1b(buffer, binary_buffer_size); + [](S& s, ChunkData& chunk) { + s.container1b(chunk.buffer, binary_buffer_size); }, [](S& s, native_size_t& window_handle) { s.value8b(window_handle); @@ -460,8 +467,8 @@ struct Event { */ using EventResultPayload = std::variant, AEffect, + ChunkData, DynamicSpeakerArrangement, VstIOProperties, VstMidiKeyName, @@ -477,8 +484,8 @@ void serialize(S& s, EventResultPayload& payload) { [](S& s, std::string& string) { s.text1b(string, max_string_length); }, - [](S& s, std::vector& buffer) { - s.container1b(buffer, binary_buffer_size); + [](S& s, ChunkData& chunk) { + s.container1b(chunk.buffer, binary_buffer_size); }, [](S& s, AEffect& effect) { s.object(effect); }, [&](DynamicSpeakerArrangement& speaker_arrangement) -> void* { diff --git a/src/plugin/plugin-bridge.cpp b/src/plugin/plugin-bridge.cpp index 82ce1cbf..44ca3489 100644 --- a/src/plugin/plugin-bridge.cpp +++ b/src/plugin/plugin-bridge.cpp @@ -203,7 +203,8 @@ class DispatchDataConverter : DefaultDataConverter { // When the host passes a chunk it will use the value parameter // to tell us its length - return std::vector(chunk_data, chunk_data + value); + return ChunkData{ + std::vector(chunk_data, chunk_data + value)}; } break; case effProcessEvents: return DynamicVstEvents(*static_cast(data)); @@ -299,7 +300,7 @@ class DispatchDataConverter : DefaultDataConverter { // `PluginBridge` and write a pointer to that struct to the data // pointer const auto buffer = - std::get>(response.payload); + std::get(response.payload).buffer; chunk.assign(buffer.begin(), buffer.end()); *static_cast(data) = chunk.data();