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
+13 -8
View File
@@ -1,17 +1,23 @@
#include "communication.h"
intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
bool is_dispatch,
int opcode,
int index,
intptr_t value,
void* data,
float option,
std::optional<std::pair<Logger&, bool>> logging) {
Logger* logger) {
// Encode the right payload type for this event. Check the documentation for
// `EventPayload` for more information.
EventPayload payload = 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
if (is_dispatch && opcode == effProcessEvents) {
payload = *static_cast<VstEvents*>(data);
} else {
// TODO: More of these structs
// Assume buffers are zeroed out, this is probably not the case
char* c_string = static_cast<char*>(data);
@@ -21,19 +27,18 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
payload = NeedsBuffer{};
}
}
}
if (logging.has_value()) {
auto [logger, is_dispatch] = *logging;
logger.log_event(is_dispatch, opcode, index, value, payload, option);
if (logger != nullptr) {
logger->log_event(is_dispatch, opcode, index, value, payload, option);
}
const Event event{opcode, index, value, option, payload};
write_object(socket, event);
const auto response = read_object<EventResult>(socket);
if (logging.has_value()) {
auto [logger, is_dispatch] = *logging;
logger.log_event_response(is_dispatch, response.return_value,
if (logger != nullptr) {
logger->log_event_response(is_dispatch, response.return_value,
response.data);
}
if (response.data.has_value()) {
+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
* the parameters and return value of this function.
*
* @param logging A pair containing a logger instance and whether or not this is
* for sending `dispatch()` events or host callbacks. Optional since it
* doesn't have to be done on both sides.
* @param is_dispatch whether or not this is for sending `dispatch()` events or
* host callbacks. Used for the serialization of opcode specific structs in
* 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
*/
intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
bool is_dispatch,
int opcode,
int index,
intptr_t value,
void* data,
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.
@@ -176,6 +180,7 @@ void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
[&](const std::string& s) -> void* {
return const_cast<char*>(s.c_str());
},
// TODO: Check if the deserialization leaks memory
[&](VstEvents& events) -> void* { return &events; },
[&](NeedsBuffer&) -> void* { return buffer.data(); }},
event.payload);
+1
View File
@@ -135,6 +135,7 @@ struct Event {
// hence the assertion. If multiple events can be
// passed at once then `VstEvents` should be
// modified.
// TODO: This is definitely not the case, somehow fix this
assert(events.numEvents <= 1);
s.container(
events.events, [](S& s, VstEvent*(&event_ptr)) {
+2 -2
View File
@@ -167,8 +167,8 @@ intptr_t HostBridge::dispatch(AEffect* /*plugin*/,
break;
}
return send_event(host_vst_dispatch, opcode, index, value, data, option,
std::pair<Logger&, bool>(logger, true));
return send_event(host_vst_dispatch, true, opcode, index, value, data,
option, &logger);
}
void HostBridge::process_replacing(AEffect* /*plugin*/,
+2 -2
View File
@@ -196,8 +196,8 @@ intptr_t PluginBridge::host_callback(AEffect* /*plugin*/,
intptr_t value,
void* data,
float option) {
return send_event(vst_host_callback, opcode, index, value, data, option,
std::nullopt);
return send_event(vst_host_callback, false, opcode, index, value, data,
option, nullptr);
}
intptr_t VST_CALL_CONV host_callback_proxy(AEffect* effect,