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
+11 -7
View File
@@ -108,15 +108,19 @@ PluginBridge::PluginBridge(std::string plugin_dll_path,
// We only needed this little hack during initialization
current_bridge_isntance = nullptr;
plugin->ptr1 = this;
// For our communication we use simple threads and blocking operations
// instead of asynchronous IO since communication has to be handled in
// lockstep anyway
dispatch_handler = std::thread([&]() {
while (true) {
passthrough_event(host_vst_dispatch, plugin, plugin->dispatcher);
}
});
}
// 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 PluginBridge::dispatch_loop() {
while (true) {
passthrough_event(host_vst_dispatch, plugin, plugin->dispatcher);
}
void PluginBridge::wait() {
dispatch_handler.join();
}
intptr_t PluginBridge::host_callback(AEffect* /*plugin*/,
+14 -5
View File
@@ -24,6 +24,8 @@
#include <vestige/aeffect.h>
#include <windows.h>
#include <thread>
/**
* This handles the communication between the Linux native VST plugin and the
* Wine VST host. The functions below should be used as callback functions in an
@@ -45,13 +47,13 @@ class PluginBridge {
*/
PluginBridge(std::string plugin_dll_path, std::string socket_endpoint_path);
/**
* Block the main thread until the plugin shuts down.
*/
void wait();
intptr_t host_callback(AEffect*, int32_t, int32_t, intptr_t, void*, float);
// TODO: Remove debug loop
void dispatch_loop();
// TODO: Set up all callback handlers
private:
/**
* The shared library handle of the VST plugin. I sadly could not get
@@ -82,4 +84,11 @@ class PluginBridge {
* pass the Wine plugin's information to the host.
*/
boost::asio::local::stream_protocol::socket vst_host_aeffect;
/**
* The thread that handles dispatch events from the host.
*/
std::thread dispatch_handler;
// TODO: Set up all other callback handlers
};
+3 -3
View File
@@ -33,10 +33,10 @@ int main(int argc, char* argv[]) {
const std::string socket_endpoint_path(argv[2]);
try {
PluginBridge Pluginbridge(plugin_dll_path, socket_endpoint_path);
PluginBridge bridge(plugin_dll_path, socket_endpoint_path);
// TODO: Remove debug
Pluginbridge.dispatch_loop();
// Block the main thread until the plugin shuts down
bridge.wait();
} catch (const std::runtime_error& error) {
std::cerr << "Error while initializing plugin:" << std::endl;
std::cerr << error.what() << std::endl;