From 168568ed51e4a650f29a0ed3ece687b246932056 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 18 Mar 2020 23:51:53 +0100 Subject: [PATCH] Move the wrapper around the dispatch function --- src/wine-host/plugin-bridge.cpp | 63 ++++++++++++++++++--------------- src/wine-host/plugin-bridge.h | 11 ++++++ 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/wine-host/plugin-bridge.cpp b/src/wine-host/plugin-bridge.cpp index 8bc0b725..c0b2437e 100644 --- a/src/wine-host/plugin-bridge.cpp +++ b/src/wine-host/plugin-bridge.cpp @@ -122,35 +122,12 @@ PluginBridge::PluginBridge(std::string plugin_dll_path, // instead of asynchronous IO since communication has to be handled in // lockstep anyway dispatch_handler = std::thread([&]() { + using namespace std::placeholders; + while (true) { - passthrough_event( - host_vst_dispatch, std::nullopt, plugin, - [&](AEffect* plugin, int opcode, int index, intptr_t value, - void* data, float option) -> intptr_t { - // TODO: editEffClose - // We have to intercept GUI open calls since we can't use - // the X11 window handle passed by the host - if (opcode == effEditOpen) { - const auto win32_handle = editor.open(); - - // The plugin will return 0 if it can not open its - // editor window (or if it does not support it, but in - // that case the DAW should be hiding the option) - const intptr_t return_value = plugin->dispatcher( - plugin, opcode, index, value, win32_handle, option); - if (return_value == 0) { - return 0; - } - - const auto x11_handle = reinterpret_cast(data); - editor.embed_into(x11_handle); - - return return_value; - } - - return plugin->dispatcher(plugin, opcode, index, value, - data, option); - }); + passthrough_event(host_vst_dispatch, std::nullopt, plugin, + std::bind(&PluginBridge::dispatch_wrapper, this, + _1, _2, _3, _4, _5, _6)); } }); @@ -212,6 +189,36 @@ PluginBridge::PluginBridge(std::string plugin_dll_path, << std::endl; } +intptr_t PluginBridge::dispatch_wrapper(AEffect* plugin, + int opcode, + int index, + intptr_t value, + void* data, + float option) { + // TODO: editEffClose + // We have to intercept GUI open calls since we can't use + // the X11 window handle passed by the host + if (opcode == effEditOpen) { + const auto win32_handle = editor.open(); + + // The plugin will return 0 if it can not open its + // editor window (or if it does not support it, but in + // that case the DAW should be hiding the option) + const intptr_t return_value = plugin->dispatcher( + plugin, opcode, index, value, win32_handle, option); + if (return_value == 0) { + return 0; + } + + const auto x11_handle = reinterpret_cast(data); + editor.embed_into(x11_handle); + + return return_value; + } + + return plugin->dispatcher(plugin, opcode, index, value, data, option); +} + void PluginBridge::wait() { dispatch_handler.join(); parameters_handler.join(); diff --git a/src/wine-host/plugin-bridge.h b/src/wine-host/plugin-bridge.h index f88a3ebb..ac6fc697 100644 --- a/src/wine-host/plugin-bridge.h +++ b/src/wine-host/plugin-bridge.h @@ -68,6 +68,17 @@ class PluginBridge { VstTimeInfo time_info; private: + /** + * A wrapper around `plugin->dispatcher` that handles the opening and + * closing of GUIs. + */ + intptr_t dispatch_wrapper(AEffect* plugin, + int opcode, + int index, + intptr_t value, + void* data, + float option); + /** * The shared library handle of the VST plugin. I sadly could not get * Boost.DLL to work here, so we'll just load the VST plugisn by hand.