From e24cecc6d796d5498e3af57182009f8deb24a333 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 11 Dec 2020 23:54:30 +0100 Subject: [PATCH] Use the univeral tresult in IComponent creation --- src/common/logging/vst3.cpp | 17 +++++++++++------ src/common/logging/vst3.h | 5 +++-- src/common/serialization/vst3/base.cpp | 6 +++--- src/common/serialization/vst3/base.h | 9 +++++++++ src/common/serialization/vst3/component.h | 17 ++++++++++------- .../bridges/vst3-impls/plugin-factory.cpp | 18 ++++++++++-------- src/wine-host/bridges/vst3.cpp | 5 +++-- 7 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/common/logging/vst3.cpp b/src/common/logging/vst3.cpp index 7807a23c..299bf473 100644 --- a/src/common/logging/vst3.cpp +++ b/src/common/logging/vst3.cpp @@ -56,13 +56,18 @@ void Vst3Logger::log_response(bool is_host_vst, const Ack&) { void Vst3Logger::log_response( bool is_host_vst, - const std::optional& args) { + const std::variant& result) { log_response_base(is_host_vst, [&](auto& message) { - if (args) { - message << "instance_id << ">"; - } else { - message << ""; - } + std::visit(overload{[&](const YaComponent::CreateArgs& args) { + message << ""; + }, + [&](const UniversalTResult& code) { + // TODO: Add a `UniversalTResult::string()` for + // the human readable representation + message << code.native(); + }}, + result); }); } diff --git a/src/common/logging/vst3.h b/src/common/logging/vst3.h index 66a0a14f..f958d0b6 100644 --- a/src/common/logging/vst3.h +++ b/src/common/logging/vst3.h @@ -53,8 +53,9 @@ class Vst3Logger { void log_request(bool is_host_vst, const WantsPluginFactory&); void log_response(bool is_host_vst, const Ack&); - void log_response(bool is_host_vst, - const std::optional&); + void log_response( + bool is_host_vst, + const std::variant&); void log_response(bool is_host_vst, const Configuration&); void log_response(bool is_host_vst, const YaPluginFactory&); diff --git a/src/common/serialization/vst3/base.cpp b/src/common/serialization/vst3/base.cpp index afbdceff..218ce166 100644 --- a/src/common/serialization/vst3/base.cpp +++ b/src/common/serialization/vst3/base.cpp @@ -16,10 +16,10 @@ #include "base.h" +UniversalTResult::UniversalTResult() : universal_result(Value::kResultFalse) {} + UniversalTResult::UniversalTResult(tresult native_result) - : universal_result(to_universal_result(native_result)) { - // -} + : universal_result(to_universal_result(native_result)) {} tresult UniversalTResult::native() const { static_assert(Steinberg::kResultOk == Steinberg::kResultTrue); diff --git a/src/common/serialization/vst3/base.h b/src/common/serialization/vst3/base.h index 2dd19f30..4221da61 100644 --- a/src/common/serialization/vst3/base.h +++ b/src/common/serialization/vst3/base.h @@ -52,6 +52,15 @@ struct Ack { */ class UniversalTResult { public: + /** + * The default constructor will initialize the value to `kResutlFalse` and + * should only ever be used by bitsery in the serialization process. + */ + UniversalTResult(); + + /** + * Convert a native tresult into a univeral one. + */ UniversalTResult(tresult native_result); /** diff --git a/src/common/serialization/vst3/component.h b/src/common/serialization/vst3/component.h index c31932de..ed9b9781 100644 --- a/src/common/serialization/vst3/component.h +++ b/src/common/serialization/vst3/component.h @@ -17,9 +17,11 @@ #pragma once #include +#include #include #include +#include #include #include @@ -82,8 +84,7 @@ class YaComponent : public Steinberg::Vst::IComponent { * ...)`. */ struct Create { - // TODO: Create a `native_tvalue` wrapper, and then also add them here - using Response = std::optional; + using Response = std::variant; ArrayUID cid; @@ -156,9 +157,11 @@ class YaComponent : public Steinberg::Vst::IComponent { CreateArgs arguments; }; -template -void serialize(S& s, std::optional& args) { - s.ext(args, bitsery::ext::StdOptional{}); -} - #pragma GCC diagnostic pop + +template +void serialize( + S& s, + std::variant& result) { + s.ext(result, bitsery::ext::StdVariant{}); +} diff --git a/src/plugin/bridges/vst3-impls/plugin-factory.cpp b/src/plugin/bridges/vst3-impls/plugin-factory.cpp index e77c3191..fad34cb4 100644 --- a/src/plugin/bridges/vst3-impls/plugin-factory.cpp +++ b/src/plugin/bridges/vst3-impls/plugin-factory.cpp @@ -31,15 +31,17 @@ YaPluginFactoryPluginImpl::createInstance(Steinberg::FIDString cid, ArrayUID cid_array; std::copy(cid, cid + sizeof(Steinberg::TUID), cid_array.begin()); if (Steinberg::FIDStringsEqual(_iid, Steinberg::Vst::IComponent::iid)) { - std::optional args = + std::variant result = bridge.send_message(YaComponent::Create{.cid = cid_array}); - if (args) { - // I find all of these raw pointers scary - *obj = new YaComponentPluginImpl(bridge, std::move(*args)); - return Steinberg::kResultOk; - } else { - return Steinberg::kNotImplemented; - } + return std::visit( + overload{ + [&](YaComponent::CreateArgs&& args) -> tresult { + // I find all of these raw pointers scary + *obj = new YaComponentPluginImpl(bridge, std::move(args)); + return Steinberg::kResultOk; + }, + [&](const UniversalTResult& code) { return code.native(); }}, + std::move(result)); } else { // When the host requests an interface we do not (yet) implement, we'll // print a recognizable log message. I don't think they include a safe diff --git a/src/wine-host/bridges/vst3.cpp b/src/wine-host/bridges/vst3.cpp index dd34e711..01d86b4a 100644 --- a/src/wine-host/bridges/vst3.cpp +++ b/src/wine-host/bridges/vst3.cpp @@ -64,10 +64,11 @@ void Vst3Bridge::run() { const size_t instance_id = generate_instance_id(); component_instances[instance_id] = std::move(component); - return std::make_optional( + return YaComponent::CreateArgs( component_instances[instance_id], instance_id); } else { - return std::nullopt; + // The actual result is lost here + return UniversalTResult(Steinberg::kNotImplemented); } }, [&](const YaComponent::Destroy& request)