From ba91971829ec6b98efaaba40c3baec8c7e1eceb8 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 10 May 2020 13:10:16 +0200 Subject: [PATCH] Simplify object reading No longer needs to read into an existing object after the last change, and reusing that function here too makes it less error prone. --- src/common/communication.h | 17 +++++------------ src/plugin/plugin-bridge.cpp | 8 ++++---- src/wine-host/wine-bridge.cpp | 5 ++--- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/common/communication.h b/src/common/communication.h index 4cc5086c..8cea096e 100644 --- a/src/common/communication.h +++ b/src/common/communication.h @@ -71,20 +71,18 @@ inline void write_object( * together with `write_object`. This will block until the object is available. * * @param socket The Boost.Asio socket to read from. - * @param object The object to deserialize to, if given. This can be used to - * update an existing `AEffect` struct without losing the pointers set by the - * host and the bridge. * @param buffer The buffer to read into. This is useful for sending audio and * chunk data since that can vary in size by a lot. * + * @return The deserialized object. + * * @throw std::runtime_error If the conversion to an object was not successful. * * @relates write_object */ template -inline T& read_object(Socket& socket, - T& object, - std::vector buffer = std::vector(64)) { +inline T read_object(Socket& socket, + std::vector buffer = std::vector(64)) { // See the note above on the use of `uint64_t` instead of `size_t` std::array message_length; boost::asio::read(socket, boost::asio::buffer(message_length)); @@ -100,6 +98,7 @@ inline T& read_object(Socket& socket, boost::asio::read(socket, boost::asio::buffer(buffer)); assert(size == actual_size); + T object; auto [_, success] = bitsery::quickDeserialization>>( {buffer.begin(), size}, object); @@ -111,9 +110,3 @@ inline T& read_object(Socket& socket, return object; } - -template -inline T read_object(Socket& socket) { - T object; - return read_object(socket, object); -} diff --git a/src/plugin/plugin-bridge.cpp b/src/plugin/plugin-bridge.cpp index 76d44c8b..e52540d8 100644 --- a/src/plugin/plugin-bridge.cpp +++ b/src/plugin/plugin-bridge.cpp @@ -222,7 +222,8 @@ PluginBridge::PluginBridge(audioMasterCallback host_callback) // Read the plugin's information from the Wine process. This can only be // done after we started accepting host callbacks as the plugin might do // this during initialization. - plugin = read_object(vst_host_aeffect, plugin); + const auto initialized_plugin = read_object(vst_host_aeffect); + update_aeffect(plugin, initialized_plugin); } class DispatchDataConverter : DefaultDataConverter { @@ -541,9 +542,8 @@ void PluginBridge::process_replacing(AEffect* /*plugin*/, write_object(host_vst_process_replacing, request, process_buffer); // Write the results back to the `outputs` arrays - AudioBuffers response; - response = - read_object(host_vst_process_replacing, response, process_buffer); + const auto response = + read_object(host_vst_process_replacing, process_buffer); assert(response.buffers.size() == static_cast(plugin.numOutputs)); for (int channel = 0; channel < plugin.numOutputs; channel++) { diff --git a/src/wine-host/wine-bridge.cpp b/src/wine-host/wine-bridge.cpp index d60e7fa8..ef4fc5cf 100644 --- a/src/wine-host/wine-bridge.cpp +++ b/src/wine-host/wine-bridge.cpp @@ -253,9 +253,8 @@ void WineBridge::handle_dispatch() { std::vector> output_buffers(plugin->numOutputs); while (true) { - AudioBuffers request; - request = - read_object(host_vst_process_replacing, request, process_buffer); + auto request = read_object(host_vst_process_replacing, + process_buffer); // The process functions expect a `float**` for their inputs and // their outputs