Use a thread for dispatch events

This commit is contained in:
Robbert van der Helm
2020-03-05 16:29:59 +01:00
parent 6c4dca151b
commit 814a3b40b5
6 changed files with 45 additions and 37 deletions
+9 -13
View File
@@ -95,10 +95,15 @@ HostBridge::HostBridge(audioMasterCallback host_callback)
plugin.getParameter = getParameter_proxy;
plugin.processReplacing = process_replacing_proxy;
// TODO: Replace manual thread creation with an async_read loop
// Start accepting host callbacks after we've set up our sockets and basic
// `AEffect` struct.
removeme = std::thread([&]() { return host_callback_loop(); });
// For our communication we use simple threads and blocking operations
// instead of asynchronous IO since communication has to be handled in
// lockstep anyway
host_callback_handler = std::thread([&]() {
while (true) {
passthrough_event(vst_host_callback, &plugin,
host_callback_function);
}
});
// Read the plugin's information from the Wine process. This can only be
// done after we started accepting host callbacks as the plugin might do
@@ -261,15 +266,6 @@ fs::path generate_endpoint_name() {
return candidate_endpoint;
}
// TODO: Replace blocking loop with async readers or threads for all of the
// sockets. Also extract this functionality somewhere since the host event
// callback needs to do exactly the same thing.
void HostBridge::host_callback_loop() {
while (true) {
passthrough_event(vst_host_callback, &plugin, host_callback_function);
}
}
/**
* Locate the wineprefix and set the `WINEPREFIX` environment variable if found.
* This way it's also possible to run .dll files outside of a wineprefix using
+5 -6
View File
@@ -21,7 +21,6 @@
#include <boost/asio/io_context.hpp>
#include <boost/asio/local/stream_protocol.hpp>
#include <boost/process/child.hpp>
// TODO: Remove
#include <thread>
/**
@@ -67,9 +66,6 @@ class HostBridge {
void set_parameter(AEffect* plugin, int32_t index, float value);
float get_parameter(AEffect* plugin, int32_t index);
// TODO: Remove debug loop
void host_callback_loop();
/**
* This AEffect struct will be populated using the data passed by the Wine
* VST host during initialization and then passed as a pointer to the Linux
@@ -96,12 +92,15 @@ class HostBridge {
*/
boost::asio::local::stream_protocol::socket vst_host_aeffect;
/**
* The thread that handles host callbacks.
*/
std::thread host_callback_handler;
/**
* The callback function passed by the host to the VST plugin instance.
*/
audioMasterCallback host_callback_function;
// TODO: Remove
std::thread removeme;
/**
* The Wine process hosting the Windows VST plugin.
*/