From 9bca4796a5a807d8a656f265bd9180bd09c4ef81 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 19 Dec 2020 14:08:41 +0100 Subject: [PATCH] Add boilerplate for Vst3ComponentHandlerProxy --- src/common/serialization/vst3/README.md | 11 +- .../vst3/component-handler-proxy.h | 115 ++++++++++++++++++ .../serialization/vst3/host-application.h | 4 +- src/common/serialization/vst3/plugin-proxy.h | 3 - 4 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 src/common/serialization/vst3/component-handler-proxy.h diff --git a/src/common/serialization/vst3/README.md b/src/common/serialization/vst3/README.md index a6d10363..c626bb36 100644 --- a/src/common/serialization/vst3/README.md +++ b/src/common/serialization/vst3/README.md @@ -19,11 +19,14 @@ VST3 plugin interfaces are implemented as follows: VST3 host interfaces are implemented as follows: -| yabridge class | Interfaces | -| ------------------- | ------------------ | -| `YaHostApplication` | `IHostApplication` | +| yabridge class | Included in | Interfaces | +| --------------------------- | --------------------------- | ------------------- | +| `YaHostApplication` | | `IHostApplication` | +| `Vst3ComponentHandlerProxy` | | All of the below: | +| `YaComponentHandler` | `Vst3ComponentHandlerProxy` | `IComponentHandler` | -The following (host) interfaces are also implemented for serialization purposes: +The following host interfaces are passed as function arguments and are thus also +implemented for serialization purposes: | yabridge class | Interfaces | Notes | | -------------------- | ------------------- | ---------------------------------------------------------------------- | diff --git a/src/common/serialization/vst3/component-handler-proxy.h b/src/common/serialization/vst3/component-handler-proxy.h new file mode 100644 index 00000000..597d6219 --- /dev/null +++ b/src/common/serialization/vst3/component-handler-proxy.h @@ -0,0 +1,115 @@ +// 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 . + +#pragma once + +#include "../common.h" +#include "base.h" +#include "host-application.h" +#include "plugin/audio-processor.h" +#include "plugin/component.h" +#include "plugin/connection-point.h" +#include "plugin/edit-controller.h" +#include "plugin/plugin-base.h" + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" + +/** + * An abstract class that implements `IComponentHandler`, and optionally also + * all other VST3 interfaces an object passed to + * `IEditController::setComponentHandler()`. This works exactly the same as + * `Vst3PluginProxy`, but instead of proxying for an object provided by the + * plugin we are proxying for the `IComponentHandler*` argument passed to plugin + * by the host. + */ +class Vst3ComponentHandlerProxy { + public: + /** + * These are the arguments for constructing a + * `Vst3ComponentHandlerProxyImpl`. + */ + 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 object, + size_t owner_instance_id); + + /** + * The unique instance identifier of the proxy object instance this + * component handler has been passed to and thus belongs to. This way we + * can refer to the correct 'actual' `IComponentHandler` instance when + * the plugin does a callback. + */ + native_size_t owner_instance_id; + + // TODO: + // YaAudioProcessor::ConstructArgs audio_processor_args; + // YaComponent::ConstructArgs component_args; + // YaConnectionPoint::ConstructArgs connection_point_args; + // YaEditController::ConstructArgs edit_controller_2_args; + // YaPluginBase::ConstructArgs plugin_base_args; + + template + void serialize(S& s) { + s.value8b(owner_instance_id); + // TODO: + // s.object(audio_processor_args); + // s.object(component_args); + // s.object(connection_point_args); + // s.object(edit_controller_2_args); + // s.object(plugin_base_args); + } + }; + + /** + * Instantiate this instance with arguments read from an actual component + * handler. + * + * @note Since this is passed as part of + * `IEditController::setComponentHandler()`, there are no direct + * `Construct` or `Destruct` messages. This object's lifetime is bound to + * that of the objects they are passed to. If those objects get dropped, + * then the host contexts should also be dropped. + */ + Vst3ComponentHandlerProxy(const ConstructArgs&& args); + + /** + * 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 + * dropped a corresponding `Vst3ComponentHandlerProxyImpl` should also be + * dropped. + */ + virtual ~Vst3ComponentHandlerProxy() = 0; + + DECLARE_FUNKNOWN_METHODS + + /** + * Get the instance ID of the owner of this object. + */ + inline size_t owner_instance_id() const { + return arguments.owner_instance_id; + } + + private: + ConstructArgs arguments; +}; + +#pragma GCC diagnostic pop diff --git a/src/common/serialization/vst3/host-application.h b/src/common/serialization/vst3/host-application.h index 9ad1a586..122c5f94 100644 --- a/src/common/serialization/vst3/host-application.h +++ b/src/common/serialization/vst3/host-application.h @@ -90,8 +90,8 @@ class YaHostApplication : public Steinberg::Vst::IHostApplication { /** * 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 - * dropped and we also track a `YaHostApplicationImpl` for the component - * with instance id `n`, then that should also be dropped. + * dropped, the corresponding `YaHostApplicationImpl` then that should also + * be dropped. */ virtual ~YaHostApplication(); diff --git a/src/common/serialization/vst3/plugin-proxy.h b/src/common/serialization/vst3/plugin-proxy.h index fe60da24..0fe9776e 100644 --- a/src/common/serialization/vst3/plugin-proxy.h +++ b/src/common/serialization/vst3/plugin-proxy.h @@ -17,11 +17,8 @@ #pragma once #include -#include #include "../common.h" -#include "base.h" -#include "host-application.h" #include "plugin/audio-processor.h" #include "plugin/component.h" #include "plugin/connection-point.h"