mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-16 05:33:07 +02:00
Use a thread for dispatch events
This commit is contained in:
@@ -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*/,
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user