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.
This commit is contained in:
Robbert van der Helm
2020-05-10 13:10:16 +02:00
parent e762a57c0d
commit ba91971829
3 changed files with 11 additions and 19 deletions
+5 -12
View File
@@ -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 <typename T, typename Socket>
inline T& read_object(Socket& socket,
T& object,
std::vector<uint8_t> buffer = std::vector<uint8_t>(64)) {
inline T read_object(Socket& socket,
std::vector<uint8_t> buffer = std::vector<uint8_t>(64)) {
// See the note above on the use of `uint64_t` instead of `size_t`
std::array<uint64_t, 1> 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<InputAdapter<std::vector<uint8_t>>>(
{buffer.begin(), size}, object);
@@ -111,9 +110,3 @@ inline T& read_object(Socket& socket,
return object;
}
template <typename T, typename Socket>
inline T read_object(Socket& socket) {
T object;
return read_object(socket, object);
}
+4 -4
View File
@@ -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<AEffect>(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<AudioBuffers>(host_vst_process_replacing, process_buffer);
assert(response.buffers.size() == static_cast<size_t>(plugin.numOutputs));
for (int channel = 0; channel < plugin.numOutputs; channel++) {
+2 -3
View File
@@ -253,9 +253,8 @@ void WineBridge::handle_dispatch() {
std::vector<std::vector<float>> output_buffers(plugin->numOutputs);
while (true) {
AudioBuffers request;
request =
read_object(host_vst_process_replacing, request, process_buffer);
auto request = read_object<AudioBuffers>(host_vst_process_replacing,
process_buffer);
// The process functions expect a `float**` for their inputs and
// their outputs