mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-08 12:30:12 +02:00
Fully implement the CLAP params extension
This commit is contained in:
@@ -22,7 +22,9 @@ 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))),
|
||||
note_ports(static_cast<const clap_host_note_ports_t*>(
|
||||
host.get_extension(&host, CLAP_EXT_NOTE_PORTS))) {}
|
||||
host.get_extension(&host, CLAP_EXT_NOTE_PORTS))),
|
||||
params(static_cast<const clap_host_params_t*>(
|
||||
host.get_extension(&host, CLAP_EXT_PARAMS))) {}
|
||||
|
||||
ClapHostExtensions::ClapHostExtensions() noexcept {}
|
||||
|
||||
@@ -30,7 +32,8 @@ clap::host::SupportedHostExtensions ClapHostExtensions::supported()
|
||||
const noexcept {
|
||||
return clap::host::SupportedHostExtensions{
|
||||
.supports_audio_ports = audio_ports != nullptr,
|
||||
.supports_note_ports = note_ports != nullptr};
|
||||
.supports_note_ports = note_ports != nullptr,
|
||||
.supports_params = params != nullptr};
|
||||
}
|
||||
|
||||
clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
||||
@@ -63,6 +66,14 @@ clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
||||
.count = ext_note_ports_count,
|
||||
.get = ext_note_ports_get,
|
||||
}),
|
||||
ext_params_vtable(clap_plugin_params_t{
|
||||
.count = ext_params_count,
|
||||
.get_info = ext_params_get_info,
|
||||
.get_value = ext_params_get_value,
|
||||
.value_to_text = ext_params_value_to_text,
|
||||
.text_to_value = ext_params_text_to_value,
|
||||
.flush = ext_params_flush,
|
||||
}),
|
||||
// These function objects are relatively large, and we probably won't be
|
||||
// getting that many of them
|
||||
pending_callbacks_(128) {}
|
||||
@@ -196,6 +207,9 @@ clap_plugin_proxy::plugin_get_extension(const struct clap_plugin* plugin,
|
||||
} else if (self->supported_extensions_.supports_note_ports &&
|
||||
strcmp(id, CLAP_EXT_NOTE_PORTS) == 0) {
|
||||
extension_ptr = &self->ext_note_ports_vtable;
|
||||
} else if (self->supported_extensions_.supports_params &&
|
||||
strcmp(id, CLAP_EXT_PARAMS) == 0) {
|
||||
extension_ptr = &self->ext_params_vtable;
|
||||
}
|
||||
|
||||
self->bridge_.logger_.log_extension_query("clap_plugin::get_extension",
|
||||
@@ -284,3 +298,113 @@ clap_plugin_proxy::ext_note_ports_get(const clap_plugin_t* plugin,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t CLAP_ABI
|
||||
clap_plugin_proxy::ext_params_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::params::plugin::Count{.instance_id = self->instance_id()});
|
||||
}
|
||||
|
||||
bool CLAP_ABI
|
||||
clap_plugin_proxy::ext_params_get_info(const clap_plugin_t* plugin,
|
||||
uint32_t param_index,
|
||||
clap_param_info_t* param_info) {
|
||||
assert(plugin && plugin->plugin_data && param_info);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
const clap::ext::params::plugin::GetInfoResponse response =
|
||||
self->bridge_.send_main_thread_message(
|
||||
clap::ext::params::plugin::GetInfo{
|
||||
.instance_id = self->instance_id(),
|
||||
.param_index = param_index});
|
||||
if (response.result) {
|
||||
response.result->reconstruct(*param_info);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CLAP_ABI
|
||||
clap_plugin_proxy::ext_params_get_value(const clap_plugin_t* plugin,
|
||||
clap_id param_id,
|
||||
double* value) {
|
||||
assert(plugin && plugin->plugin_data && value);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
const clap::ext::params::plugin::GetValueResponse response =
|
||||
self->bridge_.send_main_thread_message(
|
||||
clap::ext::params::plugin::GetValue{
|
||||
.instance_id = self->instance_id(), .param_id = param_id});
|
||||
if (response.result) {
|
||||
*value = *response.result;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CLAP_ABI
|
||||
clap_plugin_proxy::ext_params_value_to_text(const clap_plugin_t* plugin,
|
||||
clap_id param_id,
|
||||
double value,
|
||||
char* display,
|
||||
uint32_t size) {
|
||||
assert(plugin && plugin->plugin_data && display);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
const clap::ext::params::plugin::ValueToTextResponse response =
|
||||
self->bridge_.send_main_thread_message(
|
||||
clap::ext::params::plugin::ValueToText{
|
||||
.instance_id = self->instance_id(),
|
||||
.param_id = param_id,
|
||||
.value = value});
|
||||
if (response.result) {
|
||||
strlcpy_buffer(display, *response.result, size);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CLAP_ABI
|
||||
clap_plugin_proxy::ext_params_text_to_value(const clap_plugin_t* plugin,
|
||||
clap_id param_id,
|
||||
const char* display,
|
||||
double* value) {
|
||||
assert(plugin && plugin->plugin_data && display && value);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
const clap::ext::params::plugin::TextToValueResponse response =
|
||||
self->bridge_.send_main_thread_message(
|
||||
clap::ext::params::plugin::TextToValue{
|
||||
.instance_id = self->instance_id(),
|
||||
.param_id = param_id,
|
||||
.display = display});
|
||||
if (response.result) {
|
||||
*value = *response.result;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void CLAP_ABI
|
||||
clap_plugin_proxy::ext_params_flush(const clap_plugin_t* plugin,
|
||||
const clap_input_events_t* in,
|
||||
const clap_output_events_t* out) {
|
||||
assert(plugin && plugin->plugin_data);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
// This may also be called on the audio thread and it is never called during
|
||||
// process, so always using the audio thread here is safe
|
||||
self->bridge_.send_audio_thread_message(
|
||||
clap::ext::params::plugin::Flush{.instance_id = self->instance_id()});
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <clap/ext/audio-ports.h>
|
||||
#include <clap/ext/note-ports.h>
|
||||
#include <clap/ext/params.h>
|
||||
#include <clap/plugin.h>
|
||||
#include <rigtorp/MPMCQueue.h>
|
||||
#include <function2/function2.hpp>
|
||||
@@ -58,6 +59,7 @@ struct ClapHostExtensions {
|
||||
|
||||
const clap_host_audio_ports_t* audio_ports = nullptr;
|
||||
const clap_host_note_ports_t* note_ports = nullptr;
|
||||
const clap_host_params_t* params = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -139,6 +141,26 @@ class clap_plugin_proxy {
|
||||
bool is_input,
|
||||
clap_note_port_info_t* info);
|
||||
|
||||
static uint32_t CLAP_ABI ext_params_count(const clap_plugin_t* plugin);
|
||||
static bool CLAP_ABI ext_params_get_info(const clap_plugin_t* plugin,
|
||||
uint32_t param_index,
|
||||
clap_param_info_t* param_info);
|
||||
static bool CLAP_ABI ext_params_get_value(const clap_plugin_t* plugin,
|
||||
clap_id param_id,
|
||||
double* value);
|
||||
static bool CLAP_ABI ext_params_value_to_text(const clap_plugin_t* plugin,
|
||||
clap_id param_id,
|
||||
double value,
|
||||
char* display,
|
||||
uint32_t size);
|
||||
static bool CLAP_ABI ext_params_text_to_value(const clap_plugin_t* plugin,
|
||||
clap_id param_id,
|
||||
const char* display,
|
||||
double* value);
|
||||
static void CLAP_ABI ext_params_flush(const clap_plugin_t* plugin,
|
||||
const clap_input_events_t* in,
|
||||
const clap_output_events_t* out);
|
||||
|
||||
/**
|
||||
* Asynchronously run a function on the host's main thread, returning the
|
||||
* result as a future.
|
||||
@@ -207,6 +229,7 @@ class clap_plugin_proxy {
|
||||
// `clap_plugin::init()`.
|
||||
const clap_plugin_audio_ports ext_audio_ports_vtable;
|
||||
const clap_plugin_note_ports ext_note_ports_vtable;
|
||||
const clap_plugin_params ext_params_vtable;
|
||||
|
||||
/**
|
||||
* The extensions supported by the bridged plugin. Set after a successful
|
||||
|
||||
@@ -148,6 +148,48 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path)
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
[&](const clap::ext::params::host::Rescan& request)
|
||||
-> clap::ext::params::host::Rescan::Response {
|
||||
const auto& [plugin_proxy, _] =
|
||||
get_proxy(request.owner_instance_id);
|
||||
|
||||
plugin_proxy
|
||||
.run_on_main_thread(
|
||||
[&, host = plugin_proxy.host_,
|
||||
params = plugin_proxy.host_extensions_.params]() {
|
||||
params->rescan(host, request.flags);
|
||||
})
|
||||
.wait();
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
[&](const clap::ext::params::host::Clear& request)
|
||||
-> clap::ext::params::host::Clear::Response {
|
||||
const auto& [plugin_proxy, _] =
|
||||
get_proxy(request.owner_instance_id);
|
||||
|
||||
plugin_proxy
|
||||
.run_on_main_thread(
|
||||
[&, host = plugin_proxy.host_,
|
||||
params = plugin_proxy.host_extensions_.params]() {
|
||||
params->clear(host, request.param_id,
|
||||
request.flags);
|
||||
})
|
||||
.wait();
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
[&](const clap::ext::params::host::RequestFlush& request)
|
||||
-> clap::ext::params::host::RequestFlush::Response {
|
||||
const auto& [plugin_proxy, _] =
|
||||
get_proxy(request.owner_instance_id);
|
||||
|
||||
// This doesn't need to be called from the main thread
|
||||
plugin_proxy.host_extensions_.params->request_flush(
|
||||
plugin_proxy.host_);
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user