From d0aeeaba2ade0d63511c3cd5074bc7d3293aa94c Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 7 Sep 2022 17:18:28 +0200 Subject: [PATCH] Move CLAP version clamping to a function --- src/common/serialization/clap/plugin.cpp | 11 ++----- src/common/serialization/clap/version.h | 37 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 src/common/serialization/clap/version.h diff --git a/src/common/serialization/clap/plugin.cpp b/src/common/serialization/clap/plugin.cpp index 534dca0e..49a36255 100644 --- a/src/common/serialization/clap/plugin.cpp +++ b/src/common/serialization/clap/plugin.cpp @@ -16,6 +16,8 @@ #include "plugin.h" +#include "version.h" + namespace clap { namespace plugin { @@ -46,14 +48,7 @@ descriptor::descriptor(const clap_plugin_descriptor_t& original) const clap_plugin_descriptor_t* descriptor::get() const { // This should be the minimum of yabridge's supported CLAP version and // the plugin's supported CLAP version - clap_version_t supported_clap_version = clap_version; - if (CLAP_VERSION_MAJOR < clap_version.major || - (clap_version.major == CLAP_VERSION_MAJOR && - (CLAP_VERSION_MINOR < clap_version.minor || - (clap_version.minor == CLAP_VERSION_MINOR && - CLAP_VERSION_REVISION < clap_version.revision)))) { - supported_clap_version = CLAP_VERSION; - } + clap_version_t supported_clap_version = clamp_clap_version(clap_version); // `features_ptrs` needs to be populated as an envp-style null terminated // array diff --git a/src/common/serialization/clap/version.h b/src/common/serialization/clap/version.h new file mode 100644 index 00000000..5fcee8af --- /dev/null +++ b/src/common/serialization/clap/version.h @@ -0,0 +1,37 @@ +// yabridge: a Wine plugin bridge +// Copyright (C) 2020-2022 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 + +/** + * Return the minimum of the given CLAP version and the CLAP version currently + * supported by the SDK. + */ +inline clap_version_t clamp_clap_version(clap_version_t version) { + if (CLAP_VERSION_MAJOR < version.major || + (version.major == CLAP_VERSION_MAJOR && + (CLAP_VERSION_MINOR < version.minor || + (version.minor == CLAP_VERSION_MINOR && + CLAP_VERSION_REVISION < version.revision)))) { + return CLAP_VERSION; + } else { + return version; + } +}