Implement IPlugView::attached()

This commit is contained in:
Robbert van der Helm
2020-12-19 23:31:41 +01:00
parent 49fc896d62
commit 09f6d93214
7 changed files with 90 additions and 4 deletions
+14
View File
@@ -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, bool Vst3Logger::log_request(bool is_host_vst,
const YaPluginBase::Initialize& request) { const YaPluginBase::Initialize& request) {
return log_request_base(is_host_vst, [&](auto& message) { return log_request_base(is_host_vst, [&](auto& message) {
+1
View File
@@ -110,6 +110,7 @@ class Vst3Logger {
bool log_request(bool is_host_vst, const YaEditController::CreateView&); bool log_request(bool is_host_vst, const YaEditController::CreateView&);
bool log_request(bool is_host_vst, bool log_request(bool is_host_vst,
const YaPlugView::IsPlatformTypeSupported&); 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::Initialize&);
bool log_request(bool is_host_vst, const YaPluginBase::Terminate&); bool log_request(bool is_host_vst, const YaPluginBase::Terminate&);
bool log_request(bool is_host_vst, const YaPluginFactory::Construct&); bool log_request(bool is_host_vst, const YaPluginFactory::Construct&);
+1
View File
@@ -93,6 +93,7 @@ using ControlRequest = std::variant<Vst3PlugViewProxy::Destruct,
YaEditController::SetComponentHandler, YaEditController::SetComponentHandler,
YaEditController::CreateView, YaEditController::CreateView,
YaPlugView::IsPlatformTypeSupported, YaPlugView::IsPlatformTypeSupported,
YaPlugView::Attached,
YaPluginBase::Initialize, YaPluginBase::Initialize,
YaPluginBase::Terminate, YaPluginBase::Terminate,
YaPluginFactory::Construct, YaPluginFactory::Construct,
@@ -84,6 +84,32 @@ class YaPlugView : public Steinberg::IPlugView {
virtual tresult PLUGIN_API virtual tresult PLUGIN_API
isPlatformTypeSupported(Steinberg::FIDString type) override = 0; isPlatformTypeSupported(Steinberg::FIDString type) override = 0;
/**
* Message to pass through a call to `IPlugView::attached(parent, type)` to
* the Wine plugin host. Like mentioned above we will substitute
* `kPlatformStringWin` for `kPlatformStringLinux`.
*/
struct Attached {
using Response = UniversalTResult;
native_size_t owner_instance_id;
/**
* The parent handle passed by the host. This will be an
* `xcb_window_id`, and we'll embed the Wine window into it ourselves.
*/
native_size_t parent;
std::string type;
template <typename S>
void serialize(S& s) {
s.value8b(owner_instance_id);
s.value8b(parent);
s.text1b(type, 128);
}
};
virtual tresult PLUGIN_API attached(void* parent, virtual tresult PLUGIN_API attached(void* parent,
Steinberg::FIDString type) override = 0; Steinberg::FIDString type) override = 0;
virtual tresult PLUGIN_API removed() override = 0; virtual tresult PLUGIN_API removed() override = 0;
@@ -50,9 +50,12 @@ Vst3PlugViewProxyImpl::isPlatformTypeSupported(Steinberg::FIDString type) {
tresult PLUGIN_API Vst3PlugViewProxyImpl::attached(void* parent, tresult PLUGIN_API Vst3PlugViewProxyImpl::attached(void* parent,
Steinberg::FIDString type) { Steinberg::FIDString type) {
// TODO: Implement // We will embed the Wine Win32 window into the X11 window provided by the
bridge.logger.log("TODO: IPlugView::attached()"); // host
return Steinberg::kNotImplemented; return bridge.send_message(
YaPlugView::Attached{.owner_instance_id = owner_instance_id(),
.parent = reinterpret_cast<native_size_t>(parent),
.type = type});
} }
tresult PLUGIN_API Vst3PlugViewProxyImpl::removed() { tresult PLUGIN_API Vst3PlugViewProxyImpl::removed() {
+36 -1
View File
@@ -102,7 +102,7 @@ void Vst3Bridge::run() {
std::lock_guard lock(object_instances_mutex); std::lock_guard lock(object_instances_mutex);
const size_t instance_id = generate_instance_id(); 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 // This is where the magic happens. Here we deduce which
// interfaces are supported by this object so we can create // interfaces are supported by this object so we can create
@@ -411,6 +411,41 @@ void Vst3Bridge::run() {
return object_instances[request.owner_instance_id] return object_instances[request.owner_instance_id]
.plug_view->isPlatformTypeSupported(type.c_str()); .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<size_t>(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& request)
-> YaPluginBase::Initialize::Response { -> YaPluginBase::Initialize::Response {
// If we got passed a host context, we'll create a proxy object // If we got passed a host context, we'll create a proxy object
+6
View File
@@ -70,6 +70,12 @@ struct InstanceInterfaces {
*/ */
Steinberg::IPtr<Steinberg::IPlugView> plug_view; Steinberg::IPtr<Steinberg::IPlugView> 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> editor;
// All smart pointers below are created from `component`. They will be null // All smart pointers below are created from `component`. They will be null
// pointers if `component` did not implement the interface. // pointers if `component` did not implement the interface.