mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-09 22:02:10 +02:00
Implement CLAP audio-ports-config extension
This commit is contained in:
@@ -53,6 +53,9 @@ clap_host_proxy::clap_host_proxy(ClapBridge& bridge,
|
||||
.is_rescan_flag_supported = ext_audio_ports_is_rescan_flag_supported,
|
||||
.rescan = ext_audio_ports_rescan,
|
||||
}),
|
||||
ext_audio_ports_config_vtable(clap_host_audio_ports_config_t{
|
||||
.rescan = ext_audio_ports_config_rescan,
|
||||
}),
|
||||
ext_gui_vtable(clap_host_gui_t{
|
||||
.resize_hints_changed = ext_gui_resize_hints_changed,
|
||||
.request_resize = ext_gui_request_resize,
|
||||
@@ -99,6 +102,9 @@ clap_host_proxy::host_get_extension(const struct clap_host* host,
|
||||
if (self->supported_extensions_.supports_audio_ports &&
|
||||
strcmp(extension_id, CLAP_EXT_AUDIO_PORTS) == 0) {
|
||||
extension_ptr = &self->ext_audio_ports_vtable;
|
||||
} else if (self->supported_extensions_.supports_audio_ports_config &&
|
||||
strcmp(extension_id, CLAP_EXT_AUDIO_PORTS_CONFIG) == 0) {
|
||||
extension_ptr = &self->ext_audio_ports_config_vtable;
|
||||
} else if (self->supported_extensions_.supports_gui &&
|
||||
strcmp(extension_id, CLAP_EXT_GUI) == 0) {
|
||||
extension_ptr = &self->ext_gui_vtable;
|
||||
@@ -208,6 +214,16 @@ void CLAP_ABI clap_host_proxy::ext_audio_ports_rescan(const clap_host_t* host,
|
||||
.owner_instance_id = self->owner_instance_id(), .flags = flags});
|
||||
}
|
||||
|
||||
void CLAP_ABI
|
||||
clap_host_proxy::ext_audio_ports_config_rescan(const clap_host_t* host) {
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<const clap_host_proxy*>(host->host_data);
|
||||
|
||||
self->bridge_.send_mutually_recursive_main_thread_message(
|
||||
clap::ext::audio_ports_config::host::Rescan{
|
||||
.owner_instance_id = self->owner_instance_id()});
|
||||
}
|
||||
|
||||
void CLAP_ABI
|
||||
clap_host_proxy::ext_gui_resize_hints_changed(const clap_host_t* host) {
|
||||
assert(host && host->host_data);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include <clap/ext/audio-ports-config.h>
|
||||
#include <clap/ext/audio-ports.h>
|
||||
#include <clap/ext/gui.h>
|
||||
#include <clap/ext/latency.h>
|
||||
@@ -86,6 +87,8 @@ class clap_host_proxy {
|
||||
static void CLAP_ABI ext_audio_ports_rescan(const clap_host_t* host,
|
||||
uint32_t flags);
|
||||
|
||||
static void CLAP_ABI ext_audio_ports_config_rescan(const clap_host_t* host);
|
||||
|
||||
static void CLAP_ABI ext_gui_resize_hints_changed(const clap_host_t* host);
|
||||
static bool CLAP_ABI ext_gui_request_resize(const clap_host_t* host,
|
||||
uint32_t width,
|
||||
@@ -140,6 +143,7 @@ class clap_host_proxy {
|
||||
// depends on whether the plugin supported this extension when the host
|
||||
// called `clap_plugin::init()`.
|
||||
const clap_host_audio_ports_t ext_audio_ports_vtable;
|
||||
const clap_host_audio_ports_config_t ext_audio_ports_config_vtable;
|
||||
const clap_host_gui_t ext_gui_vtable;
|
||||
const clap_host_latency_t ext_latency_vtable;
|
||||
// This is also always available regardless of the proxied host. That way we
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace fs = ghc::filesystem;
|
||||
ClapPluginExtensions::ClapPluginExtensions(const clap_plugin& plugin) noexcept
|
||||
: audio_ports(static_cast<const clap_plugin_audio_ports_t*>(
|
||||
plugin.get_extension(&plugin, CLAP_EXT_AUDIO_PORTS))),
|
||||
audio_ports_config(static_cast<const clap_plugin_audio_ports_config_t*>(
|
||||
plugin.get_extension(&plugin, CLAP_EXT_AUDIO_PORTS_CONFIG))),
|
||||
gui(static_cast<const clap_plugin_gui_t*>(
|
||||
plugin.get_extension(&plugin, CLAP_EXT_GUI))),
|
||||
latency(static_cast<const clap_plugin_latency_t*>(
|
||||
@@ -52,6 +54,7 @@ clap::plugin::SupportedPluginExtensions ClapPluginExtensions::supported()
|
||||
const noexcept {
|
||||
return clap::plugin::SupportedPluginExtensions{
|
||||
.supports_audio_ports = audio_ports != nullptr,
|
||||
.supports_audio_ports_config = audio_ports_config != nullptr,
|
||||
.supports_gui = gui != nullptr,
|
||||
.supports_latency = latency != nullptr,
|
||||
.supports_note_ports = note_ports != nullptr,
|
||||
@@ -357,6 +360,45 @@ void ClapBridge::run() {
|
||||
.result = std::nullopt};
|
||||
}
|
||||
},
|
||||
[&](const clap::ext::audio_ports_config::plugin::Count& request)
|
||||
-> clap::ext::audio_ports_config::plugin::Count::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
// We'll ignore the main thread requirement for simple array
|
||||
// lookups to avoid the synchronisation costs in hot code paths
|
||||
return instance.extensions.audio_ports_config->count(
|
||||
instance.plugin.get());
|
||||
},
|
||||
[&](const clap::ext::audio_ports_config::plugin::Get& request)
|
||||
-> clap::ext::audio_ports_config::plugin::Get::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
// We'll ignore the main thread requirement for simple array
|
||||
// lookups to avoid the synchronisation costs in hot code paths
|
||||
clap_audio_ports_config_t config{};
|
||||
if (instance.extensions.audio_ports_config->get(
|
||||
instance.plugin.get(), request.index, &config)) {
|
||||
return clap::ext::audio_ports_config::plugin::GetResponse{
|
||||
.result = config};
|
||||
} else {
|
||||
return clap::ext::audio_ports_config::plugin::GetResponse{
|
||||
.result = std::nullopt};
|
||||
}
|
||||
},
|
||||
[&](const clap::ext::audio_ports_config::plugin::Select& request)
|
||||
-> clap::ext::audio_ports_config::plugin::Select::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
return main_context_
|
||||
.run_in_context(
|
||||
[&, plugin = instance.plugin.get(),
|
||||
audio_ports_config =
|
||||
instance.extensions.audio_ports_config]() {
|
||||
return audio_ports_config->select(
|
||||
plugin, request.config_id);
|
||||
})
|
||||
.get();
|
||||
},
|
||||
[&](const clap::ext::gui::plugin::IsApiSupported& request)
|
||||
-> clap::ext::gui::plugin::IsApiSupported::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
@@ -67,6 +67,7 @@ struct ClapPluginExtensions {
|
||||
clap::plugin::SupportedPluginExtensions supported() const noexcept;
|
||||
|
||||
const clap_plugin_audio_ports_t* audio_ports = nullptr;
|
||||
const clap_plugin_audio_ports_config_t* audio_ports_config = nullptr;
|
||||
const clap_plugin_gui_t* gui = nullptr;
|
||||
const clap_plugin_latency_t* latency = nullptr;
|
||||
const clap_plugin_note_ports_t* note_ports = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user