Implement the CLAP latency extension

This commit is contained in:
Robbert van der Helm
2022-09-26 18:26:42 +02:00
parent 3e0cd725a3
commit c7ea37309d
16 changed files with 171 additions and 5 deletions
@@ -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))),
latency(static_cast<const clap_host_latency_t*>(
host.get_extension(&host, CLAP_EXT_LATENCY))),
note_ports(static_cast<const clap_host_note_ports_t*>(
host.get_extension(&host, CLAP_EXT_NOTE_PORTS))),
params(static_cast<const clap_host_params_t*>(
@@ -34,6 +36,7 @@ clap::host::SupportedHostExtensions ClapHostExtensions::supported()
const noexcept {
return clap::host::SupportedHostExtensions{
.supports_audio_ports = audio_ports != nullptr,
.supports_latency = latency != nullptr,
.supports_note_ports = note_ports != nullptr,
.supports_params = params != nullptr,
.supports_tail = tail != nullptr};
@@ -65,6 +68,9 @@ clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
.count = ext_audio_ports_count,
.get = ext_audio_ports_get,
}),
ext_latency_vtable(clap_plugin_latency_t{
.get = ext_latency_get,
}),
ext_note_ports_vtable(clap_plugin_note_ports_t{
.count = ext_note_ports_count,
.get = ext_note_ports_get,
@@ -210,6 +216,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_latency &&
strcmp(id, CLAP_EXT_LATENCY) == 0) {
extension_ptr = &self->ext_latency_vtable;
} else if (self->supported_extensions_.supports_note_ports &&
strcmp(id, CLAP_EXT_NOTE_PORTS) == 0) {
extension_ptr = &self->ext_note_ports_vtable;
@@ -274,6 +283,15 @@ clap_plugin_proxy::ext_audio_ports_get(const clap_plugin_t* plugin,
}
}
uint32_t CLAP_ABI
clap_plugin_proxy::ext_latency_get(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::latency::plugin::Get{.instance_id = self->instance_id()});
}
uint32_t CLAP_ABI
clap_plugin_proxy::ext_note_ports_count(const clap_plugin_t* plugin,
bool is_input) {
@@ -21,6 +21,7 @@
#include <vector>
#include <clap/ext/audio-ports.h>
#include <clap/ext/latency.h>
#include <clap/ext/note-ports.h>
#include <clap/ext/params.h>
#include <clap/ext/tail.h>
@@ -60,6 +61,7 @@ struct ClapHostExtensions {
clap::host::SupportedHostExtensions supported() const noexcept;
const clap_host_audio_ports_t* audio_ports = nullptr;
const clap_host_latency_t* latency = nullptr;
const clap_host_note_ports_t* note_ports = nullptr;
const clap_host_params_t* params = nullptr;
const clap_host_tail_t* tail = nullptr;
@@ -137,6 +139,8 @@ class clap_plugin_proxy {
bool is_input,
clap_audio_port_info_t* info);
static uint32_t CLAP_ABI ext_latency_get(const clap_plugin_t* plugin);
static uint32_t CLAP_ABI ext_note_ports_count(const clap_plugin_t* plugin,
bool is_input);
static bool CLAP_ABI ext_note_ports_get(const clap_plugin_t* plugin,
@@ -240,6 +244,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_latency_t ext_latency_vtable;
const clap_plugin_note_ports_t ext_note_ports_vtable;
const clap_plugin_params_t ext_params_vtable;
const clap_plugin_tail_t ext_tail_vtable;
+16
View File
@@ -115,6 +115,22 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path)
return Ack{};
},
[&](const clap::ext::latency::host::Changed& request)
-> clap::ext::latency::host::Changed::Response {
const auto& [plugin_proxy, _] =
get_proxy(request.owner_instance_id);
plugin_proxy
.run_on_main_thread(
[&, host = plugin_proxy.host_,
latency =
plugin_proxy.host_extensions_.latency]() {
latency->changed(host);
})
.wait();
return Ack{};
},
[&](const clap::ext::note_ports::host::SupportedDialects&
request)
-> clap::ext::note_ports::host::SupportedDialects::