Implement IEditController::setComponentHandler()

This commit is contained in:
Robbert van der Helm
2020-12-19 15:04:27 +01:00
parent 132ba0baeb
commit bf3d802f36
8 changed files with 122 additions and 12 deletions
+15
View File
@@ -391,6 +391,21 @@ bool Vst3Logger::log_request(
}); });
} }
bool Vst3Logger::log_request(
bool is_host_vst,
const YaEditController::SetComponentHandler& request) {
return log_request_base(is_host_vst, [&](auto& message) {
message << request.instance_id
<< ": IEditController::setComponentHandler(handler = ";
if (request.component_handler_proxy_args) {
message << "<IComponentHandler*>";
} else {
message << "<nullptr>";
}
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) {
+2
View File
@@ -102,6 +102,8 @@ class Vst3Logger {
const YaEditController::GetParamNormalized&); const YaEditController::GetParamNormalized&);
bool log_request(bool is_host_vst, bool log_request(bool is_host_vst,
const YaEditController::SetParamNormalized&); const YaEditController::SetParamNormalized&);
bool log_request(bool is_host_vst,
const YaEditController::SetComponentHandler&);
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
@@ -87,6 +87,7 @@ using ControlRequest = std::variant<Vst3PluginProxy::Construct,
YaEditController::PlainParamToNormalized, YaEditController::PlainParamToNormalized,
YaEditController::GetParamNormalized, YaEditController::GetParamNormalized,
YaEditController::SetParamNormalized, YaEditController::SetParamNormalized,
YaEditController::SetComponentHandler,
YaPluginBase::Initialize, YaPluginBase::Initialize,
YaPluginBase::Terminate, YaPluginBase::Terminate,
YaPluginFactory::Construct, YaPluginFactory::Construct,
@@ -16,10 +16,12 @@
#pragma once #pragma once
#include <bitsery/ext/std_optional.h>
#include <pluginterfaces/vst/ivsteditcontroller.h> #include <pluginterfaces/vst/ivsteditcontroller.h>
#include "../../common.h" #include "../../common.h"
#include "../base.h" #include "../base.h"
#include "../component-handler-proxy.h"
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
@@ -328,6 +330,35 @@ class YaEditController : public Steinberg::Vst::IEditController {
virtual tresult PLUGIN_API virtual tresult PLUGIN_API
setParamNormalized(Steinberg::Vst::ParamID id, setParamNormalized(Steinberg::Vst::ParamID id,
Steinberg::Vst::ParamValue value) override = 0; Steinberg::Vst::ParamValue value) override = 0;
/**
* Message to pass through a call to
* `IEditController::setComponentHandler(handler)` to the Wine plugin host.
* Like when creating a proxy for a plugin object, we'll read all supported
* interfaces form the component handler instance passed by the host. We'll
* then create a perfect proxy on the plugin side, that can do callbacks to
* the actual component handler passed by the host.
*/
struct SetComponentHandler {
using Response = UniversalTResult;
native_size_t instance_id;
/**
* Arguments for instantiating the proxy object. Even though it should
* never happen, if the host passed a null pointer to this function
* we'll mimic that as well.
*/
std::optional<Vst3ComponentHandlerProxy::ConstructArgs>
component_handler_proxy_args;
template <typename S>
void serialize(S& s) {
s.value8b(instance_id);
s.ext(component_handler_proxy_args, bitsery::ext::StdOptional{});
}
};
virtual tresult PLUGIN_API setComponentHandler( virtual tresult PLUGIN_API setComponentHandler(
Steinberg::Vst::IComponentHandler* handler) override = 0; Steinberg::Vst::IComponentHandler* handler) override = 0;
virtual Steinberg::IPlugView* PLUGIN_API virtual Steinberg::IPlugView* PLUGIN_API
+18 -3
View File
@@ -315,9 +315,24 @@ Vst3PluginProxyImpl::setParamNormalized(Steinberg::Vst::ParamID id,
tresult PLUGIN_API Vst3PluginProxyImpl::setComponentHandler( tresult PLUGIN_API Vst3PluginProxyImpl::setComponentHandler(
Steinberg::Vst::IComponentHandler* handler) { Steinberg::Vst::IComponentHandler* handler) {
// TODO: Implement std::optional<Vst3ComponentHandlerProxy::ConstructArgs>
bridge.logger.log("TODO IEditController::setComponentHandler()"); component_handler_proxy_args = std::nullopt;
return Steinberg::kNotImplemented; 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(
host_application_context, instance_id());
} else {
bridge.logger.log(
"Null pointer passed to 'IEditController::setComponentHandler'");
}
return bridge.send_message(YaEditController::SetComponentHandler{
.instance_id = instance_id(),
.component_handler_proxy_args =
std::move(component_handler_proxy_args)});
} }
Steinberg::IPlugView* PLUGIN_API Steinberg::IPlugView* PLUGIN_API
@@ -133,4 +133,12 @@ class Vst3PluginProxyImpl : public Vst3PluginProxy {
*/ */
Steinberg::FUnknownPtr<Steinberg::Vst::IHostApplication> Steinberg::FUnknownPtr<Steinberg::Vst::IHostApplication>
host_application_context; host_application_context;
/**
* The component handler the host passed to us during
* `IEditController::setComponentHandler()`. When the plugin makes a
* callback on a component handler proxy object, we'll pass the call through
* to this object.
*/
Steinberg::IPtr<Steinberg::Vst::IComponentHandler> component_handler;
}; };
+35 -7
View File
@@ -23,6 +23,7 @@
#include <boost/asio/dispatch.hpp> #include <boost/asio/dispatch.hpp>
#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/host-application.h" #include "vst3-impls/host-application.h"
InstanceInterfaces::InstanceInterfaces() {} InstanceInterfaces::InstanceInterfaces() {}
@@ -336,28 +337,55 @@ void Vst3Bridge::run() {
.edit_controller->setParamNormalized(request.id, .edit_controller->setParamNormalized(request.id,
request.value); request.value);
}, },
[&](YaEditController::SetComponentHandler& request)
-> YaEditController::SetComponentHandler::Response {
// If we got passed a component handler, we'll create a proxy
// object and pass that to the initialize function. The lifetime
// of this object is tied to that of the actual plugin object
// we're proxying for.
// TODO: Does this have to be run from the UI thread? Figure out
// if it does
if (request.component_handler_proxy_args) {
object_instances[request.instance_id]
.component_handler_proxy =
Steinberg::owned(new Vst3ComponentHandlerProxyImpl(
*this,
std::move(*request.component_handler_proxy_args)));
} else {
object_instances[request.instance_id]
.component_handler_proxy = nullptr;
}
return object_instances[request.instance_id]
.edit_controller->setComponentHandler(
object_instances[request.instance_id]
.component_handler_proxy);
},
[&](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
// and pass that to the initialize function. This object should // and pass that to the initialize function. The lifetime of
// be cleaned up again during `Vst3PluginProxy::Destruct`. // this object is tied to that of the actual plugin object we're
// proxying for.
// TODO: This needs changing if it turns out we need a // TODO: This needs changing if it turns out we need a
// `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
Steinberg::FUnknown* context = nullptr;
if (request.host_application_context_args) { if (request.host_application_context_args) {
object_instances[request.instance_id] object_instances[request.instance_id]
.hsot_application_context = .host_application_context =
Steinberg::owned(new YaHostApplicationImpl( Steinberg::owned(new YaHostApplicationImpl(
*this, *this,
std::move(*request.host_application_context_args))); std::move(*request.host_application_context_args)));
context = object_instances[request.instance_id] } else {
.hsot_application_context; object_instances[request.instance_id]
.host_application_context = nullptr;
} }
return object_instances[request.instance_id] return object_instances[request.instance_id]
.plugin_base->initialize(context); .plugin_base->initialize(
object_instances[request.instance_id]
.host_application_context);
}, },
[&](const YaPluginBase::Terminate& request) [&](const YaPluginBase::Terminate& request)
-> YaPluginBase::Terminate::Response { -> YaPluginBase::Terminate::Response {
+12 -2
View File
@@ -40,9 +40,19 @@ struct InstanceInterfaces {
/** /**
* If the host passes an `IHostApplication` during * If the host passes an `IHostApplication` 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()`. * pass it to `plugin_base->initialize()`. Will be initialized with a null
* pointer until used.
*/ */
Steinberg::IPtr<YaHostApplication> hsot_application_context; Steinberg::IPtr<YaHostApplication> host_application_context;
/**
* After a call to `IEditController::setComponentHandler()`, we'll create a
* proxy of that component handler just like we did for the plugin object.
* When the plugin calls a function on this object, we make a callback to
* the original object provided by the host. Will be initialized with a null
* pointer until used.
*/
Steinberg::IPtr<Vst3ComponentHandlerProxy> component_handler_proxy;
/** /**
* The base object we cast from. * The base object we cast from.