Refactor plugin factories into Vst3*Proxy format

Now every proxy object that's directly created by the host or plugin
shares the same structure.
This commit is contained in:
Robbert van der Helm
2021-02-13 15:42:05 +01:00
parent 4e4ed3a6b4
commit 4f8eaaaa75
14 changed files with 289 additions and 133 deletions
+4 -4
View File
@@ -30,7 +30,7 @@
#include "vst3/host-context-proxy.h"
#include "vst3/plug-frame-proxy.h"
#include "vst3/plug-view-proxy.h"
#include "vst3/plugin-factory.h"
#include "vst3/plugin-factory-proxy.h"
#include "vst3/plugin-proxy.h"
// Event handling for our VST3 plugins works slightly different from how we
@@ -65,7 +65,8 @@ struct WantsConfiguration {
* request of type `ControlRequest(T)` should send back a `T::Response`.
*/
using ControlRequest =
std::variant<Vst3PlugViewProxy::Destruct,
std::variant<Vst3PluginFactoryProxy::Construct,
Vst3PlugViewProxy::Destruct,
Vst3PluginProxy::Construct,
Vst3PluginProxy::Destruct,
Vst3PluginProxy::SetState,
@@ -119,8 +120,7 @@ using ControlRequest =
YaPlugViewContentScaleSupport::SetContentScaleFactor,
YaPluginBase::Initialize,
YaPluginBase::Terminate,
YaPluginFactory::Construct,
YaPluginFactory::SetHostContext,
YaPluginFactory3::SetHostContext,
YaProcessContextRequirements::GetProcessContextRequirements,
YaProgramListData::ProgramDataSupported,
YaProgramListData::GetProgramData,
+2 -1
View File
@@ -10,7 +10,8 @@ VST3 plugin interfaces are implemented as follows:
| yabridge class | Included in | Interfaces |
| ----------------------------------- | ------------------- | ------------------------------------------------------ |
| `YaPluginFactory` | | `IPluginFactory`, `IPluginFactory2`, `IPluginFactory3` |
| `Vst3PluginFactoryProxy` | | All of the below: |
| `YaPluginFactory3` | | `IPluginFactory`, `IPluginFactory2`, `IPluginFactory3` |
| `Vst3ConnectionPointProxy` | | `IConnectionPoint` through `YaConnectionPoint` |
| `Vst3PlugViewProxy` | | All of the below: |
| `YaParameterFinder` | `Vst3PlugViewProxy` | `IParameterFinder` |
@@ -0,0 +1,58 @@
// yabridge: a Wine VST bridge
// Copyright (C) 2020-2021 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 "plugin-factory-proxy.h"
Vst3PluginFactoryProxy::ConstructArgs::ConstructArgs() {}
Vst3PluginFactoryProxy::ConstructArgs::ConstructArgs(
Steinberg::IPtr<Steinberg::FUnknown> object)
: plugin_factory_args(object) {}
Vst3PluginFactoryProxy::Vst3PluginFactoryProxy(const ConstructArgs&& args)
: YaPluginFactory3(std::move(args.plugin_factory_args)),
arguments(std::move(args)){FUNKNOWN_CTOR}
// clang-format just doesn't understand these macros, I guess
Vst3PluginFactoryProxy::~Vst3PluginFactoryProxy() {
FUNKNOWN_DTOR
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
IMPLEMENT_REFCOUNT(Vst3PluginFactoryProxy)
#pragma GCC diagnostic pop
tresult PLUGIN_API
Vst3PluginFactoryProxy::queryInterface(Steinberg::FIDString _iid, void** obj) {
if (YaPluginFactory3::supports_plugin_factory()) {
QUERY_INTERFACE(_iid, obj, Steinberg::FUnknown::iid,
Steinberg::IPluginFactory)
QUERY_INTERFACE(_iid, obj, Steinberg::IPluginFactory::iid,
Steinberg::IPluginFactory)
}
if (YaPluginFactory3::supports_plugin_factory_2()) {
QUERY_INTERFACE(_iid, obj, Steinberg::IPluginFactory2::iid,
Steinberg::IPluginFactory2)
}
if (YaPluginFactory3::supports_plugin_factory_3()) {
QUERY_INTERFACE(_iid, obj, Steinberg::IPluginFactory3::iid,
Steinberg::IPluginFactory3)
}
*obj = nullptr;
return Steinberg::kNoInterface;
}
@@ -0,0 +1,86 @@
// yabridge: a Wine VST bridge
// Copyright (C) 2020-2021 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 "../common.h"
#include "plugin-factory/plugin-factory.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
/**
* An abstract class that `IPluginFactory`, and optionally also
* `IPluginFactory2` and `IPluginFactory3` depending on what the Windows VST3
* plugin's plugin factory supports. All information is read once the Wine
* plugin host side, so the only callbacks that we'll make from here are to
* create new objects and to set a host context for the factory (if the host and
* the plugin supports that).
*/
class Vst3PluginFactoryProxy : public YaPluginFactory3 {
public:
/**
* These are the arguments for constructing a `Vst3PluginFactoryProxyImpl`.
*/
struct ConstructArgs {
ConstructArgs();
/**
* 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<FUnknown> object);
YaPluginFactory3::ConstructArgs plugin_factory_args;
template <typename S>
void serialize(S& s) {
s.object(plugin_factory_args);
}
};
/**
* Message to request the Windows VST3 plugin's plugin factory information
* from the Wine plugin host.
*/
struct Construct {
using Response = ConstructArgs;
template <typename S>
void serialize(S&) {}
};
/**
* Instantiate this instance with arguments read from an actual plugin
* factory. The is done once during startup and the plugin factory gets
* reused for the lifetime of the module.
*/
Vst3PluginFactoryProxy(const ConstructArgs&& args);
/**
* We do not need special handling here since the Window VST3 plugin's
* plugin factory will also be destroyed when we terminate the Wine plugin
* host or unload the plugin there.
*/
virtual ~Vst3PluginFactoryProxy();
DECLARE_FUNKNOWN_METHODS
private:
ConstructArgs arguments;
};
#pragma GCC diagnostic pop
@@ -21,10 +21,16 @@
#include <public.sdk/source/vst/utility/stringconvert.h>
YaPluginFactory::ConstructArgs::ConstructArgs() {}
YaPluginFactory3::ConstructArgs::ConstructArgs() {}
YaPluginFactory::ConstructArgs::ConstructArgs(
Steinberg::IPtr<Steinberg::IPluginFactory> factory) {
YaPluginFactory3::ConstructArgs::ConstructArgs(
Steinberg::IPtr<Steinberg::FUnknown> object) {
Steinberg::FUnknownPtr<Steinberg::IPluginFactory> factory(object);
if (!factory) {
return;
}
supports_plugin_factory = true;
// `IPluginFactory::getFactoryInfo`
if (Steinberg::PFactoryInfo info;
factory->getFactoryInfo(&info) == Steinberg::kResultOk) {
@@ -93,40 +99,11 @@ YaPluginFactory::ConstructArgs::ConstructArgs(
}
}
YaPluginFactory::YaPluginFactory(const ConstructArgs&& args)
: arguments(std::move(args)){FUNKNOWN_CTOR}
// clang-format just doesn't understand these macros, I guess
YaPluginFactory::~YaPluginFactory() {
FUNKNOWN_DTOR
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
IMPLEMENT_REFCOUNT(YaPluginFactory)
#pragma GCC diagnostic pop
tresult PLUGIN_API YaPluginFactory::queryInterface(Steinberg::FIDString _iid,
void** obj) {
QUERY_INTERFACE(_iid, obj, Steinberg::FUnknown::iid,
Steinberg::IPluginFactory)
QUERY_INTERFACE(_iid, obj, Steinberg::IPluginFactory::iid,
Steinberg::IPluginFactory)
if (arguments.supports_plugin_factory_2) {
QUERY_INTERFACE(_iid, obj, Steinberg::IPluginFactory2::iid,
Steinberg::IPluginFactory2)
}
if (arguments.supports_plugin_factory_3) {
QUERY_INTERFACE(_iid, obj, Steinberg::IPluginFactory3::iid,
Steinberg::IPluginFactory3)
}
*obj = nullptr;
return Steinberg::kNoInterface;
}
YaPluginFactory3::YaPluginFactory3(const ConstructArgs&& args)
: arguments(std::move(args)) {}
tresult PLUGIN_API
YaPluginFactory::getFactoryInfo(Steinberg::PFactoryInfo* info) {
YaPluginFactory3::getFactoryInfo(Steinberg::PFactoryInfo* info) {
if (info && arguments.factory_info) {
*info = *arguments.factory_info;
return Steinberg::kResultOk;
@@ -135,18 +112,18 @@ YaPluginFactory::getFactoryInfo(Steinberg::PFactoryInfo* info) {
}
}
int32 PLUGIN_API YaPluginFactory::countClasses() {
int32 PLUGIN_API YaPluginFactory3::countClasses() {
return arguments.num_classes;
}
tresult PLUGIN_API YaPluginFactory::getClassInfo(Steinberg::int32 index,
Steinberg::PClassInfo* info) {
tresult PLUGIN_API YaPluginFactory3::getClassInfo(Steinberg::int32 index,
Steinberg::PClassInfo* info) {
if (index >= static_cast<int32>(arguments.class_infos_1.size())) {
return Steinberg::kInvalidArgument;
}
// We will have already converted these class IDs to the native
// representation in `YaPluginFactory::ConstructArgs`
// representation in `YaPluginFactory3::ConstructArgs`
if (arguments.class_infos_1[index]) {
*info = *arguments.class_infos_1[index];
return Steinberg::kResultOk;
@@ -156,13 +133,13 @@ tresult PLUGIN_API YaPluginFactory::getClassInfo(Steinberg::int32 index,
}
tresult PLUGIN_API
YaPluginFactory::getClassInfo2(int32 index, Steinberg::PClassInfo2* info) {
YaPluginFactory3::getClassInfo2(int32 index, Steinberg::PClassInfo2* info) {
if (index >= static_cast<int32>(arguments.class_infos_2.size())) {
return Steinberg::kInvalidArgument;
}
// We will have already converted these class IDs to the native
// representation in `YaPluginFactory::ConstructArgs`
// representation in `YaPluginFactory3::ConstructArgs`
if (arguments.class_infos_2[index]) {
*info = *arguments.class_infos_2[index];
return Steinberg::kResultOk;
@@ -172,14 +149,14 @@ YaPluginFactory::getClassInfo2(int32 index, Steinberg::PClassInfo2* info) {
}
tresult PLUGIN_API
YaPluginFactory::getClassInfoUnicode(int32 index,
Steinberg::PClassInfoW* info) {
YaPluginFactory3::getClassInfoUnicode(int32 index,
Steinberg::PClassInfoW* info) {
if (index >= static_cast<int32>(arguments.class_infos_unicode.size())) {
return Steinberg::kInvalidArgument;
}
// We will have already converted these class IDs to the native
// representation in `YaPluginFactory::ConstructArgs`
// representation in `YaPluginFactory3::ConstructArgs`
if (arguments.class_infos_unicode[index]) {
*info = *arguments.class_infos_unicode[index];
return Steinberg::kResultOk;
@@ -20,40 +20,45 @@
#include <bitsery/traits/string.h>
#include <pluginterfaces/base/ipluginbase.h>
#include "base.h"
#include "host-context-proxy.h"
#include "../base.h"
#include "../host-context-proxy.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
/**
* Wraps around `IPluginFactory{1,2,3}` for serialization purposes. See
* `docs/vst3.md` for more information on how this works.
*
* TODO: Redo this in the new 'Vst3PluginFactoryProxy' style
* Wraps around `IPluginFactory{1,2,3}` for serialization purposes. This is
* instantiated as part of `Vst3PluginFactoryProxy`.
*/
class YaPluginFactory : public Steinberg::IPluginFactory3 {
class YaPluginFactory3 : public Steinberg::IPluginFactory3 {
public:
/**
* These are the arguments for constructing a `YaPluginFactoryImpl`.
* These are the arguments for creating a `YaPluginFactory3`. All class
* infos in all available formats are read from the plugin so the host can
* query them.
*/
struct ConstructArgs {
ConstructArgs();
/**
* Create a copy of an existing plugin factory. Depending on the
* supported interface function more or less of this struct will be left
* empty, and `known_iids` will be set accordingly.
* Check whether an existing implementation implements
* `IPluginFactory1`, `IPluginFactory2`, and ``IPluginFactory3`` and
* read arguments from it.
*/
ConstructArgs(Steinberg::IPtr<Steinberg::IPluginFactory> factory);
ConstructArgs(Steinberg::IPtr<Steinberg::FUnknown> object);
/**
* Whether `factory` supported `IPluginFactory2`.
* Whether the object supported `IPluginFactory`.
*/
bool supports_plugin_factory = false;
/**
* Whether the object supported `IPluginFactory2`.
*/
bool supports_plugin_factory_2 = false;
/**
* Whether `factory` supported `IPluginFactory3`.
* Whether the object supported `IPluginFactory3`.
*/
bool supports_plugin_factory_3 = false;
@@ -93,6 +98,7 @@ class YaPluginFactory : public Steinberg::IPluginFactory3 {
template <typename S>
void serialize(S& s) {
s.value1b(supports_plugin_factory);
s.value1b(supports_plugin_factory_2);
s.value1b(supports_plugin_factory_3);
s.ext(factory_info, bitsery::ext::StdOptional{});
@@ -112,31 +118,27 @@ class YaPluginFactory : public Steinberg::IPluginFactory3 {
}
};
/**
* Message to request the `IPluginFactory{,2,3}`'s information from the Wine
* plugin host.
*/
struct Construct {
using Response = ConstructArgs;
template <typename S>
void serialize(S&) {}
};
/**
* Instantiate this instance with arguments read from the Windows VST3
* plugin's plugin factory.
*/
YaPluginFactory(const ConstructArgs&& args);
YaPluginFactory3(const ConstructArgs&& args);
/**
* We do not need to implement the destructor in `YaPluginFactoryImpl`,
* since when the sockets are closed, RAII will clean up the Windows VST3
* module we loaded along with its factory for us.
*/
virtual ~YaPluginFactory();
inline bool supports_plugin_factory() const {
return arguments.supports_plugin_factory;
}
DECLARE_FUNKNOWN_METHODS
inline bool supports_plugin_factory_2() const {
return arguments.supports_plugin_factory_2;
}
inline bool supports_plugin_factory_3() const {
return arguments.supports_plugin_factory_3;
}
// All of these functiosn returning class information are fetched once on
// the Wine side since they'll be static so we can just copy over the
// responses
// From `IPluginFactory`
tresult PLUGIN_API getFactoryInfo(Steinberg::PFactoryInfo* info) override;
@@ -144,7 +146,8 @@ class YaPluginFactory : public Steinberg::IPluginFactory3 {
tresult PLUGIN_API getClassInfo(Steinberg::int32 index,
Steinberg::PClassInfo* info) override;
/**
* See the implementation in `YaPluginFactoryImpl` for how this is handled.
* See the implementation in `Vst3PluginFactoryProxyImpl` for how this is
* handled. We'll create new managed `Vst3PluginProxy` objects from here.
*/
virtual tresult PLUGIN_API createInstance(Steinberg::FIDString cid,
Steinberg::FIDString _iid,