mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-16 13:40:05 +02:00
Fully implement the CLAP params extension
This commit is contained in:
@@ -51,6 +51,11 @@ clap_host_proxy::clap_host_proxy(ClapBridge& bridge,
|
||||
ext_note_ports_vtable(clap_host_note_ports_t{
|
||||
.supported_dialects = ext_note_ports_supported_dialects,
|
||||
.rescan = ext_note_ports_rescan,
|
||||
}),
|
||||
ext_params_vtable(clap_host_params_t{
|
||||
.rescan = ext_params_rescan,
|
||||
.clear = ext_params_clear,
|
||||
.request_flush = ext_params_request_flush,
|
||||
}) {}
|
||||
|
||||
const void* CLAP_ABI
|
||||
@@ -66,6 +71,9 @@ clap_host_proxy::host_get_extension(const struct clap_host* host,
|
||||
} else if (self->supported_extensions_.supports_note_ports &&
|
||||
strcmp(extension_id, CLAP_EXT_NOTE_PORTS) == 0) {
|
||||
extension_ptr = &self->ext_note_ports_vtable;
|
||||
} else if (self->supported_extensions_.supports_params &&
|
||||
strcmp(extension_id, CLAP_EXT_PARAMS) == 0) {
|
||||
extension_ptr = &self->ext_params_vtable;
|
||||
}
|
||||
|
||||
self->bridge_.logger_.log_extension_query("clap_host::get_extension",
|
||||
@@ -161,3 +169,35 @@ void CLAP_ABI clap_host_proxy::ext_note_ports_rescan(const clap_host_t* host,
|
||||
self->bridge_.send_main_thread_message(clap::ext::note_ports::host::Rescan{
|
||||
.owner_instance_id = self->owner_instance_id(), .flags = flags});
|
||||
}
|
||||
|
||||
void CLAP_ABI
|
||||
clap_host_proxy::ext_params_rescan(const clap_host_t* host,
|
||||
clap_param_rescan_flags flags) {
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<clap_host_proxy*>(host->host_data);
|
||||
|
||||
self->bridge_.send_main_thread_message(clap::ext::params::host::Rescan{
|
||||
.owner_instance_id = self->owner_instance_id(), .flags = flags});
|
||||
}
|
||||
|
||||
void CLAP_ABI clap_host_proxy::ext_params_clear(const clap_host_t* host,
|
||||
clap_id param_id,
|
||||
clap_param_clear_flags flags) {
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<clap_host_proxy*>(host->host_data);
|
||||
|
||||
self->bridge_.send_main_thread_message(clap::ext::params::host::Clear{
|
||||
.owner_instance_id = self->owner_instance_id(),
|
||||
.param_id = param_id,
|
||||
.flags = flags});
|
||||
}
|
||||
|
||||
void CLAP_ABI
|
||||
clap_host_proxy::ext_params_request_flush(const clap_host_t* host) {
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<clap_host_proxy*>(host->host_data);
|
||||
|
||||
self->bridge_.send_main_thread_message(
|
||||
clap::ext::params::host::RequestFlush{.owner_instance_id =
|
||||
self->owner_instance_id()});
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <clap/ext/audio-ports.h>
|
||||
#include <clap/ext/note-ports.h>
|
||||
#include <clap/ext/params.h>
|
||||
#include <clap/host.h>
|
||||
|
||||
#include "../../common/serialization/clap/plugin-factory.h"
|
||||
@@ -75,6 +76,13 @@ class clap_host_proxy {
|
||||
static void CLAP_ABI ext_note_ports_rescan(const clap_host_t* host,
|
||||
uint32_t flags);
|
||||
|
||||
static void CLAP_ABI ext_params_rescan(const clap_host_t* host,
|
||||
clap_param_rescan_flags flags);
|
||||
static void CLAP_ABI ext_params_clear(const clap_host_t* host,
|
||||
clap_id param_id,
|
||||
clap_param_clear_flags flags);
|
||||
static void CLAP_ABI ext_params_request_flush(const clap_host_t* host);
|
||||
|
||||
/**
|
||||
* The extensions supported by the host, set just before calling
|
||||
* `clap_plugin::init()` on the bridged plugin. We'll allow the plugin to
|
||||
@@ -99,6 +107,7 @@ class clap_host_proxy {
|
||||
// called `clap_plugin::init()`.
|
||||
const clap_host_audio_ports ext_audio_ports_vtable;
|
||||
const clap_host_note_ports ext_note_ports_vtable;
|
||||
const clap_host_params ext_params_vtable;
|
||||
|
||||
/**
|
||||
* Keeps track of whether there are pending host callbacks. Used to prevent
|
||||
|
||||
@@ -30,7 +30,9 @@ 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))),
|
||||
note_ports(static_cast<const clap_plugin_note_ports_t*>(
|
||||
plugin.get_extension(&plugin, CLAP_EXT_NOTE_PORTS))) {}
|
||||
plugin.get_extension(&plugin, CLAP_EXT_NOTE_PORTS))),
|
||||
params(static_cast<const clap_plugin_params_t*>(
|
||||
plugin.get_extension(&plugin, CLAP_EXT_PARAMS))) {}
|
||||
|
||||
ClapPluginExtensions::ClapPluginExtensions() noexcept {}
|
||||
|
||||
@@ -38,7 +40,8 @@ clap::plugin::SupportedPluginExtensions ClapPluginExtensions::supported()
|
||||
const noexcept {
|
||||
return clap::plugin::SupportedPluginExtensions{
|
||||
.supports_audio_ports = audio_ports != nullptr,
|
||||
.supports_note_ports = note_ports != nullptr};
|
||||
.supports_note_ports = note_ports != nullptr,
|
||||
.supports_params = params != nullptr};
|
||||
}
|
||||
|
||||
ClapPluginInstance::ClapPluginInstance(
|
||||
@@ -362,6 +365,81 @@ void ClapBridge::run() {
|
||||
.result = std::nullopt};
|
||||
}
|
||||
},
|
||||
[&](const clap::ext::params::plugin::Count& request)
|
||||
-> clap::ext::params::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 code code paths
|
||||
return instance.extensions.params->count(instance.plugin.get());
|
||||
},
|
||||
[&](const clap::ext::params::plugin::GetInfo& request)
|
||||
-> clap::ext::params::plugin::GetInfo::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 code code paths
|
||||
clap_param_info_t param_info{};
|
||||
if (instance.extensions.params->get_info(instance.plugin.get(),
|
||||
request.param_index,
|
||||
¶m_info)) {
|
||||
return clap::ext::params::plugin::GetInfoResponse{
|
||||
.result = param_info};
|
||||
} else {
|
||||
return clap::ext::params::plugin::GetInfoResponse{
|
||||
.result = std::nullopt};
|
||||
}
|
||||
},
|
||||
[&](const clap::ext::params::plugin::GetValue& request)
|
||||
-> clap::ext::params::plugin::GetValue::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 code code paths
|
||||
double value;
|
||||
if (instance.extensions.params->get_value(
|
||||
instance.plugin.get(), request.param_id, &value)) {
|
||||
return clap::ext::params::plugin::GetValueResponse{
|
||||
.result = value};
|
||||
} else {
|
||||
return clap::ext::params::plugin::GetValueResponse{
|
||||
.result = std::nullopt};
|
||||
}
|
||||
},
|
||||
[&](const clap::ext::params::plugin::ValueToText& request)
|
||||
-> clap::ext::params::plugin::ValueToText::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 code code paths
|
||||
std::array<char, 1024> display{0};
|
||||
if (instance.extensions.params->value_to_text(
|
||||
instance.plugin.get(), request.param_id, request.value,
|
||||
display.data(), display.size())) {
|
||||
return clap::ext::params::plugin::ValueToTextResponse{
|
||||
.result = display.data()};
|
||||
} else {
|
||||
return clap::ext::params::plugin::ValueToTextResponse{
|
||||
.result = std::nullopt};
|
||||
}
|
||||
},
|
||||
[&](const clap::ext::params::plugin::TextToValue& request)
|
||||
-> clap::ext::params::plugin::TextToValue::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 code code paths
|
||||
double value;
|
||||
if (instance.extensions.params->text_to_value(
|
||||
instance.plugin.get(), request.param_id,
|
||||
request.display.c_str(), &value)) {
|
||||
return clap::ext::params::plugin::TextToValueResponse{
|
||||
.result = value};
|
||||
} else {
|
||||
return clap::ext::params::plugin::TextToValueResponse{
|
||||
.result = std::nullopt};
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -570,6 +648,17 @@ void ClapBridge::register_plugin_instance(
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
[&](const clap::ext::params::plugin::Flush& request)
|
||||
-> clap::ext::params::plugin::Flush::Response {
|
||||
const auto& [instance, _] =
|
||||
get_instance(request.instance_id);
|
||||
|
||||
// TODO: Implement this
|
||||
// instance.extensions.params->flush(instance.plugin.get(),
|
||||
// in, out);
|
||||
|
||||
return clap::ext::params::plugin::FlushResponse{};
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ struct ClapPluginExtensions {
|
||||
|
||||
const clap_plugin_audio_ports_t* audio_ports = nullptr;
|
||||
const clap_plugin_note_ports_t* note_ports = nullptr;
|
||||
const clap_plugin_params_t* params = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user