Pass all events to the plugin

This commit is contained in:
Robbert van der Helm
2020-02-24 19:25:26 +01:00
parent b04353e88c
commit 3d12489e58
6 changed files with 64 additions and 27 deletions
+19 -5
View File
@@ -22,6 +22,13 @@
#include <msgpack.hpp> #include <msgpack.hpp>
#include <optional> #include <optional>
/**
* The maximum size in bytes of a string or buffer passed through a void pointer
* in one of the dispatch functions. This is used as a buffer size and also as a
* cutoff for checking if c-style strings behind a `char*` have changed.
*/
constexpr size_t max_string_size = 128;
/** /**
* An event as dispatched by the VST host. These events will get forwarded to * An event as dispatched by the VST host. These events will get forwarded to
* the VST host process running under Wine. The fields here mirror those * the VST host process running under Wine. The fields here mirror those
@@ -34,8 +41,15 @@ struct Event {
// dereferenced? // dereferenced?
intptr_t value; intptr_t value;
float option; float option;
/**
* The event dispatch function has a void pointer parameter that's used to
* either send string messages to the event (e.g. for `effCanDo`) or to
* write a string back into. This value will contain an (empty) string if
* the void* parameter for the dispatch function was not a null pointer.
*/
std::optional<std::string> data;
MSGPACK_DEFINE(opcode, parameter, value, option) MSGPACK_DEFINE(opcode, parameter, value, option, data)
}; };
/** /**
@@ -50,11 +64,11 @@ struct EventResult {
* If present, this should get written into the void pointer passed to the * If present, this should get written into the void pointer passed to the
* dispatch function. * dispatch function.
*/ */
std::optional<std::string> result; std::optional<std::string> data;
// TODO: Add missing return value fields; // TODO: Add missing return value fields;
MSGPACK_DEFINE(return_value, result) MSGPACK_DEFINE(return_value, data)
}; };
/** /**
@@ -89,9 +103,9 @@ inline void write_object(Socket& socket, const T& object) {
*/ */
template <typename T, typename Socket> template <typename T, typename Socket>
inline T read_object(Socket& socket) { inline T read_object(Socket& socket) {
// TODO: Reuse buffers // TODO: Reuse buffers, also this is way too large right now
// TODO: Use boost's buffers directly after switching to bitsery // TODO: Use boost's buffers directly after switching to bitsery
char buffer[65536]; char buffer[4096];
auto message_length = socket.receive(boost::asio::buffer(buffer)); auto message_length = socket.receive(boost::asio::buffer(buffer));
return msgpack::unpack(buffer, message_length).get().convert(); return msgpack::unpack(buffer, message_length).get().convert();
+10 -5
View File
@@ -76,7 +76,7 @@ intptr_t Bridge::dispatch(AEffect* /*plugin*/,
int32_t opcode, int32_t opcode,
int32_t parameter, int32_t parameter,
intptr_t value, intptr_t value,
void* result, void* data,
float option) { float option) {
// Some events need some extra handling // Some events need some extra handling
// TODO: Handle other things such as GUI itneraction // TODO: Handle other things such as GUI itneraction
@@ -97,13 +97,18 @@ intptr_t Bridge::dispatch(AEffect* /*plugin*/,
break; break;
} }
const Event event{opcode, parameter, value, option}; auto payload =
data == nullptr
? std::nullopt
: std::make_optional(std::string(static_cast<char*>(data)));
const Event event{opcode, parameter, value, option, payload};
write_object(host_vst_dispatch, event); write_object(host_vst_dispatch, event);
const auto response = read_object<EventResult>(host_vst_dispatch); const auto response = read_object<EventResult>(host_vst_dispatch);
if (response.result) { if (response.data.has_value()) {
std::copy(response.result->begin(), response.result->end(), std::copy(response.data->begin(), response.data->end(),
static_cast<char*>(result)); static_cast<char*>(data));
} }
return response.return_value; return response.return_value;
+1 -1
View File
@@ -52,7 +52,7 @@ class Bridge {
int32_t opcode, int32_t opcode,
int32_t parameter, int32_t parameter,
intptr_t value, intptr_t value,
void* result, void* data,
float option); float option);
void process(AEffect* plugin, void process(AEffect* plugin,
float** inputs, float** inputs,
+2 -2
View File
@@ -95,10 +95,10 @@ intptr_t dispatch(AEffect* plugin,
int32_t opcode, int32_t opcode,
int32_t parameter, int32_t parameter,
intptr_t value, intptr_t value,
void* result, void* data,
float option) { float option) {
return get_bridge_instance(*plugin).dispatch(plugin, opcode, parameter, return get_bridge_instance(*plugin).dispatch(plugin, opcode, parameter,
value, result, option); value, data, option);
} }
void process(AEffect* plugin, void process(AEffect* plugin,
+1
View File
@@ -34,6 +34,7 @@
#undef __WIN32__ #undef __WIN32__
#undef _WIN64 #undef _WIN64
#include <boost/algorithm/string/predicate.hpp>
#include <boost/asio/io_context.hpp> #include <boost/asio/io_context.hpp>
#include <boost/asio/local/stream_protocol.hpp> #include <boost/asio/local/stream_protocol.hpp>
#include <msgpack.hpp> #include <msgpack.hpp>
+31 -14
View File
@@ -59,12 +59,6 @@ int main(int argc, char* argv[]) {
// TODO: Check whether this returned a null pointer // TODO: Check whether this returned a null pointer
AEffect* plugin = vst_entry_point(host_callback); AEffect* plugin = vst_entry_point(host_callback);
// TODO: Check the spec, how large should this be?
std::vector<char> buffer(2048, 0);
plugin->dispatcher(plugin, effGetEffectName, 0, 0, buffer.data(), 0.0);
std::string plugin_title(buffer.data());
// Connect to the sockets for communication once the plugin has finished // Connect to the sockets for communication once the plugin has finished
// loading // loading
// TODO: The program should terminate gracefully when one of the sockets // TODO: The program should terminate gracefully when one of the sockets
@@ -85,18 +79,41 @@ int main(int argc, char* argv[]) {
// TODO: Remove debug, we're just reporting the plugin's name we retrieved // TODO: Remove debug, we're just reporting the plugin's name we retrieved
// above // above
std::array<char, max_string_size> buffer;
while (true) { while (true) {
auto event = read_object<Event>(host_vst_dispatch); auto event = read_object<Event>(host_vst_dispatch);
EventResult response; // The void pointer argument for the dispatch function is used for
if (event.opcode == effGetEffectName) { // either:
response.result = plugin_title; // - Not at all, in which case it will be a null pointer
response.return_value = 1; // - For passing strings as input to the event
} else { // - For providing a buffer for the event to write results back into
response.return_value = 0; char* payload = nullptr;
if (event.data.has_value()) {
// If the data parameter was an empty string, then we're going to
// pass a larger buffer to the dispatch function instead..
if (!event.data->empty()) {
payload = const_cast<char*>(event.data->c_str());
} else {
payload = buffer.data();
}
} }
write_object(host_vst_dispatch, response); const intptr_t return_value =
plugin->dispatcher(plugin, event.opcode, event.option,
event.parameter, payload, event.option);
// Only write back the value from `payload` if we were passed an empty
// buffer to write into
bool is_updated = event.data.has_value() && event.data->empty();
if (is_updated) {
EventResult response{return_value, payload};
write_object(host_vst_dispatch, response);
} else {
EventResult response{return_value, std::nullopt};
write_object(host_vst_dispatch, response);
}
} }
} }
@@ -105,7 +122,7 @@ intptr_t VST_CALL_CONV host_callback(AEffect* plugin,
int32_t opcode, int32_t opcode,
int32_t parameter, int32_t parameter,
intptr_t value, intptr_t value,
void* result, void* data,
float option) { float option) {
return 1; return 1;
} }