From 2e6184171c11d48027321f262555431d433aa41f Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 8 Dec 2020 23:00:44 +0100 Subject: [PATCH] Use std::array for serializing UIDs These are easily assignable and we have to convert between char pointers, char arrays and UID objects all the time anyways. --- src/common/serialization/vst3/base.h | 36 +++++++++++++++++++ src/common/serialization/vst3/component.h | 12 ++++--- .../serialization/vst3/plugin-factory.h | 3 +- src/wine-host/bridges/vst3.cpp | 4 ++- 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/common/serialization/vst3/base.h diff --git a/src/common/serialization/vst3/base.h b/src/common/serialization/vst3/base.h new file mode 100644 index 00000000..e4836118 --- /dev/null +++ b/src/common/serialization/vst3/base.h @@ -0,0 +1,36 @@ +// 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 + +#include +#include + +// Yet Another layer of includes, but these are some VST3-specific typedefs that +// we'll need for all of our interfaces + +using Steinberg::TBool, Steinberg::int8, Steinberg::int32, Steinberg::tresult; + +/** + * Both `TUID` (`int8_t[16]`) and `FIDString` (`char*`) are hard to work with + * because you can't just copy them. So when serializing/deserializing them + * we'll use `std::array`. + */ +using ArrayUID = std::array< + std::remove_reference_t()[0])>, + std::extent_v>; diff --git a/src/common/serialization/vst3/component.h b/src/common/serialization/vst3/component.h index 2d285e69..3be2f83e 100644 --- a/src/common/serialization/vst3/component.h +++ b/src/common/serialization/vst3/component.h @@ -17,14 +17,14 @@ #pragma once #include -#include "src/common/serialization/common.h" #include #include #include #include -using Steinberg::TBool, Steinberg::int8, Steinberg::int32, Steinberg::tresult; +#include "../common.h" +#include "base.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" @@ -38,6 +38,9 @@ using Steinberg::TBool, Steinberg::int8, Steinberg::int32, Steinberg::tresult; * We might be able to do some caching here with the buss infos, but since that * sounds like a huge potential source of errors we'll just do pure callbacks * for everything other than the edit controller's class ID. + * + * TODO: I think it's expected that components also implement `IAudioProcessor` + * and `IConnectionPoint`. */ class YaComponent : public Steinberg::Vst::IComponent { public: @@ -60,8 +63,7 @@ class YaComponent : public Steinberg::Vst::IComponent { * The class ID of this component's corresponding editor controller. You * can't use C-style array in `std::optional`s. */ - std::optional>> - edit_controller_cid; + std::optional edit_controller_cid; template void serialize(S& s) { @@ -81,7 +83,7 @@ class YaComponent : public Steinberg::Vst::IComponent { // TODO: Create a `native_tvalue` wrapper, and then also add them here using Response = std::optional; - Steinberg::TUID cid; + ArrayUID cid; template void serialize(S& s) { diff --git a/src/common/serialization/vst3/plugin-factory.h b/src/common/serialization/vst3/plugin-factory.h index a0e87daf..5815e084 100644 --- a/src/common/serialization/vst3/plugin-factory.h +++ b/src/common/serialization/vst3/plugin-factory.h @@ -24,8 +24,7 @@ #include #include "../../bitsery/ext/vst3.h" - -using Steinberg::int32, Steinberg::tresult; +#include "base.h" // TODO: After implementing one or two more of these, abstract away some of the // nasty bits diff --git a/src/wine-host/bridges/vst3.cpp b/src/wine-host/bridges/vst3.cpp index 618b41c9..060cfedf 100644 --- a/src/wine-host/bridges/vst3.cpp +++ b/src/wine-host/bridges/vst3.cpp @@ -53,9 +53,11 @@ void Vst3Bridge::run() { overload{ [&](const YaComponent::Create& args) -> YaComponent::Create::Response { + Steinberg::TUID cid; + std::copy(args.cid.begin(), args.cid.end(), cid); Steinberg::IPtr component = module->getFactory() - .createInstance(args.cid); + .createInstance(cid); if (component) { std::lock_guard lock(component_instances_mutex);