From 9c8b543d5d882db44a906f5ea129d1601e0bc397 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 29 Nov 2020 13:29:01 +0100 Subject: [PATCH] Split serialization.h into common and VST2 parts --- meson.build | 4 +- src/common/logging.h | 3 +- src/common/serialization/common.h | 90 +++++++++++++++++++ .../vst2.cpp} | 2 +- .../{serialization.h => serialization/vst2.h} | 73 +-------------- 5 files changed, 97 insertions(+), 75 deletions(-) create mode 100644 src/common/serialization/common.h rename src/common/{serialization.cpp => serialization/vst2.cpp} (99%) rename src/common/{serialization.h => serialization/vst2.h} (89%) diff --git a/meson.build b/meson.build index 9cabf1bc..62c857a2 100644 --- a/meson.build +++ b/meson.build @@ -105,7 +105,7 @@ shared_library( [ 'src/common/configuration.cpp', 'src/common/logging.cpp', - 'src/common/serialization.cpp', + 'src/common/serialization/vst2.cpp', 'src/common/communication.cpp', 'src/common/utils.cpp', 'src/plugin/host-process.cpp', @@ -130,7 +130,7 @@ shared_library( host_sources = [ 'src/common/configuration.cpp', 'src/common/logging.cpp', - 'src/common/serialization.cpp', + 'src/common/serialization/vst2.cpp', 'src/common/communication.cpp', 'src/common/utils.cpp', 'src/wine-host/bridges/vst2.cpp', diff --git a/src/common/logging.h b/src/common/logging.h index e01075fd..ef046f94 100644 --- a/src/common/logging.h +++ b/src/common/logging.h @@ -16,10 +16,11 @@ #pragma once +#include #include #include -#include "serialization.h" +#include "serialization/vst2.h" /** * Super basic logging facility meant for debugging malfunctioning VST diff --git a/src/common/serialization/common.h b/src/common/serialization/common.h new file mode 100644 index 00000000..7c9f60bc --- /dev/null +++ b/src/common/serialization/common.h @@ -0,0 +1,90 @@ +// 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 +#include + +// The plugin should always be compiled to a 64-bit version, but the host +// application can also be 32-bit to allow using 32-bit legacy Windows VST in a +// modern Linux VST host. Because of this we have to make sure to always use +// 64-bit integers in places where we would otherwise use `size_t` and +// `intptr_t`. Otherwise the binary serialization would break. The 64 <-> 32 bit +// conversion for the 32-bit host application won't cause any issues for us +// since we can't directly pass pointers between the plugin and the host anyway. + +#ifndef __WINE__ +// Sanity check for the plugin, both the 64 and 32 bit hosts should follow these +// conventions +static_assert(std::is_same_v); +static_assert(std::is_same_v); +#endif +using native_size_t = uint64_t; +using native_intptr_t = int64_t; + +// The cannonical overloading template for `std::visitor`, not sure why this +// isn't part of the standard library +template +struct overload : Ts... { + using Ts::operator()...; +}; +template +overload(Ts...) -> overload; + +/** + * An object containing the startup options for hosting a plugin in a plugin + * group process. These are the exact same options that would have been passed + * to `yabridge-host.exe` were the plugin to be hosted individually. + */ +struct GroupRequest { + std::string plugin_path; + std::string endpoint_base_dir; + + template + void serialize(S& s) { + s.text1b(plugin_path, 4096); + s.text1b(endpoint_base_dir, 4096); + } +}; + +template <> +struct std::hash { + std::size_t operator()(GroupRequest const& params) const noexcept { + std::hash hasher{}; + + return hasher(params.plugin_path) ^ + (hasher(params.endpoint_base_dir) << 1); + } +}; + +/** + * The response sent back after the group host process receives a `GroupRequest` + * object. This only holds the group process's PID because we need to know if + * the group process crashes while it is initializing the plugin to prevent us + * from waiting indefinitely for the socket to be connected to. + */ +struct GroupResponse { + pid_t pid; + + template + void serialize(S& s) { + s.value4b(pid); + } +}; diff --git a/src/common/serialization.cpp b/src/common/serialization/vst2.cpp similarity index 99% rename from src/common/serialization.cpp rename to src/common/serialization/vst2.cpp index a764a7e7..f0219559 100644 --- a/src/common/serialization.cpp +++ b/src/common/serialization/vst2.cpp @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "serialization.h" +#include "vst2.h" DynamicVstEvents::DynamicVstEvents(const VstEvents& c_events) : events(c_events.numEvents) { diff --git a/src/common/serialization.h b/src/common/serialization/vst2.h similarity index 89% rename from src/common/serialization.h rename to src/common/serialization/vst2.h index 03011b3d..ada95336 100644 --- a/src/common/serialization.h +++ b/src/common/serialization/vst2.h @@ -16,18 +16,16 @@ #pragma once -#include -#include #include #include #include -#include #include #include #include -#include "vst24.h" +#include "../vst24.h" +#include "common.h" // These constants are limits used by bitsery @@ -60,32 +58,6 @@ constexpr size_t max_midi_events = max_buffer_size / sizeof(size_t); */ constexpr size_t binary_buffer_size = 50 << 20; -// The plugin should always be compiled to a 64-bit version, but the host -// application can also be 32-bit to allow using 32-bit legacy Windows VST in a -// modern Linux VST host. Because of this we have to make sure to always use -// 64-bit integers in places where we would otherwise use `size_t` and -// `intptr_t`. Otherwise the binary serialization would break. The 64 <-> 32 bit -// conversion for the 32-bit host application won't cause any issues for us -// since we can't directly pass pointers between the plugin and the host anyway. - -#ifndef __WINE__ -// Sanity check for the plugin, both the 64 and 32 bit hosts should follow these -// conventions -static_assert(std::is_same_v); -static_assert(std::is_same_v); -#endif -using native_size_t = uint64_t; -using native_intptr_t = int64_t; - -// The cannonical overloading template for `std::visitor`, not sure why this -// isn't part of the standard library -template -struct overload : Ts... { - using Ts::operator()...; -}; -template -overload(Ts...) -> overload; - /** * Update an `AEffect` object, copying values from `updated_plugin` to `plugin`. * This will copy all flags and regular values, leaving all pointers in `plugin` @@ -601,44 +573,3 @@ struct AudioBuffers { s.value4b(sample_frames); } }; - -/** - * An object containing the startup options for hosting a plugin in a plugin - * group process. These are the exact same options that would have been passed - * to `yabridge-host.exe` were the plugin to be hosted individually. - */ -struct GroupRequest { - std::string plugin_path; - std::string endpoint_base_dir; - - template - void serialize(S& s) { - s.text1b(plugin_path, 4096); - s.text1b(endpoint_base_dir, 4096); - } -}; - -template <> -struct std::hash { - std::size_t operator()(GroupRequest const& params) const noexcept { - std::hash hasher{}; - - return hasher(params.plugin_path) ^ - (hasher(params.endpoint_base_dir) << 1); - } -}; - -/** - * The response sent back after the group host process receives a `GroupRequest` - * object. This only holds the group process's PID because we need to know if - * the group process crashes while it is initializing the plugin to prevent us - * from waiting indefinitely for the socket to be connected to. - */ -struct GroupResponse { - pid_t pid; - - template - void serialize(S& s) { - s.value4b(pid); - } -};