diff --git a/src/wine-host/bridges/common.cpp b/src/wine-host/bridges/common.cpp index 81bec63e..01bd6359 100644 --- a/src/wine-host/bridges/common.cpp +++ b/src/wine-host/bridges/common.cpp @@ -16,6 +16,9 @@ #include "common.h" +HostBridge::HostBridge(boost::filesystem::path plugin_path) + : plugin_path(plugin_path) {} + void HostBridge::handle_win32_events() { if (editor) { editor->handle_win32_events(); diff --git a/src/wine-host/bridges/common.h b/src/wine-host/bridges/common.h index 85eac4e1..eee60936 100644 --- a/src/wine-host/bridges/common.h +++ b/src/wine-host/bridges/common.h @@ -24,6 +24,9 @@ * will actually host a plugin and do all the function call forwarding. */ class HostBridge { + protected: + HostBridge(boost::filesystem::path plugin_path); + public: virtual ~HostBridge(){}; @@ -64,6 +67,11 @@ class HostBridge { */ void handle_win32_events(); + /** + * The path to the .dll being loaded in the Wine plugin host. + */ + const boost::filesystem::path plugin_path; + protected: /** * The plugin editor window. Allows embedding the plugin's editor into a diff --git a/src/wine-host/bridges/group.cpp b/src/wine-host/bridges/group.cpp index 25dc67bd..7c743e7c 100644 --- a/src/wine-host/bridges/group.cpp +++ b/src/wine-host/bridges/group.cpp @@ -108,7 +108,7 @@ GroupBridge::~GroupBridge() { void GroupBridge::handle_plugin_dispatch(size_t plugin_id) { // At this point the `active_plugins` map will already contain the // intialized plugin's `Vst2Bridge` instance and this thread's handle - Vst2Bridge* bridge; + HostBridge* bridge; { std::lock_guard lock(active_plugins_mutex); bridge = active_plugins[plugin_id].second.get(); @@ -117,7 +117,7 @@ void GroupBridge::handle_plugin_dispatch(size_t plugin_id) { // Blocks this thread until the plugin shuts down, handling all events on // the main IO context bridge->run(); - logger.log("'" + bridge->vst_plugin_path.string() + "' has exited"); + logger.log("'" + bridge->plugin_path.string() + "' has exited"); // After the plugin has exited we'll remove this thread's plugin from the // active plugins. This is done within the IO context because the call to @@ -181,9 +181,6 @@ void GroupBridge::accept_requests() { // yabridge plugin will be able to tell if the plugin has caused // this process to crash during its initialization to prevent // waiting indefinitely on the sockets to be connected to. - // TODO: Do something with the plugin type - // TODO: Maybe try to merge instantiation with `individual_host`? - // Might only make things messier const auto request = read_object(socket); write_object(socket, HostResponse{boost::this_process::get_id()}); @@ -196,9 +193,23 @@ void GroupBridge::accept_requests() { "' using socket endpoint base directory '" + request.endpoint_base_dir + "'"); try { - auto bridge = std::make_unique( - main_context, request.plugin_path, - request.endpoint_base_dir); + std::unique_ptr bridge = nullptr; + switch (request.plugin_type) { + case PluginType::vst2: + bridge = std::make_unique( + main_context, request.plugin_path, + request.endpoint_base_dir); + break; + case PluginType::vst3: + throw std::runtime_error("TODO: Not yet implemented"); + break; + case PluginType::unknown: + throw std::runtime_error( + "Invalid plugin host request received, how did you " + "even manage to do this?"); + break; + } + logger.log("Finished initializing '" + request.plugin_path + "'"); diff --git a/src/wine-host/bridges/group.h b/src/wine-host/bridges/group.h index 0313d249..a255f75e 100644 --- a/src/wine-host/bridges/group.h +++ b/src/wine-host/bridges/group.h @@ -252,7 +252,7 @@ class GroupBridge { * on `next_plugin_id`. */ std::unordered_map>> + std::pair>> active_plugins; /** * A counter for the next unique plugin ID. When hosting a new plugin we'll diff --git a/src/wine-host/bridges/vst2.cpp b/src/wine-host/bridges/vst2.cpp index 03bb7ca1..ac349839 100644 --- a/src/wine-host/bridges/vst2.cpp +++ b/src/wine-host/bridges/vst2.cpp @@ -69,7 +69,7 @@ Vst2Bridge& get_bridge_instance(const AEffect* plugin) { Vst2Bridge::Vst2Bridge(MainContext& main_context, std::string plugin_dll_path, std::string endpoint_base_dir) - : vst_plugin_path(plugin_dll_path), + : HostBridge(plugin_dll_path), main_context(main_context), plugin_handle(LoadLibrary(plugin_dll_path.c_str()), FreeLibrary), sockets(main_context.context, endpoint_base_dir, false) { diff --git a/src/wine-host/bridges/vst2.h b/src/wine-host/bridges/vst2.h index 65e719ea..5694010a 100644 --- a/src/wine-host/bridges/vst2.h +++ b/src/wine-host/bridges/vst2.h @@ -78,11 +78,6 @@ class Vst2Bridge : public HostBridge { */ std::optional time_info; - /** - * The path to the .dll being loaded in the Wine VST host. - */ - const boost::filesystem::path vst_plugin_path; - private: /** * A wrapper around `plugin->dispatcher` that handles the opening and