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.
This commit is contained in:
Robbert van der Helm
2020-12-08 23:00:44 +01:00
parent 7828fc7bef
commit 2e6184171c
4 changed files with 47 additions and 8 deletions
+36
View File
@@ -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 <https://www.gnu.org/licenses/>.
#pragma once
#include <array>
#include <pluginterfaces/base/ftypes.h>
#include <pluginterfaces/base/funknown.h>
// 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<decltype(std::declval<Steinberg::TUID>()[0])>,
std::extent_v<Steinberg::TUID>>;
+7 -5
View File
@@ -17,14 +17,14 @@
#pragma once #pragma once
#include <optional> #include <optional>
#include "src/common/serialization/common.h"
#include <bitsery/ext/pointer.h> #include <bitsery/ext/pointer.h>
#include <bitsery/ext/std_optional.h> #include <bitsery/ext/std_optional.h>
#include <bitsery/traits/array.h> #include <bitsery/traits/array.h>
#include <pluginterfaces/vst/ivstcomponent.h> #include <pluginterfaces/vst/ivstcomponent.h>
using Steinberg::TBool, Steinberg::int8, Steinberg::int32, Steinberg::tresult; #include "../common.h"
#include "base.h"
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" #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 * 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 * sounds like a huge potential source of errors we'll just do pure callbacks
* for everything other than the edit controller's class ID. * 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 { class YaComponent : public Steinberg::Vst::IComponent {
public: public:
@@ -60,8 +63,7 @@ class YaComponent : public Steinberg::Vst::IComponent {
* The class ID of this component's corresponding editor controller. You * The class ID of this component's corresponding editor controller. You
* can't use C-style array in `std::optional`s. * can't use C-style array in `std::optional`s.
*/ */
std::optional<std::array<int8, std::extent_v<Steinberg::TUID>>> std::optional<ArrayUID> edit_controller_cid;
edit_controller_cid;
template <typename S> template <typename S>
void serialize(S& s) { 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 // TODO: Create a `native_tvalue` wrapper, and then also add them here
using Response = std::optional<Arguments>; using Response = std::optional<Arguments>;
Steinberg::TUID cid; ArrayUID cid;
template <typename S> template <typename S>
void serialize(S& s) { void serialize(S& s) {
@@ -24,8 +24,7 @@
#include <pluginterfaces/base/ipluginbase.h> #include <pluginterfaces/base/ipluginbase.h>
#include "../../bitsery/ext/vst3.h" #include "../../bitsery/ext/vst3.h"
#include "base.h"
using Steinberg::int32, Steinberg::tresult;
// TODO: After implementing one or two more of these, abstract away some of the // TODO: After implementing one or two more of these, abstract away some of the
// nasty bits // nasty bits
+3 -1
View File
@@ -53,9 +53,11 @@ void Vst3Bridge::run() {
overload{ overload{
[&](const YaComponent::Create& args) [&](const YaComponent::Create& args)
-> YaComponent::Create::Response { -> YaComponent::Create::Response {
Steinberg::TUID cid;
std::copy(args.cid.begin(), args.cid.end(), cid);
Steinberg::IPtr<Steinberg::Vst::IComponent> component = Steinberg::IPtr<Steinberg::Vst::IComponent> component =
module->getFactory() module->getFactory()
.createInstance<Steinberg::Vst::IComponent>(args.cid); .createInstance<Steinberg::Vst::IComponent>(cid);
if (component) { if (component) {
std::lock_guard lock(component_instances_mutex); std::lock_guard lock(component_instances_mutex);