Create Vst3HostContextProxy from YaHostApplication

This is quite a huge refactor, but note everything is consistent (and
we're going to need one or two more of these `Vst3*Proxy` objects).
Right now nothing extends `IHostApplication`, but this way it will be
trivial to add support for more host context interfaces.
This commit is contained in:
Robbert van der Helm
2020-12-19 17:13:17 +01:00
parent c94089b832
commit 0522f84f4a
21 changed files with 301 additions and 184 deletions
+5 -3
View File
@@ -84,10 +84,11 @@ vst3_plugin_sources = [
'src/common/serialization/vst3/plugin/edit-controller-2.cpp', 'src/common/serialization/vst3/plugin/edit-controller-2.cpp',
'src/common/serialization/vst3/plugin/plugin-base.cpp', 'src/common/serialization/vst3/plugin/plugin-base.cpp',
'src/common/serialization/vst3/component-handler/component-handler.cpp', 'src/common/serialization/vst3/component-handler/component-handler.cpp',
'src/common/serialization/vst3/host-context/host-application.cpp',
'src/common/serialization/vst3/base.cpp', 'src/common/serialization/vst3/base.cpp',
'src/common/serialization/vst3/component-handler-proxy.cpp', 'src/common/serialization/vst3/component-handler-proxy.cpp',
'src/common/serialization/vst3/event-list.cpp', 'src/common/serialization/vst3/event-list.cpp',
'src/common/serialization/vst3/host-application.cpp', 'src/common/serialization/vst3/host-context-proxy.cpp',
'src/common/serialization/vst3/param-value-queue.cpp', 'src/common/serialization/vst3/param-value-queue.cpp',
'src/common/serialization/vst3/parameter-changes.cpp', 'src/common/serialization/vst3/parameter-changes.cpp',
'src/common/serialization/vst3/plugin-proxy.cpp', 'src/common/serialization/vst3/plugin-proxy.cpp',
@@ -131,17 +132,18 @@ if with_vst3
'src/common/serialization/vst3/plugin/edit-controller-2.cpp', 'src/common/serialization/vst3/plugin/edit-controller-2.cpp',
'src/common/serialization/vst3/plugin/plugin-base.cpp', 'src/common/serialization/vst3/plugin/plugin-base.cpp',
'src/common/serialization/vst3/component-handler/component-handler.cpp', 'src/common/serialization/vst3/component-handler/component-handler.cpp',
'src/common/serialization/vst3/host-context/host-application.cpp',
'src/common/serialization/vst3/base.cpp', 'src/common/serialization/vst3/base.cpp',
'src/common/serialization/vst3/component-handler-proxy.cpp', 'src/common/serialization/vst3/component-handler-proxy.cpp',
'src/common/serialization/vst3/event-list.cpp', 'src/common/serialization/vst3/event-list.cpp',
'src/common/serialization/vst3/host-application.cpp', 'src/common/serialization/vst3/host-context-proxy.cpp',
'src/common/serialization/vst3/param-value-queue.cpp', 'src/common/serialization/vst3/param-value-queue.cpp',
'src/common/serialization/vst3/parameter-changes.cpp', 'src/common/serialization/vst3/parameter-changes.cpp',
'src/common/serialization/vst3/plugin-proxy.cpp', 'src/common/serialization/vst3/plugin-proxy.cpp',
'src/common/serialization/vst3/plugin-factory.cpp', 'src/common/serialization/vst3/plugin-factory.cpp',
'src/common/serialization/vst3/process-data.cpp', 'src/common/serialization/vst3/process-data.cpp',
'src/wine-host/bridges/vst3-impls/component-handler-proxy.cpp', 'src/wine-host/bridges/vst3-impls/component-handler-proxy.cpp',
'src/wine-host/bridges/vst3-impls/host-application.cpp', 'src/wine-host/bridges/vst3-impls/host-context-proxy.cpp',
'src/wine-host/bridges/vst3.cpp', 'src/wine-host/bridges/vst3.cpp',
] ]
endif endif
+10 -4
View File
@@ -411,8 +411,8 @@ bool Vst3Logger::log_request(bool is_host_vst,
return log_request_base(is_host_vst, [&](auto& message) { return log_request_base(is_host_vst, [&](auto& message) {
message << request.instance_id message << request.instance_id
<< ": IPluginBase::initialize(context = "; << ": IPluginBase::initialize(context = ";
if (request.host_application_context_args) { if (request.host_context_args) {
message << "<IHostApplication*>"; message << "<FUnknown*>";
} else { } else {
message << "<nullptr>"; message << "<nullptr>";
} }
@@ -434,9 +434,15 @@ bool Vst3Logger::log_request(bool is_host_vst,
} }
bool Vst3Logger::log_request(bool is_host_vst, bool Vst3Logger::log_request(bool is_host_vst,
const YaPluginFactory::SetHostContext&) { const YaPluginFactory::SetHostContext& request) {
return log_request_base(is_host_vst, [&](auto& message) { return log_request_base(is_host_vst, [&](auto& message) {
message << "IPluginFactory3::setHostContext(IHostApplication*)"; message << "IPluginFactory3::setHostContext(";
if (request.host_context_args) {
message << "<FUnknown*>";
} else {
message << "<nullptr>";
}
message << ")";
}); });
} }
+1
View File
@@ -24,6 +24,7 @@
#include "../utils.h" #include "../utils.h"
#include "common.h" #include "common.h"
#include "vst3/component-handler-proxy.h" #include "vst3/component-handler-proxy.h"
#include "vst3/host-context-proxy.h"
#include "vst3/plugin-factory.h" #include "vst3/plugin-factory.h"
#include "vst3/plugin-proxy.h" #include "vst3/plugin-proxy.h"
+2 -1
View File
@@ -22,7 +22,8 @@ VST3 host interfaces are implemented as follows:
| yabridge class | Included in | Interfaces | | yabridge class | Included in | Interfaces |
| --------------------------- | --------------------------- | ------------------- | | --------------------------- | --------------------------- | ------------------- |
| `YaHostApplication` | | `IHostApplication` | | `Vst3HostContextProxy` | | All of the below: |
| `YaHostApplication` | `Vst3HostContextProxy` | `IHostApplication` |
| `Vst3ComponentHandlerProxy` | | All of the below: | | `Vst3ComponentHandlerProxy` | | All of the below: |
| `YaComponentHandler` | `Vst3ComponentHandlerProxy` | `IComponentHandler` | | `YaComponentHandler` | `Vst3ComponentHandlerProxy` | `IComponentHandler` |
@@ -0,0 +1,50 @@
// yabridge: a Wine VST bridge
// Copyright (C) 2020 Robbert van der Helm
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "host-context-proxy.h"
Vst3HostContextProxy::ConstructArgs::ConstructArgs() {}
Vst3HostContextProxy::ConstructArgs::ConstructArgs(
Steinberg::IPtr<Steinberg::FUnknown> object,
std::optional<size_t> owner_instance_id)
: owner_instance_id(owner_instance_id), host_application_args(object) {}
Vst3HostContextProxy::Vst3HostContextProxy(const ConstructArgs&& args)
: YaHostApplication(std::move(args.host_application_args)),
arguments(std::move(args)){FUNKNOWN_CTOR}
Vst3HostContextProxy::~Vst3HostContextProxy() {
FUNKNOWN_DTOR
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
IMPLEMENT_REFCOUNT(Vst3HostContextProxy)
#pragma GCC diagnostic pop
tresult PLUGIN_API
Vst3HostContextProxy::queryInterface(Steinberg::FIDString _iid, void** obj) {
if (YaHostApplication::supported()) {
QUERY_INTERFACE(_iid, obj, Steinberg::FUnknown::iid,
Steinberg::Vst::IHostApplication)
QUERY_INTERFACE(_iid, obj, Steinberg::Vst::IHostApplication::iid,
Steinberg::Vst::IHostApplication)
}
*obj = nullptr;
return Steinberg::kNoInterface;
}
@@ -16,42 +16,36 @@
#pragma once #pragma once
#include <type_traits>
#include <bitsery/ext/std_optional.h>
#include <bitsery/traits/string.h>
#include <pluginterfaces/vst/ivsthostapplication.h>
#include "../common.h" #include "../common.h"
#include "base.h" #include "host-context/host-application.h"
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
/** /**
* Wraps around `IHostApplication` for serialization purposes. An instance of * An abstract class that optionally implements all interfaces a `context`
* this proxy object will be initialized on the Wine plugin host side after the * object passed to `IPluginBase::intialize()` or
* host passes an actual instance to the plugin, and all function calls made to * `IPluginFactory3::setHostContext()` might implement. This works exactly the
* this proxy will be passed through to the actual object. This is used to proxy * same as `Vst3PluginProxy`, but instead of proxying for an object provided by
* both the host application context passed during `IPluginBase::intialize()` as * the plugin we are proxying for the `FUnknown*` argument passed to plugin by
* well as for the 'global' context in `IPluginFactory3::setHostContext()`. * the host. When we are proxying for a host context object passed to
* * `IPluginBase::initialize()` we'll keep track of the object instance ID the
* TODO: Create a `Vst3HostContextProxy`, and make this to only interface it * actual context object belongs to.
* inherits. For uniformity's sake it's a good idea to have every kind of
* object we directly instantiate be in the same form.
*/ */
class YaHostApplication : public Steinberg::Vst::IHostApplication { class Vst3HostContextProxy : public YaHostApplication {
public: public:
/** /**
* These are the arguments for constructing a `YaHostApplicationImpl`. * These are the arguments for constructing a
* `Vst3HostContextProxyImpl`.
*/ */
struct ConstructArgs { struct ConstructArgs {
ConstructArgs(); ConstructArgs();
/** /**
* Read arguments from an existing implementation. * Read from an existing object. We will try to mimic this object, so
* we'll support any interfaces this object also supports.
*/ */
ConstructArgs(Steinberg::IPtr<Steinberg::Vst::IHostApplication> context, ConstructArgs(Steinberg::IPtr<FUnknown> object,
std::optional<size_t> owner_instance_id); std::optional<size_t> owner_instance_id);
/** /**
@@ -61,10 +55,7 @@ class YaHostApplication : public Steinberg::Vst::IHostApplication {
*/ */
std::optional<native_size_t> owner_instance_id; std::optional<native_size_t> owner_instance_id;
/** YaHostApplication::ConstructArgs host_application_args;
* For `IHostApplication::getName`.
*/
std::optional<std::u16string> name;
template <typename S> template <typename S>
void serialize(S& s) { void serialize(S& s) {
@@ -72,10 +63,7 @@ class YaHostApplication : public Steinberg::Vst::IHostApplication {
[](S& s, native_size_t& instance_id) { [](S& s, native_size_t& instance_id) {
s.value8b(instance_id); s.value8b(instance_id);
}); });
s.ext(name, bitsery::ext::StdOptional{}, s.object(host_application_args);
[](S& s, std::u16string& name) {
s.text2b(name, std::extent_v<Steinberg::Vst::String128>);
});
} }
}; };
@@ -89,25 +77,27 @@ class YaHostApplication : public Steinberg::Vst::IHostApplication {
* objects they are passed to. If those objects get dropped, then the host * objects they are passed to. If those objects get dropped, then the host
* contexts should also be dropped. * contexts should also be dropped.
*/ */
YaHostApplication(const ConstructArgs&& args); Vst3HostContextProxy(const ConstructArgs&& args);
/** /**
* The lifetime of this object should be bound to the object we created it * The lifetime of this object should be bound to the object we created it
* for. When for instance the `Vst3PluginProxy` instance with id `n` gets * for. When for instance the `Vst3PluginProxy` instance with id `n` gets
* dropped, the corresponding `YaHostApplicationImpl` then that should also * dropped a corresponding `Vst3HostContextProxyImpl` should also be
* be dropped. * dropped.
*/ */
virtual ~YaHostApplication(); virtual ~Vst3HostContextProxy() = 0;
DECLARE_FUNKNOWN_METHODS DECLARE_FUNKNOWN_METHODS
// From `IHostApplication` /**
tresult PLUGIN_API getName(Steinberg::Vst::String128 name) override; * Get the instance ID of the owner of this object, if this is not the
virtual tresult PLUGIN_API createInstance(Steinberg::TUID cid, * global host context passed to the module's plugin factory.
Steinberg::TUID _iid, */
void** obj) override = 0; inline std::optional<size_t> owner_instance_id() const {
return arguments.owner_instance_id;
}
protected: private:
ConstructArgs arguments; ConstructArgs arguments;
}; };
@@ -19,37 +19,22 @@
YaHostApplication::ConstructArgs::ConstructArgs() {} YaHostApplication::ConstructArgs::ConstructArgs() {}
YaHostApplication::ConstructArgs::ConstructArgs( YaHostApplication::ConstructArgs::ConstructArgs(
Steinberg::IPtr<Steinberg::Vst::IHostApplication> context, Steinberg::IPtr<Steinberg::FUnknown> object)
std::optional<size_t> owner_instance_id) : supported(false) {
: owner_instance_id(owner_instance_id) { if (auto host_application =
Steinberg::Vst::String128 name_array; Steinberg::FUnknownPtr<Steinberg::Vst::IHostApplication>(object)) {
if (context->getName(name_array) == Steinberg::kResultOk) { supported = true;
name = tchar_pointer_to_u16string(name_array);
// `IHostApplication::getName`
Steinberg::Vst::String128 name_array;
if (host_application->getName(name_array) == Steinberg::kResultOk) {
name = tchar_pointer_to_u16string(name_array);
}
} }
} }
YaHostApplication::YaHostApplication(const ConstructArgs&& args) YaHostApplication::YaHostApplication(const ConstructArgs&& args)
: arguments(std::move(args)){FUNKNOWN_CTOR} : arguments(std::move(args)) {}
YaHostApplication::~YaHostApplication() {
FUNKNOWN_DTOR
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
IMPLEMENT_REFCOUNT(YaHostApplication)
#pragma GCC diagnostic pop
tresult PLUGIN_API YaHostApplication::queryInterface(Steinberg::FIDString _iid,
void** obj) {
QUERY_INTERFACE(_iid, obj, Steinberg::FUnknown::iid,
Steinberg::Vst::IHostApplication);
QUERY_INTERFACE(_iid, obj, Steinberg::Vst::IHostApplication::iid,
Steinberg::Vst::IHostApplication)
*obj = nullptr;
return Steinberg::kNoInterface;
}
tresult PLUGIN_API YaHostApplication::getName(Steinberg::Vst::String128 name) { tresult PLUGIN_API YaHostApplication::getName(Steinberg::Vst::String128 name) {
if (arguments.name) { if (arguments.name) {
@@ -0,0 +1,86 @@
// yabridge: a Wine VST bridge
// Copyright (C) 2020 Robbert van der Helm
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <type_traits>
#include <bitsery/ext/std_optional.h>
#include <bitsery/traits/string.h>
#include <pluginterfaces/vst/ivsthostapplication.h>
#include "../../common.h"
#include "../base.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
/**
* Wraps around `IHostApplication` for serialization purposes. This is
* instantiated as part of `Vst3HostContextProxy`.
*/
class YaHostApplication : public Steinberg::Vst::IHostApplication {
public:
/**
* These are the arguments for creating a `YaHostApplication`.
*/
struct ConstructArgs {
ConstructArgs();
/**
* Check whether an existing implementation implements
* `IHostApplication` and read arguments from it.
*/
ConstructArgs(Steinberg::IPtr<Steinberg::FUnknown> object);
/**
* Whether the object supported this interface.
*/
bool supported;
/**
* For `IHostApplication::getName`.
*/
std::optional<std::u16string> name;
template <typename S>
void serialize(S& s) {
s.value1b(supported);
s.ext(name, bitsery::ext::StdOptional{},
[](S& s, std::u16string& name) {
s.text2b(name, std::extent_v<Steinberg::Vst::String128>);
});
}
};
/**
* Instantiate this instance with arguments read from another interface
* implementation.
*/
YaHostApplication(const ConstructArgs&& args);
inline bool supported() const { return arguments.supported; }
tresult PLUGIN_API getName(Steinberg::Vst::String128 name) override;
virtual tresult PLUGIN_API createInstance(Steinberg::TUID cid,
Steinberg::TUID _iid,
void** obj) override = 0;
protected:
ConstructArgs arguments;
};
#pragma GCC diagnostic pop
@@ -41,7 +41,7 @@ YaPluginFactory::ConstructArgs::ConstructArgs(
} }
} }
auto factory2 = Steinberg::FUnknownPtr<Steinberg::IPluginFactory2>(factory); Steinberg::FUnknownPtr<Steinberg::IPluginFactory2> factory2(factory);
if (!factory2) { if (!factory2) {
return; return;
} }
@@ -56,7 +56,7 @@ YaPluginFactory::ConstructArgs::ConstructArgs(
} }
} }
auto factory3 = Steinberg::FUnknownPtr<Steinberg::IPluginFactory3>(factory); Steinberg::FUnknownPtr<Steinberg::IPluginFactory3> factory3(factory);
if (!factory3) { if (!factory3) {
return; return;
} }
+10 -8
View File
@@ -22,7 +22,7 @@
#include "../../bitsery/ext/vst3.h" #include "../../bitsery/ext/vst3.h"
#include "base.h" #include "base.h"
#include "host-application.h" #include "host-context-proxy.h"
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
@@ -155,20 +155,22 @@ class YaPluginFactory : public Steinberg::IPluginFactory3 {
/** /**
* Message to pass through a call to `IPluginFactory3::setHostContext()` to * Message to pass through a call to `IPluginFactory3::setHostContext()` to
* the Wine plugin host. A proxy `YaHostApplication` should be created on * the Wine plugin host. A `Vst3HostContextProxy` should be created on the
* the Wine plugin host and then passed as an argument to * Wine plugin host and then passed as an argument to
* `IPluginFactory3::setHostContext()`. If the host called * `IPluginFactory3::setHostContext()`.
* `IPluginFactory3::setHostContext()` with something other than an
* `IHostApplication*`, we return an error immediately and log the call.
*/ */
struct SetHostContext { struct SetHostContext {
using Response = UniversalTResult; using Response = UniversalTResult;
YaHostApplication::ConstructArgs host_application_context_args; /**
* Arguments for creating a proxy host context object. If we got passed
* an null pointer we'll reflect that.
*/
std::optional<Vst3HostContextProxy::ConstructArgs> host_context_args;
template <typename S> template <typename S>
void serialize(S& s) { void serialize(S& s) {
s.object(host_application_context_args); s.ext(host_context_args, bitsery::ext::StdOptional{});
} }
}; };
@@ -21,7 +21,6 @@
#include "../../common.h" #include "../../common.h"
#include "../base.h" #include "../base.h"
#include "../host-application.h"
#include "../process-data.h" #include "../process-data.h"
#pragma GCC diagnostic push #pragma GCC diagnostic push
@@ -19,10 +19,10 @@
YaComponent::ConstructArgs::ConstructArgs() {} YaComponent::ConstructArgs::ConstructArgs() {}
YaComponent::ConstructArgs::ConstructArgs( YaComponent::ConstructArgs::ConstructArgs(
Steinberg::IPtr<Steinberg::FUnknown> object) { Steinberg::IPtr<Steinberg::FUnknown> object)
auto component = Steinberg::FUnknownPtr<Steinberg::Vst::IComponent>(object); : supported(false) {
if (auto component =
if (component) { Steinberg::FUnknownPtr<Steinberg::Vst::IComponent>(object)) {
supported = true; supported = true;
// `IComponent::getControllerClassId` // `IComponent::getControllerClassId`
@@ -21,7 +21,7 @@
#include "../../common.h" #include "../../common.h"
#include "../base.h" #include "../base.h"
#include "../host-application.h" #include "../host-context-proxy.h"
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
@@ -66,23 +66,23 @@ class YaPluginBase : public Steinberg::IPluginBase {
/** /**
* Message to pass through a call to `IPluginBase::initialize()` to the Wine * Message to pass through a call to `IPluginBase::initialize()` to the Wine
* plugin host. if we pass an `IHostApplication` instance, then a proxy * plugin host. We will read what interfaces the passed context object
* `YaHostApplication` should be created and passed as an argument to * implements so we can then create a proxy object on the Wine side that the
* `IPluginBase::initialize()`. If this is absent a null pointer should be * plugin can use to make callbacks with. The lifetime of this
* passed. The lifetime of this `YaHostApplication` object should be bound * `Vst3HostContextProxy` object should be bound to the `IComponent` we are
* to the `IComponent` we are proxying. * proxying.
*/ */
struct Initialize { struct Initialize {
using Response = UniversalTResult; using Response = UniversalTResult;
native_size_t instance_id; native_size_t instance_id;
std::optional<YaHostApplication::ConstructArgs>
host_application_context_args; std::optional<Vst3HostContextProxy::ConstructArgs> host_context_args;
template <typename S> template <typename S>
void serialize(S& s) { void serialize(S& s) {
s.value8b(instance_id); s.value8b(instance_id);
s.ext(host_application_context_args, bitsery::ext::StdOptional{}); s.ext(host_context_args, bitsery::ext::StdOptional{});
} }
}; };
@@ -100,24 +100,21 @@ YaPluginFactoryImpl::createInstance(Steinberg::FIDString cid,
tresult PLUGIN_API tresult PLUGIN_API
YaPluginFactoryImpl::setHostContext(Steinberg::FUnknown* context) { YaPluginFactoryImpl::setHostContext(Steinberg::FUnknown* context) {
// This `context` will likely be an `IHostApplication`. If it is, we will // We will create a proxy object that that supports all the same interfaces
// store it for future calls, create a proxy object on the Wine side, and // as `context`, and then we'll store `context` in this object. We can then
// then pass it to the Windows VST3 plugin's plugin factory using the same // use it to handle callbacks made by the Windows VST3 plugin to this
// function. If we get passed anything else we'll just return instead since // context.
// there's nothing we can do with it. host_context = context;
host_application_context = context;
if (host_application_context) { std::optional<Vst3HostContextProxy::ConstructArgs> host_context_args{};
YaHostApplication::ConstructArgs host_application_context_args( if (host_context) {
host_application_context, std::nullopt); host_context_args =
Vst3HostContextProxy::ConstructArgs(host_context, std::nullopt);
return bridge.send_message(YaPluginFactory::SetHostContext{
.host_application_context_args =
std::move(host_application_context_args)});
} else { } else {
bridge.logger.log_unknown_interface( bridge.logger.log(
"In IPluginFactory3::setHostContext(), ignoring", "Null pointer passed to 'IPluginFactory3::setHostContext()'");
context ? std::optional(context->iid) : std::nullopt);
return Steinberg::kNotImplemented;
} }
return bridge.send_message(YaPluginFactory::SetHostContext{
.host_context_args = std::move(host_context_args)});
} }
@@ -32,9 +32,8 @@ class YaPluginFactoryImpl : public YaPluginFactory {
Vst3PluginBridge& bridge; Vst3PluginBridge& bridge;
/** /**
* An `IHostApplication` instance if we get one through * An host context if we get passed one through
* `IPluginFactory3::setHostContext()`. * `IPluginFactory3::setHostContext()`.
*/ */
Steinberg::FUnknownPtr<Steinberg::Vst::IHostApplication> Steinberg::IPtr<Steinberg::FUnknown> host_context;
host_application_context;
}; };
+18 -22
View File
@@ -315,18 +315,18 @@ Vst3PluginProxyImpl::setParamNormalized(Steinberg::Vst::ParamID id,
tresult PLUGIN_API Vst3PluginProxyImpl::setComponentHandler( tresult PLUGIN_API Vst3PluginProxyImpl::setComponentHandler(
Steinberg::Vst::IComponentHandler* handler) { Steinberg::Vst::IComponentHandler* handler) {
// We'll store the pointer for when the plugin later makes a callback to
// this component handler
component_handler = handler;
std::optional<Vst3ComponentHandlerProxy::ConstructArgs> std::optional<Vst3ComponentHandlerProxy::ConstructArgs>
component_handler_proxy_args = std::nullopt; component_handler_proxy_args = std::nullopt;
if (handler) { if (handler) {
// We'll store the pointer for when the plugin later makes a callback to
// this component handler
component_handler = handler;
component_handler_proxy_args = Vst3ComponentHandlerProxy::ConstructArgs( component_handler_proxy_args = Vst3ComponentHandlerProxy::ConstructArgs(
component_handler, instance_id()); component_handler, instance_id());
} else { } else {
bridge.logger.log( bridge.logger.log(
"Null pointer passed to 'IEditController::setComponentHandler'"); "Null pointer passed to 'IEditController::setComponentHandler()'");
} }
return bridge.send_message(YaEditController::SetComponentHandler{ return bridge.send_message(YaEditController::SetComponentHandler{
@@ -362,27 +362,23 @@ tresult PLUGIN_API Vst3PluginProxyImpl::openAboutBox(TBool onlyCheck) {
} }
tresult PLUGIN_API Vst3PluginProxyImpl::initialize(FUnknown* context) { tresult PLUGIN_API Vst3PluginProxyImpl::initialize(FUnknown* context) {
// This `context` will likely be an `IHostApplication`. If it is, we // We will create a proxy object that that supports all the same interfaces
// will store it here, and we'll proxy through all calls to it made from // as `context`, and then we'll store `context` in this object. We can then
// the Wine side. Otherwise we'll still call `IPluginBase::initialize()` // use it to handle callbacks made by the Windows VST3 plugin to this
// but with a null pointer instead. // context.
host_application_context = context; host_context = context;
std::optional<YaHostApplication::ConstructArgs> std::optional<Vst3HostContextProxy::ConstructArgs> host_context_args{};
host_application_context_args = std::nullopt; if (host_context) {
if (host_application_context) { host_context_args =
host_application_context_args = YaHostApplication::ConstructArgs( Vst3HostContextProxy::ConstructArgs(host_context, instance_id());
host_application_context, instance_id());
} else { } else {
bridge.logger.log_unknown_interface( bridge.logger.log("Null pointer passed to 'IPluginBase::initialize()'");
"In IPluginBase::initialize()",
context ? std::optional(context->iid) : std::nullopt);
} }
return bridge.send_message( return bridge.send_message(YaPluginBase::Initialize{
YaPluginBase::Initialize{.instance_id = instance_id(), .instance_id = instance_id(),
.host_application_context_args = .host_context_args = std::move(host_context_args)});
std::move(host_application_context_args)});
} }
tresult PLUGIN_API Vst3PluginProxyImpl::terminate() { tresult PLUGIN_API Vst3PluginProxyImpl::terminate() {
+9 -9
View File
@@ -122,15 +122,6 @@ class Vst3PluginProxyImpl : public Vst3PluginProxy {
tresult PLUGIN_API initialize(FUnknown* context) override; tresult PLUGIN_API initialize(FUnknown* context) override;
tresult PLUGIN_API terminate() override; tresult PLUGIN_API terminate() override;
/**
* An `IHostApplication` instance if we get one through
* `IPluginBase::initialize()`. This should be the same for all plugin
* instances so we should not have to store it here separately, but for the
* sake of correctness we will.
*/
Steinberg::FUnknownPtr<Steinberg::Vst::IHostApplication>
host_application_context;
/** /**
* The component handler the host passed to us during * The component handler the host passed to us during
* `IEditController::setComponentHandler()`. When the plugin makes a * `IEditController::setComponentHandler()`. When the plugin makes a
@@ -141,4 +132,13 @@ class Vst3PluginProxyImpl : public Vst3PluginProxy {
private: private:
Vst3PluginBridge& bridge; Vst3PluginBridge& bridge;
/**
* An host context if we get passed one through `IPluginBase::initialize()`.
* We'll read which interfaces it supports and we'll then create a proxy
* object that supports those same interfaces. This should be the same for
* all plugin instances so we should not have to store it here separately,
* but for the sake of correctness we will.
*/
Steinberg::IPtr<Steinberg::FUnknown> host_context;
}; };
@@ -14,24 +14,25 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "host-application.h" #include "host-context-proxy.h"
#include <iostream> #include <iostream>
YaHostApplicationImpl::YaHostApplicationImpl( Vst3HostContextProxyImpl::Vst3HostContextProxyImpl(
Vst3Bridge& bridge, Vst3Bridge& bridge,
YaHostApplication::ConstructArgs&& args) Vst3HostContextProxy::ConstructArgs&& args)
: YaHostApplication(std::move(args)), bridge(bridge) { : Vst3HostContextProxy(std::move(args)), bridge(bridge) {
// The lifecycle is thos object is managed together with that of the plugin // The lifecycle is thos object is managed together with that of the plugin
// object instance this belongs to // object instance instance this belongs to
} }
tresult PLUGIN_API tresult PLUGIN_API
YaHostApplicationImpl::queryInterface(const Steinberg::TUID _iid, void** obj) { Vst3HostContextProxyImpl::queryInterface(const Steinberg::TUID _iid,
void** obj) {
// I don't think it's expected of a host to implement multiple interfaces on // I don't think it's expected of a host to implement multiple interfaces on
// this object, so if we do get a call here it's important that it's logged // this object, so if we do get a call here it's important that it's logged
// TODO: Successful queries should also be logged // TODO: Successful queries should also be logged
const tresult result = YaHostApplication::queryInterface(_iid, obj); const tresult result = Vst3HostContextProxy::queryInterface(_iid, obj);
if (result != Steinberg::kResultOk) { if (result != Steinberg::kResultOk) {
std::cerr << "TODO: Implement unknown interface logging on Wine side" std::cerr << "TODO: Implement unknown interface logging on Wine side"
<< std::endl; << std::endl;
@@ -40,9 +41,10 @@ YaHostApplicationImpl::queryInterface(const Steinberg::TUID _iid, void** obj) {
return result; return result;
} }
tresult PLUGIN_API YaHostApplicationImpl::createInstance(Steinberg::TUID cid, tresult PLUGIN_API
Steinberg::TUID _iid, Vst3HostContextProxyImpl::createInstance(Steinberg::TUID cid,
void** obj) { Steinberg::TUID _iid,
void** obj) {
// TODO: Implement // TODO: Implement
std::cerr << "TODO: IHostApplication::createInstance()" << std::endl; std::cerr << "TODO: IHostApplication::createInstance()" << std::endl;
return Steinberg::kNotImplemented; return Steinberg::kNotImplemented;
@@ -18,10 +18,10 @@
#include "../vst3.h" #include "../vst3.h"
class YaHostApplicationImpl : public YaHostApplication { class Vst3HostContextProxyImpl : public Vst3HostContextProxy {
public: public:
YaHostApplicationImpl(Vst3Bridge& bridge, Vst3HostContextProxyImpl(Vst3Bridge& bridge,
YaHostApplication::ConstructArgs&& args); Vst3HostContextProxy::ConstructArgs&& args);
/** /**
* We'll override the query interface to log queries for interfaces we do * We'll override the query interface to log queries for interfaces we do
@@ -30,6 +30,7 @@ class YaHostApplicationImpl : public YaHostApplication {
tresult PLUGIN_API queryInterface(const Steinberg::TUID _iid, tresult PLUGIN_API queryInterface(const Steinberg::TUID _iid,
void** obj) override; void** obj) override;
// From `IHostApplication`
tresult PLUGIN_API createInstance(Steinberg::TUID cid, tresult PLUGIN_API createInstance(Steinberg::TUID cid,
Steinberg::TUID _iid, Steinberg::TUID _iid,
void** obj) override; void** obj) override;
+17 -16
View File
@@ -24,7 +24,7 @@
#include <public.sdk/source/vst/hosting/module_win32.cpp> #include <public.sdk/source/vst/hosting/module_win32.cpp>
#include "vst3-impls/component-handler-proxy.h" #include "vst3-impls/component-handler-proxy.h"
#include "vst3-impls/host-application.h" #include "vst3-impls/host-context-proxy.h"
InstanceInterfaces::InstanceInterfaces() {} InstanceInterfaces::InstanceInterfaces() {}
@@ -371,21 +371,19 @@ void Vst3Bridge::run() {
// `Vst3HostProxy` // `Vst3HostProxy`
// TODO: Does this have to be run from the UI thread? Figure out // TODO: Does this have to be run from the UI thread? Figure out
// if it does // if it does
if (request.host_application_context_args) { if (request.host_context_args) {
object_instances[request.instance_id] object_instances[request.instance_id].host_context_proxy =
.host_application_context = Steinberg::owned(new Vst3HostContextProxyImpl(
Steinberg::owned(new YaHostApplicationImpl( *this, std::move(*request.host_context_args)));
*this,
std::move(*request.host_application_context_args)));
} else { } else {
object_instances[request.instance_id] object_instances[request.instance_id].host_context_proxy =
.host_application_context = nullptr; nullptr;
} }
return object_instances[request.instance_id] return object_instances[request.instance_id]
.plugin_base->initialize( .plugin_base->initialize(
object_instances[request.instance_id] object_instances[request.instance_id]
.host_application_context); .host_context_proxy);
}, },
[&](const YaPluginBase::Terminate& request) [&](const YaPluginBase::Terminate& request)
-> YaPluginBase::Terminate::Response { -> YaPluginBase::Terminate::Response {
@@ -399,16 +397,19 @@ void Vst3Bridge::run() {
}, },
[&](YaPluginFactory::SetHostContext& request) [&](YaPluginFactory::SetHostContext& request)
-> YaPluginFactory::SetHostContext::Response { -> YaPluginFactory::SetHostContext::Response {
plugin_factory_host_application_context = if (request.host_context_args) {
Steinberg::owned(new YaHostApplicationImpl( plugin_factory_host_context =
*this, Steinberg::owned(new Vst3HostContextProxyImpl(
std::move(request.host_application_context_args))); *this, std::move(*request.host_context_args)));
} else {
plugin_factory_host_context = nullptr;
}
Steinberg::FUnknownPtr<Steinberg::IPluginFactory3> factory_3( Steinberg::FUnknownPtr<Steinberg::IPluginFactory3> factory_3(
module->getFactory().get()); module->getFactory().get());
assert(factory_3); assert(factory_3);
return factory_3->setHostContext( return factory_3->setHostContext(plugin_factory_host_context);
plugin_factory_host_application_context);
}}); }});
} }
+5 -6
View File
@@ -38,12 +38,12 @@ struct InstanceInterfaces {
InstanceInterfaces(Steinberg::IPtr<Steinberg::FUnknown> object); InstanceInterfaces(Steinberg::IPtr<Steinberg::FUnknown> object);
/** /**
* If the host passes an `IHostApplication` during * If the host passes a host context object during
* `IPluginBase::initialize()`, we'll store a proxy object here and then * `IPluginBase::initialize()`, we'll store a proxy object here and then
* pass it to `plugin_base->initialize()`. Will be initialized with a null * pass it to `plugin_base->initialize()`. Will be initialized with a null
* pointer until used. * pointer until used.
*/ */
Steinberg::IPtr<YaHostApplication> host_application_context; Steinberg::IPtr<Vst3HostContextProxy> host_context_proxy;
/** /**
* After a call to `IEditController::setComponentHandler()`, we'll create a * After a call to `IEditController::setComponentHandler()`, we'll create a
@@ -155,11 +155,10 @@ class Vst3Bridge : public HostBridge {
std::atomic_size_t current_instance_id; std::atomic_size_t current_instance_id;
/** /**
* The host application context proxy object if we got passed a host * The host context proxy object if we got passed a host context during a
* application context during a call to `IPluginFactory3::setHostContext()` * call to `IPluginFactory3::setHostContext()` by the host.
* by the host.
*/ */
Steinberg::IPtr<YaHostApplication> plugin_factory_host_application_context; Steinberg::IPtr<Vst3HostContextProxy> plugin_factory_host_context;
/** /**
* These are all the objects we have created through the Windows VST3 * These are all the objects we have created through the Windows VST3