diff --git a/src/common/communication.h b/src/common/communication.h index 34ba7379..309d9147 100644 --- a/src/common/communication.h +++ b/src/common/communication.h @@ -145,13 +145,11 @@ class DefaultDataConverter { } /** - * Write the reponse back to the data pointer. It's also possible to - * override the return value, this is used in one place to return a pointer - * to a `VstTime` object that's contantly being updated. + * Write the reponse back to the data pointer. */ - virtual std::optional write(const int /*opcode*/, - void* data, - const EventResult& response) { + virtual void write(const int /*opcode*/, + void* data, + const EventResult& response) { if (response.data.has_value()) { char* output = static_cast(data); @@ -162,8 +160,20 @@ class DefaultDataConverter { std::copy(response.data->begin(), response.data->end(), output); output[response.data->size()] = 0; } + } - return std::nullopt; + /** + * This function can override a callback's return value based on the opcode. + * This is used in one place to return a pointer to a `VstTime` object + * that's contantly being updated. + * + * @param opcode The opcode for the current event. + * @param original The original return value as returned by the callback + * function. + */ + virtual intptr_t return_value(const int /*opcode*/, + const intptr_t original) { + return original; } }; @@ -221,13 +231,9 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket, response.data); } - const auto return_value_override = - data_converter.write(opcode, data, response); - if (return_value_override.has_value()) { - return return_value_override.value(); - } + data_converter.write(opcode, data, response); - return response.return_value; + return data_converter.return_value(opcode, response.return_value); } /** diff --git a/src/plugin/host-bridge.cpp b/src/plugin/host-bridge.cpp index cc4ceecd..2032f6b7 100644 --- a/src/plugin/host-bridge.cpp +++ b/src/plugin/host-bridge.cpp @@ -182,9 +182,7 @@ class DispatchDataConverter : DefaultDataConverter { } } - std::optional write(const int opcode, - void* data, - const EventResult& response) { + void write(const int opcode, void* data, const EventResult& response) { switch (opcode) { case effGetChunk: // Write the chunk data to some publically accessible place in @@ -194,14 +192,17 @@ class DispatchDataConverter : DefaultDataConverter { chunk.assign(response.data->begin(), response.data->end()); *static_cast(data) = chunk.data(); - return std::nullopt; break; default: - return DefaultDataConverter::write(opcode, data, response); + DefaultDataConverter::write(opcode, data, response); break; } } + intptr_t return_value(const int opcode, const intptr_t original) { + return DefaultDataConverter::return_value(opcode, original); + } + private: std::vector& chunk; }; diff --git a/src/wine-host/plugin-bridge.cpp b/src/wine-host/plugin-bridge.cpp index ce5e0280..5813dca8 100644 --- a/src/wine-host/plugin-bridge.cpp +++ b/src/wine-host/plugin-bridge.cpp @@ -221,22 +221,31 @@ class HostCallbackDataConverter : DefaultDataConverter { } } - std::optional write(const int opcode, - void* data, - const EventResult& response) { + void write(const int opcode, void* data, const EventResult& response) { switch (opcode) { case audioMasterGetTime: // Write the returned `VstTimeInfo` struct into a field and make - // the function return a poitner to it + // the function return a poitner to it in the function below // TODO: Start a time to update this on the host bridge once // it's been requested. Not sure if this is needed though! time = *static_cast( static_cast(response.data->data())); + break; + default: + DefaultDataConverter::write(opcode, data, response); + break; + } + } + intptr_t return_value(const int opcode, const intptr_t original) { + switch (opcode) { + case audioMasterGetTime: + // Return a pointer to the `VstTimeInfo` object written in the + // function above return reinterpret_cast(&time); break; default: - return DefaultDataConverter::write(opcode, data, response); + return DefaultDataConverter::return_value(opcode, original); break; } }