From 09f6d932141862e4228615a8ff8ff944e3f8113f Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 19 Dec 2020 23:31:41 +0100 Subject: [PATCH] Implement IPlugView::attached() --- src/common/logging/vst3.cpp | 14 +++++++ src/common/logging/vst3.h | 1 + src/common/serialization/vst3.h | 1 + .../serialization/vst3/plug-view/plug-view.h | 26 +++++++++++++ .../bridges/vst3-impls/plug-view-proxy.cpp | 9 +++-- src/wine-host/bridges/vst3.cpp | 37 ++++++++++++++++++- src/wine-host/bridges/vst3.h | 6 +++ 7 files changed, 90 insertions(+), 4 deletions(-) diff --git a/src/common/logging/vst3.cpp b/src/common/logging/vst3.cpp index a4048bfc..cec028f2 100644 --- a/src/common/logging/vst3.cpp +++ b/src/common/logging/vst3.cpp @@ -447,6 +447,20 @@ bool Vst3Logger::log_request( }); } +bool Vst3Logger::log_request(bool is_host_vst, + const YaPlugView::Attached& request) { + return log_request_base(is_host_vst, [&](auto& message) { + message << request.owner_instance_id + << ": IPlugView::attached(parent = " << request.parent + << ", type = \"" << request.type; + if (request.type == Steinberg::kPlatformTypeX11EmbedWindowID) { + message << "\" (will be translated to \"" + << Steinberg::kPlatformTypeHWND << "\")"; + } + message << ")"; + }); +} + bool Vst3Logger::log_request(bool is_host_vst, const YaPluginBase::Initialize& request) { return log_request_base(is_host_vst, [&](auto& message) { diff --git a/src/common/logging/vst3.h b/src/common/logging/vst3.h index 1cbff659..68f7c9ed 100644 --- a/src/common/logging/vst3.h +++ b/src/common/logging/vst3.h @@ -110,6 +110,7 @@ class Vst3Logger { bool log_request(bool is_host_vst, const YaEditController::CreateView&); bool log_request(bool is_host_vst, const YaPlugView::IsPlatformTypeSupported&); + bool log_request(bool is_host_vst, const YaPlugView::Attached&); bool log_request(bool is_host_vst, const YaPluginBase::Initialize&); bool log_request(bool is_host_vst, const YaPluginBase::Terminate&); bool log_request(bool is_host_vst, const YaPluginFactory::Construct&); diff --git a/src/common/serialization/vst3.h b/src/common/serialization/vst3.h index 4a6ee6e0..697c5dba 100644 --- a/src/common/serialization/vst3.h +++ b/src/common/serialization/vst3.h @@ -93,6 +93,7 @@ using ControlRequest = std::variant + void serialize(S& s) { + s.value8b(owner_instance_id); + s.value8b(parent); + s.text1b(type, 128); + } + }; + virtual tresult PLUGIN_API attached(void* parent, Steinberg::FIDString type) override = 0; virtual tresult PLUGIN_API removed() override = 0; diff --git a/src/plugin/bridges/vst3-impls/plug-view-proxy.cpp b/src/plugin/bridges/vst3-impls/plug-view-proxy.cpp index ea30b644..0976c3a5 100644 --- a/src/plugin/bridges/vst3-impls/plug-view-proxy.cpp +++ b/src/plugin/bridges/vst3-impls/plug-view-proxy.cpp @@ -50,9 +50,12 @@ Vst3PlugViewProxyImpl::isPlatformTypeSupported(Steinberg::FIDString type) { tresult PLUGIN_API Vst3PlugViewProxyImpl::attached(void* parent, Steinberg::FIDString type) { - // TODO: Implement - bridge.logger.log("TODO: IPlugView::attached()"); - return Steinberg::kNotImplemented; + // We will embed the Wine Win32 window into the X11 window provided by the + // host + return bridge.send_message( + YaPlugView::Attached{.owner_instance_id = owner_instance_id(), + .parent = reinterpret_cast(parent), + .type = type}); } tresult PLUGIN_API Vst3PlugViewProxyImpl::removed() { diff --git a/src/wine-host/bridges/vst3.cpp b/src/wine-host/bridges/vst3.cpp index 5498c796..ecf91f48 100644 --- a/src/wine-host/bridges/vst3.cpp +++ b/src/wine-host/bridges/vst3.cpp @@ -102,7 +102,7 @@ void Vst3Bridge::run() { std::lock_guard lock(object_instances_mutex); const size_t instance_id = generate_instance_id(); - object_instances[instance_id] = std::move(object); + object_instances.emplace(instance_id, std::move(object)); // This is where the magic happens. Here we deduce which // interfaces are supported by this object so we can create @@ -411,6 +411,41 @@ void Vst3Bridge::run() { return object_instances[request.owner_instance_id] .plug_view->isPlatformTypeSupported(type.c_str()); }, + [&](const YaPlugView::Attached& request) + -> YaPlugView::Attached::Response { + const std::string type = + request.type == Steinberg::kPlatformTypeX11EmbedWindowID + ? Steinberg::kPlatformTypeHWND + : request.type; + + // Just like with VST2 plugins, we'll embed a Wine window into + // the X11 window provided by the host + // TODO: The docs say that we should support XEmbed (and we're + // purposely avoiding that because Wine's implementation + // doesn't work correctly). Check if this causes issues, + // and if it's actually needed (for instance when the host + // resizes the window without informing the plugin) + const auto x11_handle = static_cast(request.parent); + const std::string window_class = + "yabridge plugin " + sockets.base_dir.string() + " " + + std::to_string(request.owner_instance_id); + Editor& editor_instance = + object_instances[request.owner_instance_id].editor.emplace( + config, window_class, x11_handle); + + const tresult result = + object_instances[request.owner_instance_id] + .plug_view->attached(editor_instance.get_win32_handle(), + type.c_str()); + + // Get rid of the editor again if the plugin didn't embed itself + // in it + if (result != Steinberg::kResultOk) { + object_instances[request.owner_instance_id].editor.reset(); + } + + return result; + }, [&](YaPluginBase::Initialize& request) -> YaPluginBase::Initialize::Response { // If we got passed a host context, we'll create a proxy object diff --git a/src/wine-host/bridges/vst3.h b/src/wine-host/bridges/vst3.h index 096899c6..026ceb53 100644 --- a/src/wine-host/bridges/vst3.h +++ b/src/wine-host/bridges/vst3.h @@ -70,6 +70,12 @@ struct InstanceInterfaces { */ Steinberg::IPtr plug_view; + /** + * This instance's editor, if it has an open editor. Embedding here works + * exactly the same as how it works for VST2 plugins. + */ + std::optional editor; + // All smart pointers below are created from `component`. They will be null // pointers if `component` did not implement the interface.