mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 12:10:09 +02:00
Implement CLAP audio-ports-config extension
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
ClapHostExtensions::ClapHostExtensions(const clap_host& host) noexcept
|
||||
: audio_ports(static_cast<const clap_host_audio_ports_t*>(
|
||||
host.get_extension(&host, CLAP_EXT_AUDIO_PORTS))),
|
||||
audio_ports_config(static_cast<const clap_host_audio_ports_config_t*>(
|
||||
host.get_extension(&host, CLAP_EXT_AUDIO_PORTS_CONFIG))),
|
||||
gui(static_cast<const clap_host_gui_t*>(
|
||||
host.get_extension(&host, CLAP_EXT_GUI))),
|
||||
latency(static_cast<const clap_host_latency_t*>(
|
||||
@@ -44,6 +46,7 @@ clap::host::SupportedHostExtensions ClapHostExtensions::supported()
|
||||
const noexcept {
|
||||
return clap::host::SupportedHostExtensions{
|
||||
.supports_audio_ports = audio_ports != nullptr,
|
||||
.supports_audio_ports_config = audio_ports_config != nullptr,
|
||||
.supports_gui = gui != nullptr,
|
||||
.supports_latency = latency != nullptr,
|
||||
.supports_log = log != nullptr,
|
||||
@@ -80,6 +83,11 @@ clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
||||
.count = ext_audio_ports_count,
|
||||
.get = ext_audio_ports_get,
|
||||
}),
|
||||
ext_audio_ports_config_vtable(clap_plugin_audio_ports_config_t{
|
||||
.count = ext_audio_ports_config_count,
|
||||
.get = ext_audio_ports_config_get,
|
||||
.select = ext_audio_ports_config_select,
|
||||
}),
|
||||
ext_gui_vtable(clap_plugin_gui_t{
|
||||
.is_api_supported = ext_gui_is_api_supported,
|
||||
.get_preferred_api = ext_gui_get_preferred_api,
|
||||
@@ -302,6 +310,9 @@ clap_plugin_proxy::plugin_get_extension(const struct clap_plugin* plugin,
|
||||
if (self->supported_extensions_.supports_audio_ports &&
|
||||
strcmp(id, CLAP_EXT_AUDIO_PORTS) == 0) {
|
||||
extension_ptr = &self->ext_audio_ports_vtable;
|
||||
} else if (self->supported_extensions_.supports_audio_ports_config &&
|
||||
strcmp(id, CLAP_EXT_AUDIO_PORTS_CONFIG) == 0) {
|
||||
extension_ptr = &self->ext_audio_ports_config_vtable;
|
||||
} else if (self->supported_extensions_.supports_gui &&
|
||||
strcmp(id, CLAP_EXT_GUI) == 0) {
|
||||
extension_ptr = &self->ext_gui_vtable;
|
||||
@@ -381,6 +392,47 @@ clap_plugin_proxy::ext_audio_ports_get(const clap_plugin_t* plugin,
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t CLAP_ABI
|
||||
clap_plugin_proxy::ext_audio_ports_config_count(const clap_plugin_t* plugin) {
|
||||
assert(plugin && plugin->plugin_data);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
return self->bridge_.send_main_thread_message(
|
||||
clap::ext::audio_ports_config::plugin::Count{.instance_id =
|
||||
self->instance_id()});
|
||||
}
|
||||
|
||||
bool CLAP_ABI clap_plugin_proxy::ext_audio_ports_config_get(
|
||||
const clap_plugin_t* plugin,
|
||||
uint32_t index,
|
||||
clap_audio_ports_config_t* config) {
|
||||
assert(plugin && plugin->plugin_data && config);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
const clap::ext::audio_ports_config::plugin::GetResponse response =
|
||||
self->bridge_.send_main_thread_message(
|
||||
clap::ext::audio_ports_config::plugin::Get{
|
||||
.instance_id = self->instance_id(), .index = index});
|
||||
if (response.result) {
|
||||
response.result->reconstruct(*config);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CLAP_ABI
|
||||
clap_plugin_proxy::ext_audio_ports_config_select(const clap_plugin_t* plugin,
|
||||
clap_id config_id) {
|
||||
assert(plugin && plugin->plugin_data);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
return self->bridge_.send_main_thread_message(
|
||||
clap::ext::audio_ports_config::plugin::Select{
|
||||
.instance_id = self->instance_id(), .config_id = config_id});
|
||||
}
|
||||
|
||||
bool CLAP_ABI
|
||||
clap_plugin_proxy::ext_gui_is_api_supported(const clap_plugin_t* plugin,
|
||||
const char* api,
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include <clap/ext/audio-ports-config.h>
|
||||
#include <clap/ext/audio-ports.h>
|
||||
#include <clap/ext/gui.h>
|
||||
#include <clap/ext/latency.h>
|
||||
@@ -66,6 +67,7 @@ struct ClapHostExtensions {
|
||||
clap::host::SupportedHostExtensions supported() const noexcept;
|
||||
|
||||
const clap_host_audio_ports_t* audio_ports = nullptr;
|
||||
const clap_host_audio_ports_config_t* audio_ports_config = nullptr;
|
||||
const clap_host_gui_t* gui = nullptr;
|
||||
const clap_host_latency_t* latency = nullptr;
|
||||
const clap_host_log_t* log = nullptr;
|
||||
@@ -196,6 +198,16 @@ class clap_plugin_proxy {
|
||||
bool is_input,
|
||||
clap_audio_port_info_t* info);
|
||||
|
||||
static uint32_t CLAP_ABI
|
||||
ext_audio_ports_config_count(const clap_plugin_t* plugin);
|
||||
static bool CLAP_ABI
|
||||
ext_audio_ports_config_get(const clap_plugin_t* plugin,
|
||||
uint32_t index,
|
||||
clap_audio_ports_config_t* config);
|
||||
static bool CLAP_ABI
|
||||
ext_audio_ports_config_select(const clap_plugin_t* plugin,
|
||||
clap_id config_id);
|
||||
|
||||
static bool CLAP_ABI ext_gui_is_api_supported(const clap_plugin_t* plugin,
|
||||
const char* api,
|
||||
bool is_floating);
|
||||
@@ -331,6 +343,7 @@ class clap_plugin_proxy {
|
||||
// depends on whether the plugin supported this extension when we called
|
||||
// `clap_plugin::init()`.
|
||||
const clap_plugin_audio_ports_t ext_audio_ports_vtable;
|
||||
const clap_plugin_audio_ports_config_t ext_audio_ports_config_vtable;
|
||||
const clap_plugin_gui_t ext_gui_vtable;
|
||||
const clap_plugin_latency_t ext_latency_vtable;
|
||||
const clap_plugin_note_ports_t ext_note_ports_vtable;
|
||||
|
||||
@@ -115,6 +115,22 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path)
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
[&](const clap::ext::audio_ports_config::host::Rescan& request)
|
||||
-> clap::ext::audio_ports_config::host::Rescan::Response {
|
||||
const auto& [plugin_proxy, _] =
|
||||
get_proxy(request.owner_instance_id);
|
||||
|
||||
plugin_proxy
|
||||
.run_on_main_thread(
|
||||
[&, host = plugin_proxy.host_,
|
||||
audio_ports_config = plugin_proxy.host_extensions_
|
||||
.audio_ports_config]() {
|
||||
audio_ports_config->rescan(host);
|
||||
})
|
||||
.wait();
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
[&](const clap::ext::gui::host::ResizeHintsChanged& request)
|
||||
-> clap::ext::gui::host::ResizeHintsChanged::Response {
|
||||
const auto& [plugin_proxy, _] =
|
||||
|
||||
Reference in New Issue
Block a user