From 523f77d3343d6a4d30145c14f4b7a59f1b91f47a Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 23 Jul 2020 14:11:00 +0200 Subject: [PATCH] Use designated initializers for complex structs This was one of the main reasons why I wanted to switch to C++20, I just forgot to do it. --- src/common/events.h | 11 +++++++++-- src/plugin/host-process.cpp | 12 +++++++----- src/plugin/plugin-bridge.cpp | 4 +++- src/wine-host/bridges/vst2.cpp | 9 ++++++--- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/common/events.h b/src/common/events.h index 99473828..68864b13 100644 --- a/src/common/events.h +++ b/src/common/events.h @@ -160,7 +160,12 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket, value_payload); } - const Event event{opcode, index, value, option, payload, value_payload}; + const Event event{.opcode = opcode, + .index = index, + .value = value, + .option = option, + .payload = payload, + .value_payload = value_payload}; // Prevent two threads from writing over the socket at the same time and // messages getting out of order. This is needed because we can't prevent @@ -394,7 +399,9 @@ auto passthrough_event(AEffect* plugin, F callback) { std::visit(write_payload_fn, *event.value_payload); } - EventResult response{return_value, response_data, value_response_data}; + EventResult response{.return_value = return_value, + .payload = response_data, + .value_payload = value_response_data}; return response; }; diff --git a/src/plugin/host-process.cpp b/src/plugin/host-process.cpp index eb91eed2..9c6b9871 100644 --- a/src/plugin/host-process.cpp +++ b/src/plugin/host-process.cpp @@ -166,8 +166,9 @@ GroupHost::GroupHost( boost::asio::local::stream_protocol::socket group_socket(io_context); group_socket.connect(group_socket_path.string()); - write_object(group_socket, GroupRequest{plugin_path.string(), - socket_endpoint.string()}); + write_object(group_socket, + GroupRequest{.plugin_path = plugin_path.string(), + .socket_path = socket_endpoint.string()}); const auto response = read_object(group_socket); host_pid = response.pid; @@ -202,9 +203,10 @@ GroupHost::GroupHost( io_context); group_socket.connect(group_socket_path.string()); - write_object(group_socket, - GroupRequest{plugin_path.string(), - socket_endpoint.string()}); + write_object( + group_socket, + GroupRequest{.plugin_path = plugin_path.string(), + .socket_path = socket_endpoint.string()}); const auto response = read_object(group_socket); diff --git a/src/plugin/plugin-bridge.cpp b/src/plugin/plugin-bridge.cpp index 3f150c0b..578483a5 100644 --- a/src/plugin/plugin-bridge.cpp +++ b/src/plugin/plugin-bridge.cpp @@ -155,7 +155,9 @@ PluginBridge::PluginBridge(audioMasterCallback host_callback) incoming_midi_events.push_back( std::get(event.payload)); - EventResult response{1, nullptr, std::nullopt}; + EventResult response{.return_value = 1, + .payload = nullptr, + .value_payload = std::nullopt}; return response; } else { diff --git a/src/wine-host/bridges/vst2.cpp b/src/wine-host/bridges/vst2.cpp index a2daefe7..519b2976 100644 --- a/src/wine-host/bridges/vst2.cpp +++ b/src/wine-host/bridges/vst2.cpp @@ -132,7 +132,9 @@ Vst2Bridge::Vst2Bridge(boost::asio::io_context& main_context, // of this object will be sent over the `dispatcher()` socket. This would be // done after the host calls `effOpen()`, and when the plugin calls // `audioMasterIOChanged()`. - write_object(host_vst_control, EventResult{0, *plugin, std::nullopt}); + write_object(host_vst_control, EventResult{.return_value = 0, + .payload = *plugin, + .value_payload = std::nullopt}); // After sending the AEffect struct we'll receive this instance's // configuration as a response @@ -218,8 +220,9 @@ void Vst2Bridge::handle_dispatch_midi_events() { plugin, event.opcode, event.index, event.value, &events.as_c_events(), event.option); - EventResult response{return_value, nullptr, - std::nullopt}; + EventResult response{.return_value = return_value, + .payload = nullptr, + .value_payload = std::nullopt}; return response; } else {