diff --git a/src/common/serialization/clap.h b/src/common/serialization/clap.h index f2b2f74d..5b6bdcaa 100644 --- a/src/common/serialization/clap.h +++ b/src/common/serialization/clap.h @@ -23,6 +23,7 @@ #include "../bitsery/ext/message-reference.h" #include "../utils.h" #include "clap/events.h" +#include "clap/ext/audio-ports-config.h" #include "clap/ext/audio-ports.h" #include "clap/ext/gui.h" #include "clap/ext/latency.h" diff --git a/src/common/serialization/clap/ext/audio-ports-config.cpp b/src/common/serialization/clap/ext/audio-ports-config.cpp new file mode 100644 index 00000000..57280b05 --- /dev/null +++ b/src/common/serialization/clap/ext/audio-ports-config.cpp @@ -0,0 +1,58 @@ +// 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 "audio-ports-config.h" + +#include "../../../utils.h" + +namespace clap { +namespace ext { +namespace audio_ports_config { + +AudioPortsConfig::AudioPortsConfig(const clap_audio_ports_config_t& original) + : id(original.id), + name(original.name), + input_port_count(original.input_port_count), + output_port_count(original.output_port_count), + has_main_input(original.has_main_input), + main_input_channel_count(original.main_input_channel_count), + main_input_port_type(clap::ext::audio_ports::parse_audio_port_type( + original.main_input_port_type)), + has_main_output(original.has_main_output), + main_output_channel_count(original.main_output_channel_count), + main_output_port_type(clap::ext::audio_ports::parse_audio_port_type( + original.main_output_port_type)) {} + +void AudioPortsConfig::reconstruct(clap_audio_ports_config_t& config) const { + config = clap_audio_ports_config_t{}; + config.id = id; + strlcpy_buffer(config.name, name); + config.input_port_count = input_port_count; + config.output_port_count = output_port_count; + config.has_main_input = has_main_input; + config.main_input_channel_count = main_input_channel_count; + config.main_input_port_type = + clap::ext::audio_ports::audio_port_type_to_string(main_input_port_type); + config.has_main_output = has_main_output; + config.main_output_channel_count = main_output_channel_count; + config.main_output_port_type = + clap::ext::audio_ports::audio_port_type_to_string( + main_output_port_type); +} + +} // namespace audio_ports_config +} // namespace ext +} // namespace clap diff --git a/src/common/serialization/clap/ext/audio-ports-config.h b/src/common/serialization/clap/ext/audio-ports-config.h new file mode 100644 index 00000000..825094f3 --- /dev/null +++ b/src/common/serialization/clap/ext/audio-ports-config.h @@ -0,0 +1,167 @@ +// 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" +#include "audio-ports.h" + +// Serialization messages for `clap/ext/audio-ports-config.h` + +namespace clap { +namespace ext { +namespace audio_ports_config { + +/** + * A serializable version of `clap_audio_ports_config_t` that owns all of the + * data it references. + */ +struct AudioPortsConfig { + /** + * Parse a native `clap_audio_ports_config` struct so it can be serialized + * and sent to the Wine plugin host. + */ + AudioPortsConfig(const clap_audio_ports_config_t& original); + + /** + * Default constructor for bitsery. + */ + AudioPortsConfig() {} + + /** + * Write the stored configuration to a host provided struct. + */ + void reconstruct(clap_audio_ports_config_t& config) const; + + clap_id id; + std::string name; + uint32_t input_port_count; + uint32_t output_port_count; + + bool has_main_input; + uint32_t main_input_channel_count; + clap::ext::audio_ports::AudioPortType main_input_port_type; + + bool has_main_output; + uint32_t main_output_channel_count; + clap::ext::audio_ports::AudioPortType main_output_port_type; + + template + void serialize(S& s) { + s.value4b(id); + s.text1b(name, 4096); + s.value4b(input_port_count); + s.value4b(output_port_count); + s.value1b(has_main_input); + s.value4b(main_input_channel_count); + s.value4b(main_input_port_type); + s.value1b(has_main_output); + s.value4b(main_output_channel_count); + s.value4b(main_output_port_type); + } +}; + +namespace plugin { + +/** + * Message struct for `clap_plugin_audio_ports_config::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::audio_ports_config::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_audio_ports_config::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); + } +}; + +/** + * Message struct for `clap_plugin_audio_ports_config::select()`. + */ +struct Select { + using Response = PrimitiveResponse; + + native_size_t instance_id; + clap_id config_id; + + template + void serialize(S& s) { + s.value8b(instance_id); + s.value4b(config_id); + } +}; + +} // namespace plugin + +namespace host { + +/** + * Message struct for `clap_host_audio_ports_config::rescan()`. + */ +struct Rescan { + using Response = Ack; + + native_size_t owner_instance_id; + + template + void serialize(S& s) { + s.value8b(owner_instance_id); + } +}; + +} // namespace host + +} // namespace audio_ports_config +} // namespace ext +} // namespace clap diff --git a/src/common/serialization/clap/ext/audio-ports.h b/src/common/serialization/clap/ext/audio-ports.h index fdc93571..c3c94350 100644 --- a/src/common/serialization/clap/ext/audio-ports.h +++ b/src/common/serialization/clap/ext/audio-ports.h @@ -61,8 +61,8 @@ AudioPortType parse_audio_port_type(const char* port_type); const char* audio_port_type_to_string(AudioPortType port_type); /** - * A serializable version of `clap_audio_port_info` that owns all of the data it - * references. + * A serializable version of `clap_audio_port_info_t` that owns all of the data + * it references. */ struct AudioPortInfo { /** diff --git a/src/plugin/meson.build b/src/plugin/meson.build index 7a3fe7ee..5fb94e59 100644 --- a/src/plugin/meson.build +++ b/src/plugin/meson.build @@ -78,6 +78,7 @@ if with_clap '../common/plugins.cpp', '../common/process.cpp', '../common/serialization/clap/ext/audio-ports.cpp', + '../common/serialization/clap/ext/audio-ports-config.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 e4889a7a..7892e521 100644 --- a/src/wine-host/meson.build +++ b/src/wine-host/meson.build @@ -81,6 +81,7 @@ if with_clap host_sources += files( '../common/logging/clap.cpp', '../common/serialization/clap/ext/audio-ports.cpp', + '../common/serialization/clap/ext/audio-ports-config.cpp', '../common/serialization/clap/ext/note-ports.cpp', '../common/serialization/clap/ext/params.cpp', '../common/serialization/clap/events.cpp',