From bd0dd63ad22d7424372be0c75de1f2ccad5b1fb1 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 20 May 2021 15:53:16 +0200 Subject: [PATCH] Rename the EventResult struct to Vst2EventResult --- src/common/communication/vst2.cpp | 13 +++++++------ src/common/communication/vst2.h | 28 ++++++++++++++------------- src/common/serialization/vst2.h | 2 +- src/plugin/bridges/vst2.cpp | 32 ++++++++++++++++--------------- src/wine-host/bridges/vst2.cpp | 17 ++++++++-------- 5 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/common/communication/vst2.cpp b/src/common/communication/vst2.cpp index cdad7d59..f05dc898 100644 --- a/src/common/communication/vst2.cpp +++ b/src/common/communication/vst2.cpp @@ -46,7 +46,7 @@ std::optional DefaultDataConverter::read_value( void DefaultDataConverter::write_data(const int /*opcode*/, void* data, - const EventResult& response) const { + const Vst2EventResult& response) const { // The default behavior is to handle this as a null terminated C-style // string std::visit(overload{[&](const auto&) {}, @@ -62,18 +62,19 @@ void DefaultDataConverter::write_data(const int /*opcode*/, response.payload); } -void DefaultDataConverter::write_value(const int /*opcode*/, - intptr_t /*value*/, - const EventResult& /*response*/) const {} +void DefaultDataConverter::write_value( + const int /*opcode*/, + intptr_t /*value*/, + const Vst2EventResult& /*response*/) const {} intptr_t DefaultDataConverter::return_value(const int /*opcode*/, const intptr_t original) const { return original; } -EventResult DefaultDataConverter::send_event( +Vst2EventResult DefaultDataConverter::send_event( boost::asio::local::stream_protocol::socket& socket, const Vst2Event& event) const { write_object(socket, event); - return read_object(socket); + return read_object(socket); } diff --git a/src/common/communication/vst2.h b/src/common/communication/vst2.h index 9401f9df..79209208 100644 --- a/src/common/communication/vst2.h +++ b/src/common/communication/vst2.h @@ -57,7 +57,7 @@ class DefaultDataConverter { */ virtual void write_data(const int opcode, void* data, - const EventResult& response) const; + const Vst2EventResult& response) const; /** * Write the response back to the `value` pointer. This is only used during @@ -65,7 +65,7 @@ class DefaultDataConverter { */ virtual void write_value(const int opcode, intptr_t value, - const EventResult& response) const; + const Vst2EventResult& response) const; /** * This function can override a callback's return value based on the opcode. @@ -85,7 +85,7 @@ class DefaultDataConverter { * back. This can be overridden to use `MutualRecursionHelper::fork()` for * specific opcodes to allow mutually recursive calling sequences. */ - virtual EventResult send_event( + virtual Vst2EventResult send_event( boost::asio::local::stream_protocol::socket& socket, const Vst2Event& event) const; }; @@ -204,7 +204,7 @@ class Vst2EventHandler : public AdHocSocketHandler { // from the socket, so we can override this for specific function calls // that potentially need to have their responses handled on the same // calling thread (i.e. mutual recursion). - const EventResult response = this->send( + const Vst2EventResult response = this->send( [&](boost::asio::local::stream_protocol::socket& socket) { return data_converter.send_event(socket, event); }); @@ -226,8 +226,8 @@ class Vst2EventHandler : public AdHocSocketHandler { * Spawn a new thread to listen for extra connections to `endpoint`, and * then start a blocking loop that handles events from the primary `socket`. * - * The specified function will be used to create an `EventResult` from an - * `Vst2Event`. This is almost always uses `passthrough_event()`, which + * The specified function will be used to create an `Vst2EventResult` from + * 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`. @@ -241,7 +241,7 @@ class Vst2EventHandler : public AdHocSocketHandler { * @relates Vst2EventHandler::send_event * @relates passthrough_event */ - template F> + template F> void receive_events(std::optional> logging, F&& callback) { // Reading, processing, and writing back event data from the sockets @@ -257,7 +257,7 @@ class Vst2EventHandler : public AdHocSocketHandler { event.value_payload); } - EventResult response = callback(event, on_main_thread); + Vst2EventResult response = callback(event, on_main_thread); if (logging) { auto [logger, is_dispatch] = *logging; logger.log_event_response( @@ -388,7 +388,7 @@ class Vst2Sockets : public Sockets { * Unmarshall an `Vst2Event::Payload` back to the representation used by VST2, * pass that value to a callback function (either `AEffect::dispatcher()` for * host -> plugin events or `audioMaster()` for plugin -> host events), and then - * serialize the results back into an `EventResult`. + * serialize the results back into an `Vst2EventResult`. * * This is the receiving analogue of the `*DataCovnerter` objects. * @@ -410,7 +410,9 @@ class Vst2Sockets : public Sockets { */ template < invocable_returning F> -EventResult passthrough_event(AEffect* plugin, F&& callback, Vst2Event& event) { +Vst2EventResult passthrough_event(AEffect* plugin, + F&& callback, + Vst2Event& event) { // This buffer is used to write strings and small objects to. We'll // initialize the beginning with null values to both prevent it from being // read as some arbitrary C-style string, and to make sure that @@ -547,7 +549,7 @@ EventResult passthrough_event(AEffect* plugin, F&& callback, Vst2Event& event) { std::visit(write_payload_fn, *event.value_payload); } - return EventResult{.return_value = return_value, - .payload = response_data, - .value_payload = value_response_data}; + return Vst2EventResult{.return_value = return_value, + .payload = response_data, + .value_payload = value_response_data}; } diff --git a/src/common/serialization/vst2.h b/src/common/serialization/vst2.h index 813af163..0194d6ed 100644 --- a/src/common/serialization/vst2.h +++ b/src/common/serialization/vst2.h @@ -477,7 +477,7 @@ void serialize(S& s, EventResultPayload& payload) { /** * AN instance of this should be sent back as a response to an incoming event. */ -struct EventResult { +struct Vst2EventResult { /** * The result that should be returned from the dispatch function. */ diff --git a/src/plugin/bridges/vst2.cpp b/src/plugin/bridges/vst2.cpp index 7e696c19..ebeb7fdf 100644 --- a/src/plugin/bridges/vst2.cpp +++ b/src/plugin/bridges/vst2.cpp @@ -91,9 +91,9 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback) incoming_midi_events.push_back( std::get(event.payload)); - return EventResult{.return_value = 1, - .payload = nullptr, - .value_payload = std::nullopt}; + return Vst2EventResult{.return_value = 1, + .payload = nullptr, + .value_payload = std::nullopt}; } break; // REAPER requires that `audioMasterSizeWindow()` calls are // handled from the GUI thread, which is the thread that @@ -105,9 +105,9 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback) incoming_resize = std::pair(event.index, event.value); - return EventResult{.return_value = 1, - .payload = nullptr, - .value_payload = std::nullopt}; + return Vst2EventResult{.return_value = 1, + .payload = nullptr, + .value_payload = std::nullopt}; } break; // HACK: Certain plugins may have undesirable DAW-specific // behaviour. Chromaphone 3 for instance has broken @@ -125,9 +125,10 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback) std::string(product_name_override) + "\" instead of the actual host's name."); - return EventResult{.return_value = 1, - .payload = product_name_override, - .value_payload = std::nullopt}; + return Vst2EventResult{ + .return_value = 1, + .payload = product_name_override, + .value_payload = std::nullopt}; } } break; case audioMasterGetVendorString: { @@ -139,9 +140,10 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback) std::string(vendor_name_override) + "\" instead of the actual host's vendor."); - return EventResult{.return_value = 1, - .payload = vendor_name_override, - .value_payload = std::nullopt}; + return Vst2EventResult{ + .return_value = 1, + .payload = vendor_name_override, + .value_payload = std::nullopt}; } } break; } @@ -157,7 +159,7 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback) // over the `dispatcher()` socket. This would happen whenever the plugin // calls `audioMasterIOChanged()` and after the host calls `effOpen()`. const auto initialization_data = - sockets.host_vst_control.receive_single(); + sockets.host_vst_control.receive_single(); const auto initialized_plugin = std::get(initialization_data.payload); @@ -330,7 +332,7 @@ class DispatchDataConverter : public DefaultDataConverter { void write_data(const int opcode, void* data, - const EventResult& response) const override { + const Vst2EventResult& response) const override { switch (opcode) { case effOpen: { // Update our `AEffect` object one last time for improperly @@ -418,7 +420,7 @@ class DispatchDataConverter : public DefaultDataConverter { void write_value(const int opcode, intptr_t value, - const EventResult& response) const override { + const Vst2EventResult& response) const override { switch (opcode) { case effGetSpeakerArrangement: { // Same as the above, but now for the input speaker diff --git a/src/wine-host/bridges/vst2.cpp b/src/wine-host/bridges/vst2.cpp index 8e32a3d6..78ff9fd6 100644 --- a/src/wine-host/bridges/vst2.cpp +++ b/src/wine-host/bridges/vst2.cpp @@ -167,7 +167,7 @@ Vst2Bridge::Vst2Bridge(MainContext& 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()`. - sockets.host_vst_control.send(EventResult{ + sockets.host_vst_control.send(Vst2EventResult{ .return_value = 0, .payload = *plugin, .value_payload = std::nullopt}); // After sending the AEffect struct we'll receive this instance's @@ -385,9 +385,9 @@ void Vst2Bridge::run() { plugin, event.opcode, event.index, event.value, &events.as_c_events(), event.option); - EventResult response{.return_value = return_value, - .payload = nullptr, - .value_payload = std::nullopt}; + Vst2EventResult response{.return_value = return_value, + .payload = nullptr, + .value_payload = std::nullopt}; return response; } else { @@ -588,7 +588,7 @@ class HostCallbackDataConverter : public DefaultDataConverter { void write_data(const int opcode, void* data, - const EventResult& response) const override { + const Vst2EventResult& response) const override { switch (opcode) { case audioMasterGetTime: // If the host returned a valid `VstTimeInfo` object, then we'll @@ -624,12 +624,13 @@ class HostCallbackDataConverter : public DefaultDataConverter { void write_value(const int opcode, intptr_t value, - const EventResult& response) const override { + const Vst2EventResult& response) const override { return DefaultDataConverter::write_value(opcode, value, response); } - EventResult send_event(boost::asio::local::stream_protocol::socket& socket, - const Vst2Event& event) const override { + Vst2EventResult send_event( + boost::asio::local::stream_protocol::socket& socket, + const Vst2Event& event) const override { if (mutually_recursive_callbacks.contains(event.opcode)) { return mutual_recursion.fork([&]() { return DefaultDataConverter::send_event(socket, event);