mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Add serialization for CLAP plugin descriptors
This commit is contained in:
@@ -9,7 +9,7 @@ Yabridge currently tracks CLAP 1.1.1. The implementation status for CLAP's core
|
||||
| core feature | status |
|
||||
| ----------------------------------------- | --------------------- |
|
||||
| Core plugin and host functionality | :x: Work in progress |
|
||||
| `clap.plugin-factory` | :x: Work in progress |
|
||||
| `clap.plugin-factory` | :heavy_check_mark: |
|
||||
| `clap.plugin-invalidation-factory/draft0` | :x: Not supported yet |
|
||||
|
||||
| extension | status |
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "plugin.h"
|
||||
|
||||
namespace clap {
|
||||
namespace plugin {
|
||||
|
||||
descriptor::descriptor(const clap_plugin_descriptor_t& original)
|
||||
: clap_version(original.clap_version),
|
||||
id((assert(original.id), original.id)),
|
||||
name((assert(original.id), original.id)),
|
||||
vendor(original.vendor ? std::optional(original.vendor) : std::nullopt),
|
||||
url(original.url ? std::optional(original.url) : std::nullopt),
|
||||
manual_url(original.manual_url ? std::optional(original.manual_url)
|
||||
: std::nullopt),
|
||||
support_url(original.support_url ? std::optional(original.support_url)
|
||||
: std::nullopt),
|
||||
version(original.version ? std::optional(original.version)
|
||||
: std::nullopt),
|
||||
description(original.description ? std::optional(original.description)
|
||||
: std::nullopt) {
|
||||
// The features array is stored as an envp-style null terminated array
|
||||
const char** orig_features = original.features;
|
||||
if (orig_features) {
|
||||
while (*orig_features) {
|
||||
features.push_back(*orig_features);
|
||||
orig_features++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// `features_ptrs` needs to be populated as envp-style null terminated array
|
||||
features_ptrs.resize(features.size() + 1);
|
||||
for (size_t i = 0; i < features.size(); i++) {
|
||||
features_ptrs[i] = features[i].c_str();
|
||||
}
|
||||
features_ptrs[features.size()] = nullptr;
|
||||
|
||||
return clap_plugin_descriptor_t{
|
||||
.clap_version = supported_clap_version,
|
||||
.id = id.c_str(),
|
||||
.name = name.c_str(),
|
||||
.vendor = vendor ? vendor->c_str() : nullptr,
|
||||
.url = url ? url->c_str() : nullptr,
|
||||
.manual_url = manual_url ? manual_url->c_str() : nullptr,
|
||||
.support_url = support_url ? support_url->c_str() : nullptr,
|
||||
.version = version ? version->c_str() : nullptr,
|
||||
.description = description ? description->c_str() : nullptr,
|
||||
.features = features_ptrs.data(),
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace plugin
|
||||
} // namespace clap
|
||||
@@ -0,0 +1,111 @@
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <bitsery/traits/vector.h>
|
||||
#include <clap/plugin.h>
|
||||
|
||||
#include "../../bitsery/ext/in-place-optional.h"
|
||||
|
||||
// Serialization messages for `clap/plugin.h`
|
||||
|
||||
namespace clap {
|
||||
namespace plugin {
|
||||
|
||||
/**
|
||||
* Owned wrapper around `clap_plugin_descriptor` for serialization purposes.
|
||||
*/
|
||||
struct descriptor {
|
||||
/**
|
||||
* Parse a plugin-provided descriptor so it can be serialized and sent to
|
||||
* the native CLAP plugin.
|
||||
*/
|
||||
descriptor(const clap_plugin_descriptor_t& original);
|
||||
|
||||
/**
|
||||
* Default constructor for bitsery.
|
||||
*/
|
||||
descriptor() {}
|
||||
|
||||
/**
|
||||
* We'll report the maximum of the plugin's supported CLAP version and
|
||||
* yabridge's supported CLAP version. I don't know why there's a version
|
||||
* field here when the entry point also has a version field.
|
||||
*/
|
||||
clap_version_t clap_version;
|
||||
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::optional<std::string> vendor;
|
||||
std::optional<std::string> url;
|
||||
std::optional<std::string> manual_url;
|
||||
std::optional<std::string> support_url;
|
||||
std::optional<std::string> version;
|
||||
std::optional<std::string> description;
|
||||
|
||||
std::vector<std::string> features;
|
||||
|
||||
/**
|
||||
* Create a CLAP plugin descriptor from this wrapper. This contains pointers
|
||||
* to this object's fields, so this descriptor is only valid as long as this
|
||||
* object is alive and doesn't get moved.
|
||||
*/
|
||||
clap_plugin_descriptor_t get() const;
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s) {
|
||||
s.object(clap_version);
|
||||
|
||||
s.text1b(id, 4096);
|
||||
s.text1b(name, 4096);
|
||||
s.ext(vendor, bitsery::ext::InPlaceOptional(),
|
||||
[](S& s, auto& v) { s.text1b(v, 4096); });
|
||||
s.ext(url, bitsery::ext::InPlaceOptional(),
|
||||
[](S& s, auto& v) { s.text1b(v, 4096); });
|
||||
s.ext(manual_url, bitsery::ext::InPlaceOptional(),
|
||||
[](S& s, auto& v) { s.text1b(v, 4096); });
|
||||
s.ext(support_url, bitsery::ext::InPlaceOptional(),
|
||||
[](S& s, auto& v) { s.text1b(v, 4096); });
|
||||
s.ext(version, bitsery::ext::InPlaceOptional(),
|
||||
[](S& s, auto& v) { s.text1b(v, 4096); });
|
||||
s.ext(description, bitsery::ext::InPlaceOptional(),
|
||||
[](S& s, auto& v) { s.text1b(v, 4096); });
|
||||
|
||||
s.container(features, 4096, [](S& s, auto& v) { s.text1b(v, 4096); });
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* A null terminated array of pointers to the features in `features`.
|
||||
* Populated as part of `get()`.
|
||||
*/
|
||||
mutable std::vector<const char*> features_ptrs;
|
||||
};
|
||||
|
||||
} // namespace plugin
|
||||
} // namespace clap
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s, clap_version_t& version) {
|
||||
s.value4b(version.major);
|
||||
s.value4b(version.minor);
|
||||
s.value4b(version.revision);
|
||||
}
|
||||
@@ -77,6 +77,7 @@ if with_clap
|
||||
'../common/notifications.cpp',
|
||||
'../common/plugins.cpp',
|
||||
'../common/process.cpp',
|
||||
'../common/serialization/clap/plugin.cpp',
|
||||
'../common/utils.cpp',
|
||||
'../include/llvm/small-vector.cpp',
|
||||
'bridges/clap.cpp',
|
||||
|
||||
@@ -80,6 +80,7 @@ host_sources = files(
|
||||
if with_clap
|
||||
host_sources += files(
|
||||
'../common/logging/clap.cpp',
|
||||
'../common/serialization/clap/plugin.cpp',
|
||||
'bridges/clap.cpp',
|
||||
)
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user