diff --git a/src/common/communication/vst3.h b/src/common/communication/vst3.h index 89bf0601..4b2c783e 100644 --- a/src/common/communication/vst3.h +++ b/src/common/communication/vst3.h @@ -178,7 +178,7 @@ class Vst3MessageHandler : public AdHocSocketHandler { request); } - const auto response = callback(request); + const auto& response = callback(request); if (logging) { auto [logger, is_host_vst] = *logging; logger.log_response(!is_host_vst, response); diff --git a/src/common/serialization/vst3.h b/src/common/serialization/vst3.h index 1654d6e9..e6880d76 100644 --- a/src/common/serialization/vst3.h +++ b/src/common/serialization/vst3.h @@ -50,7 +50,9 @@ struct WantsConfiguration { * copy of the hosted Windows VST3 plugin's `IPluginFactory{,2,3}` interface. */ struct WantsPluginFactory { - using Response = YaPluginFactory; + // TODO: Some things had to be changed to use references since this is an + // abstract class. Check if nothing breaks. + using Response = YaPluginFactory&; }; /** diff --git a/src/plugin/vst3-plugin.cpp b/src/plugin/vst3-plugin.cpp index c2a26050..5bb17f84 100644 --- a/src/plugin/vst3-plugin.cpp +++ b/src/plugin/vst3-plugin.cpp @@ -73,6 +73,10 @@ SMTG_EXPORT_SYMBOL Steinberg::IPluginFactory* PLUGIN_API GetPluginFactory() { // The host should have called `InitModule()` first assert(bridge); + // TODO: I think there is a flag that indicates that the class configuration + // may change, but I don't remember if it's at runtime or every time + // the module is loaded. If it's the former then this will take some + // special handling. return bridge->plugin_factory.get(); // TODO: In the normal implementation of this function they manually call diff --git a/src/wine-host/bridges/vst3.cpp b/src/wine-host/bridges/vst3.cpp index 385e8009..9920bf2c 100644 --- a/src/wine-host/bridges/vst3.cpp +++ b/src/wine-host/bridges/vst3.cpp @@ -36,6 +36,11 @@ Vst3Bridge::Vst3Bridge(MainContext& main_context, sockets.connect(); + // Serialize the plugin's plugin factory. The native VST3 plugin will + // request a copy of this during its initialization. + plugin_factory = + std::make_unique(module->getFactory().get()); + // Fetch this instance's configuration from the plugin to finish the setup // process config = sockets.vst_host_callback.send_message(WantsConfiguration{}, @@ -43,18 +48,12 @@ Vst3Bridge::Vst3Bridge(MainContext& main_context, } void Vst3Bridge::run() { - // TODO: Remove, this is just for type checking - if (false) { - boost::asio::local::stream_protocol::socket* socket; - Steinberg::IPtr factory; - YaPluginFactoryHostImpl object(factory); - write_object(*socket, object); - } - - // TODO: Handle events - // sockets.host_vst_control.receive_messages( - // std::nullopt, [&](ControlRequest request) -> ControlResponse { - // }); - - std::cerr << "TODO: Not yet implemented" << std::endl; + sockets.host_vst_control.receive_messages( + std::nullopt, [&](ControlRequest request) -> auto& { + return std::visit(overload{[&](const WantsPluginFactory&) + -> WantsPluginFactory::Response { + return *plugin_factory; + }}, + request); + }); } diff --git a/src/wine-host/bridges/vst3.h b/src/wine-host/bridges/vst3.h index bb9e4804..c5f52d5c 100644 --- a/src/wine-host/bridges/vst3.h +++ b/src/wine-host/bridges/vst3.h @@ -83,4 +83,11 @@ class Vst3Bridge : public HostBridge { * threads to exit. */ Vst3Sockets sockets; + + /** + * A plugin factory copied from the Windows VST3 plugin during + * initialization. The native VST3 plugin will request a copy of this + * information during its initialization. + */ + std::unique_ptr plugin_factory; };