mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Use the univeral tresult in IComponent creation
This commit is contained in:
@@ -56,13 +56,18 @@ void Vst3Logger::log_response(bool is_host_vst, const Ack&) {
|
|||||||
|
|
||||||
void Vst3Logger::log_response(
|
void Vst3Logger::log_response(
|
||||||
bool is_host_vst,
|
bool is_host_vst,
|
||||||
const std::optional<YaComponent::CreateArgs>& args) {
|
const std::variant<YaComponent::CreateArgs, UniversalTResult>& result) {
|
||||||
log_response_base(is_host_vst, [&](auto& message) {
|
log_response_base(is_host_vst, [&](auto& message) {
|
||||||
if (args) {
|
std::visit(overload{[&](const YaComponent::CreateArgs& args) {
|
||||||
message << "<IComponent* #" << args->instance_id << ">";
|
message << "<IComponent* #" << args.instance_id
|
||||||
} else {
|
<< ">";
|
||||||
message << "<nullptr>";
|
},
|
||||||
}
|
[&](const UniversalTResult& code) {
|
||||||
|
// TODO: Add a `UniversalTResult::string()` for
|
||||||
|
// the human readable representation
|
||||||
|
message << code.native();
|
||||||
|
}},
|
||||||
|
result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,8 +53,9 @@ class Vst3Logger {
|
|||||||
void log_request(bool is_host_vst, const WantsPluginFactory&);
|
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 Ack&);
|
||||||
void log_response(bool is_host_vst,
|
void log_response(
|
||||||
const std::optional<YaComponent::CreateArgs>&);
|
bool is_host_vst,
|
||||||
|
const std::variant<YaComponent::CreateArgs, UniversalTResult>&);
|
||||||
void log_response(bool is_host_vst, const Configuration&);
|
void log_response(bool is_host_vst, const Configuration&);
|
||||||
void log_response(bool is_host_vst, const YaPluginFactory&);
|
void log_response(bool is_host_vst, const YaPluginFactory&);
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
|
|
||||||
|
UniversalTResult::UniversalTResult() : universal_result(Value::kResultFalse) {}
|
||||||
|
|
||||||
UniversalTResult::UniversalTResult(tresult native_result)
|
UniversalTResult::UniversalTResult(tresult native_result)
|
||||||
: universal_result(to_universal_result(native_result)) {
|
: universal_result(to_universal_result(native_result)) {}
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
tresult UniversalTResult::native() const {
|
tresult UniversalTResult::native() const {
|
||||||
static_assert(Steinberg::kResultOk == Steinberg::kResultTrue);
|
static_assert(Steinberg::kResultOk == Steinberg::kResultTrue);
|
||||||
|
|||||||
@@ -52,6 +52,15 @@ struct Ack {
|
|||||||
*/
|
*/
|
||||||
class UniversalTResult {
|
class UniversalTResult {
|
||||||
public:
|
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);
|
UniversalTResult(tresult native_result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,9 +17,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
#include <bitsery/ext/pointer.h>
|
#include <bitsery/ext/pointer.h>
|
||||||
#include <bitsery/ext/std_optional.h>
|
#include <bitsery/ext/std_optional.h>
|
||||||
|
#include <bitsery/ext/std_variant.h>
|
||||||
#include <bitsery/traits/array.h>
|
#include <bitsery/traits/array.h>
|
||||||
#include <pluginterfaces/vst/ivstcomponent.h>
|
#include <pluginterfaces/vst/ivstcomponent.h>
|
||||||
|
|
||||||
@@ -82,8 +84,7 @@ class YaComponent : public Steinberg::Vst::IComponent {
|
|||||||
* ...)`.
|
* ...)`.
|
||||||
*/
|
*/
|
||||||
struct Create {
|
struct Create {
|
||||||
// TODO: Create a `native_tvalue` wrapper, and then also add them here
|
using Response = std::variant<CreateArgs, UniversalTResult>;
|
||||||
using Response = std::optional<CreateArgs>;
|
|
||||||
|
|
||||||
ArrayUID cid;
|
ArrayUID cid;
|
||||||
|
|
||||||
@@ -156,9 +157,11 @@ class YaComponent : public Steinberg::Vst::IComponent {
|
|||||||
CreateArgs arguments;
|
CreateArgs arguments;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename S>
|
|
||||||
void serialize(S& s, std::optional<YaComponent::CreateArgs>& args) {
|
|
||||||
s.ext(args, bitsery::ext::StdOptional{});
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
template <typename S>
|
||||||
|
void serialize(
|
||||||
|
S& s,
|
||||||
|
std::variant<YaComponent::CreateArgs, UniversalTResult>& result) {
|
||||||
|
s.ext(result, bitsery::ext::StdVariant{});
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,15 +31,17 @@ YaPluginFactoryPluginImpl::createInstance(Steinberg::FIDString cid,
|
|||||||
ArrayUID cid_array;
|
ArrayUID cid_array;
|
||||||
std::copy(cid, cid + sizeof(Steinberg::TUID), cid_array.begin());
|
std::copy(cid, cid + sizeof(Steinberg::TUID), cid_array.begin());
|
||||||
if (Steinberg::FIDStringsEqual(_iid, Steinberg::Vst::IComponent::iid)) {
|
if (Steinberg::FIDStringsEqual(_iid, Steinberg::Vst::IComponent::iid)) {
|
||||||
std::optional<YaComponent::CreateArgs> args =
|
std::variant<YaComponent::CreateArgs, UniversalTResult> result =
|
||||||
bridge.send_message(YaComponent::Create{.cid = cid_array});
|
bridge.send_message(YaComponent::Create{.cid = cid_array});
|
||||||
if (args) {
|
return std::visit(
|
||||||
// I find all of these raw pointers scary
|
overload{
|
||||||
*obj = new YaComponentPluginImpl(bridge, std::move(*args));
|
[&](YaComponent::CreateArgs&& args) -> tresult {
|
||||||
return Steinberg::kResultOk;
|
// I find all of these raw pointers scary
|
||||||
} else {
|
*obj = new YaComponentPluginImpl(bridge, std::move(args));
|
||||||
return Steinberg::kNotImplemented;
|
return Steinberg::kResultOk;
|
||||||
}
|
},
|
||||||
|
[&](const UniversalTResult& code) { return code.native(); }},
|
||||||
|
std::move(result));
|
||||||
} else {
|
} else {
|
||||||
// When the host requests an interface we do not (yet) implement, we'll
|
// 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
|
// print a recognizable log message. I don't think they include a safe
|
||||||
|
|||||||
@@ -64,10 +64,11 @@ void Vst3Bridge::run() {
|
|||||||
const size_t instance_id = generate_instance_id();
|
const size_t instance_id = generate_instance_id();
|
||||||
component_instances[instance_id] = std::move(component);
|
component_instances[instance_id] = std::move(component);
|
||||||
|
|
||||||
return std::make_optional<YaComponent::CreateArgs>(
|
return YaComponent::CreateArgs(
|
||||||
component_instances[instance_id], instance_id);
|
component_instances[instance_id], instance_id);
|
||||||
} else {
|
} else {
|
||||||
return std::nullopt;
|
// The actual result is lost here
|
||||||
|
return UniversalTResult(Steinberg::kNotImplemented);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[&](const YaComponent::Destroy& request)
|
[&](const YaComponent::Destroy& request)
|
||||||
|
|||||||
Reference in New Issue
Block a user