From 39b0f75fad8caeae7b52cb52be735055213e2c41 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 21 Oct 2022 17:02:28 +0200 Subject: [PATCH] Add structs for the CLAP note name extension --- src/common/serialization/clap.h | 1 + .../serialization/clap/ext/note-name.cpp | 41 ++++++ src/common/serialization/clap/ext/note-name.h | 136 ++++++++++++++++++ src/plugin/meson.build | 1 + src/wine-host/meson.build | 1 + 5 files changed, 180 insertions(+) create mode 100644 src/common/serialization/clap/ext/note-name.cpp create mode 100644 src/common/serialization/clap/ext/note-name.h diff --git a/src/common/serialization/clap.h b/src/common/serialization/clap.h index 2b123207..50a93dfb 100644 --- a/src/common/serialization/clap.h +++ b/src/common/serialization/clap.h @@ -28,6 +28,7 @@ #include "clap/ext/gui.h" #include "clap/ext/latency.h" #include "clap/ext/log.h" +#include "clap/ext/note-name.h" #include "clap/ext/note-ports.h" #include "clap/ext/params.h" #include "clap/ext/render.h" diff --git a/src/common/serialization/clap/ext/note-name.cpp b/src/common/serialization/clap/ext/note-name.cpp new file mode 100644 index 00000000..7e3b6f93 --- /dev/null +++ b/src/common/serialization/clap/ext/note-name.cpp @@ -0,0 +1,41 @@ +// 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 . + +#include "note-name.h" + +#include "../../../utils.h" + +namespace clap { +namespace ext { +namespace note_name { + +NoteName::NoteName(const clap_note_name_t& original) + : name(original.name), + port(original.port), + key(original.key), + channel(original.channel) {} + +void NoteName::reconstruct(clap_note_name_t& note_name) const { + note_name = clap_note_name_t{}; + strlcpy_buffer(note_name.name, name); + note_name.port = port; + note_name.key = key; + note_name.channel = channel; +} + +} // namespace note_name +} // namespace ext +} // namespace clap diff --git a/src/common/serialization/clap/ext/note-name.h b/src/common/serialization/clap/ext/note-name.h new file mode 100644 index 00000000..545925c3 --- /dev/null +++ b/src/common/serialization/clap/ext/note-name.h @@ -0,0 +1,136 @@ +// 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 +#include + +#include + +#include "../../../bitsery/ext/in-place-optional.h" +#include "../../common.h" + +// Serialization messages for `clap/ext/note-name.h` + +namespace clap { +namespace ext { +namespace note_name { + +/** + * A serializable version of `clap_note_name_t` that owns all of the data it + * references. + */ +struct NoteName { + /** + * Parse a native `clap_note_name_t` struct so it can be serialized and sent + * to the Wine plugin host. + */ + NoteName(const clap_note_name_t& original); + + /** + * Default constructor for bitsery. + */ + NoteName() {} + + /** + * Write the stored information to a host provided struct. + */ + void reconstruct(clap_note_name_t& note_name) const; + + std::string name; + int16_t port; + int16_t key; + int16_t channel; + + template + void serialize(S& s) { + s.text1b(name, 4096); + s.value2b(port); + s.value2b(key); + s.value2b(channel); + } +}; + +namespace plugin { + +/** + * Message struct for `clap_plugin_note_name::count()`. + */ +struct Count { + using Response = PrimitiveResponse; + + native_size_t instance_id; + + template + void serialize(S& s) { + s.value8b(instance_id); + } +}; + +/** + * The response to the `clap::ext::note_name::plugin::Get` message defined + * below. + */ +struct GetResponse { + std::optional result; + + template + void serialize(S& s) { + s.ext(result, bitsery::ext::InPlaceOptional()); + } +}; + +/** + * Message struct for `clap_plugin_note_name::get()`. + */ +struct Get { + using Response = GetResponse; + + native_size_t instance_id; + uint32_t index; + + template + void serialize(S& s) { + s.value8b(instance_id); + s.value4b(index); + } +}; + +} // namespace plugin + +namespace host { + +/** + * Message struct for `clap_host_note_name::changed()`. + */ +struct Changed { + using Response = Ack; + + native_size_t owner_instance_id; + + template + void serialize(S& s) { + s.value8b(owner_instance_id); + } +}; + +} // namespace host + +} // namespace note_name +} // namespace ext +} // namespace clap diff --git a/src/plugin/meson.build b/src/plugin/meson.build index 5fb94e59..d53e45bd 100644 --- a/src/plugin/meson.build +++ b/src/plugin/meson.build @@ -79,6 +79,7 @@ if with_clap '../common/process.cpp', '../common/serialization/clap/ext/audio-ports.cpp', '../common/serialization/clap/ext/audio-ports-config.cpp', + '../common/serialization/clap/ext/note-name.cpp', '../common/serialization/clap/ext/note-ports.cpp', '../common/serialization/clap/ext/params.cpp', '../common/serialization/clap/events.cpp', diff --git a/src/wine-host/meson.build b/src/wine-host/meson.build index 7892e521..20273123 100644 --- a/src/wine-host/meson.build +++ b/src/wine-host/meson.build @@ -82,6 +82,7 @@ if with_clap '../common/logging/clap.cpp', '../common/serialization/clap/ext/audio-ports.cpp', '../common/serialization/clap/ext/audio-ports-config.cpp', + '../common/serialization/clap/ext/note-name.cpp', '../common/serialization/clap/ext/note-ports.cpp', '../common/serialization/clap/ext/params.cpp', '../common/serialization/clap/events.cpp',