Pass throug the VstEvents struct

This commit is contained in:
Robbert van der Helm
2020-03-08 20:29:40 +01:00
parent c5ea1e5153
commit 40142f801e
5 changed files with 34 additions and 23 deletions
+20 -15
View File
@@ -1,40 +1,45 @@
#include "communication.h" #include "communication.h"
intptr_t send_event(boost::asio::local::stream_protocol::socket& socket, intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
bool is_dispatch,
int opcode, int opcode,
int index, int index,
intptr_t value, intptr_t value,
void* data, void* data,
float option, float option,
std::optional<std::pair<Logger&, bool>> logging) { Logger* logger) {
// Encode the right payload type for this event. Check the documentation for // Encode the right payload type for this event. Check the documentation for
// `EventPayload` for more information. // `EventPayload` for more information.
EventPayload payload = nullptr; EventPayload payload = nullptr;
if (data != nullptr) { if (data != nullptr) {
// TODO: Specific structs go here // There are some events that need specific structs that we can't simply
// serialize as a string because they might contain null bytes
// Assume buffers are zeroed out, this is probably not the case if (is_dispatch && opcode == effProcessEvents) {
char* c_string = static_cast<char*>(data); payload = *static_cast<VstEvents*>(data);
if (c_string[0] != 0) {
payload = std::string(c_string);
} else { } else {
payload = NeedsBuffer{}; // TODO: More of these structs
// Assume buffers are zeroed out, this is probably not the case
char* c_string = static_cast<char*>(data);
if (c_string[0] != 0) {
payload = std::string(c_string);
} else {
payload = NeedsBuffer{};
}
} }
} }
if (logging.has_value()) { if (logger != nullptr) {
auto [logger, is_dispatch] = *logging; logger->log_event(is_dispatch, opcode, index, value, payload, option);
logger.log_event(is_dispatch, opcode, index, value, payload, option);
} }
const Event event{opcode, index, value, option, payload}; const Event event{opcode, index, value, option, payload};
write_object(socket, event); write_object(socket, event);
const auto response = read_object<EventResult>(socket); const auto response = read_object<EventResult>(socket);
if (logging.has_value()) { if (logger != nullptr) {
auto [logger, is_dispatch] = *logging; logger->log_event_response(is_dispatch, response.return_value,
logger.log_event_response(is_dispatch, response.return_value, response.data);
response.data);
} }
if (response.data.has_value()) { if (response.data.has_value()) {
char* output = static_cast<char*>(data); char* output = static_cast<char*>(data);
+9 -4
View File
@@ -125,19 +125,23 @@ inline T read_object(Socket& socket) {
* since they follow the same format. See one of those functions for details on * since they follow the same format. See one of those functions for details on
* the parameters and return value of this function. * the parameters and return value of this function.
* *
* @param logging A pair containing a logger instance and whether or not this is * @param is_dispatch whether or not this is for sending `dispatch()` events or
* for sending `dispatch()` events or host callbacks. Optional since it * host callbacks. Used for the serialization of opcode specific structs in
* doesn't have to be done on both sides. * the `dispatch()` function.
* @param logger A logger instance. Optional since it doesn't have to be done on
* both sides. Optional references are somehow not possible in C++17 things
* like `std::reference_wrapper`, so a raw pointer it is.
* *
* @relates passthrough_event * @relates passthrough_event
*/ */
intptr_t send_event(boost::asio::local::stream_protocol::socket& socket, intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
bool is_dispatch,
int opcode, int opcode,
int index, int index,
intptr_t value, intptr_t value,
void* data, void* data,
float option, float option,
std::optional<std::pair<Logger&, bool>> logging); Logger* logger);
/** /**
* Receive an event from a socket and pass it through to some callback function. * Receive an event from a socket and pass it through to some callback function.
@@ -176,6 +180,7 @@ void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
[&](const std::string& s) -> void* { [&](const std::string& s) -> void* {
return const_cast<char*>(s.c_str()); return const_cast<char*>(s.c_str());
}, },
// TODO: Check if the deserialization leaks memory
[&](VstEvents& events) -> void* { return &events; }, [&](VstEvents& events) -> void* { return &events; },
[&](NeedsBuffer&) -> void* { return buffer.data(); }}, [&](NeedsBuffer&) -> void* { return buffer.data(); }},
event.payload); event.payload);
+1
View File
@@ -135,6 +135,7 @@ struct Event {
// hence the assertion. If multiple events can be // hence the assertion. If multiple events can be
// passed at once then `VstEvents` should be // passed at once then `VstEvents` should be
// modified. // modified.
// TODO: This is definitely not the case, somehow fix this
assert(events.numEvents <= 1); assert(events.numEvents <= 1);
s.container( s.container(
events.events, [](S& s, VstEvent*(&event_ptr)) { events.events, [](S& s, VstEvent*(&event_ptr)) {
+2 -2
View File
@@ -167,8 +167,8 @@ intptr_t HostBridge::dispatch(AEffect* /*plugin*/,
break; break;
} }
return send_event(host_vst_dispatch, opcode, index, value, data, option, return send_event(host_vst_dispatch, true, opcode, index, value, data,
std::pair<Logger&, bool>(logger, true)); option, &logger);
} }
void HostBridge::process_replacing(AEffect* /*plugin*/, void HostBridge::process_replacing(AEffect* /*plugin*/,
+2 -2
View File
@@ -196,8 +196,8 @@ intptr_t PluginBridge::host_callback(AEffect* /*plugin*/,
intptr_t value, intptr_t value,
void* data, void* data,
float option) { float option) {
return send_event(vst_host_callback, opcode, index, value, data, option, return send_event(vst_host_callback, false, opcode, index, value, data,
std::nullopt); option, nullptr);
} }
intptr_t VST_CALL_CONV host_callback_proxy(AEffect* effect, intptr_t VST_CALL_CONV host_callback_proxy(AEffect* effect,