mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-14 20:40:03 +02:00
Implement the CLAP latency extension
This commit is contained in:
@@ -48,6 +48,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_latency_vtable(clap_host_latency_t{
|
||||
.changed = ext_latency_changed,
|
||||
}),
|
||||
ext_note_ports_vtable(clap_host_note_ports_t{
|
||||
.supported_dialects = ext_note_ports_supported_dialects,
|
||||
.rescan = ext_note_ports_rescan,
|
||||
@@ -71,6 +74,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_latency &&
|
||||
strcmp(extension_id, CLAP_EXT_LATENCY) == 0) {
|
||||
extension_ptr = &self->ext_latency_vtable;
|
||||
} else if (self->supported_extensions_.supports_note_ports &&
|
||||
strcmp(extension_id, CLAP_EXT_NOTE_PORTS) == 0) {
|
||||
extension_ptr = &self->ext_note_ports_vtable;
|
||||
@@ -157,6 +163,14 @@ 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_latency_changed(const clap_host_t* host) {
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<const clap_host_proxy*>(host->host_data);
|
||||
|
||||
self->bridge_.send_main_thread_message(clap::ext::latency::host::Changed{
|
||||
.owner_instance_id = self->owner_instance_id()});
|
||||
}
|
||||
|
||||
uint32_t CLAP_ABI
|
||||
clap_host_proxy::ext_note_ports_supported_dialects(const clap_host_t* host) {
|
||||
assert(host && host->host_data);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <atomic>
|
||||
|
||||
#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>
|
||||
@@ -72,6 +73,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_latency_changed(const clap_host_t* host);
|
||||
|
||||
static uint32_t CLAP_ABI
|
||||
ext_note_ports_supported_dialects(const clap_host_t* host);
|
||||
static void CLAP_ABI ext_note_ports_rescan(const clap_host_t* host,
|
||||
@@ -109,6 +112,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_latency_t ext_latency_vtable;
|
||||
const clap_host_note_ports_t ext_note_ports_vtable;
|
||||
const clap_host_params_t ext_params_vtable;
|
||||
const clap_host_tail_t ext_tail_vtable;
|
||||
|
||||
@@ -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))),
|
||||
latency(static_cast<const clap_plugin_latency_t*>(
|
||||
plugin.get_extension(&plugin, CLAP_EXT_LATENCY))),
|
||||
note_ports(static_cast<const clap_plugin_note_ports_t*>(
|
||||
plugin.get_extension(&plugin, CLAP_EXT_NOTE_PORTS))),
|
||||
params(static_cast<const clap_plugin_params_t*>(
|
||||
@@ -42,6 +44,7 @@ clap::plugin::SupportedPluginExtensions ClapPluginExtensions::supported()
|
||||
const noexcept {
|
||||
return clap::plugin::SupportedPluginExtensions{
|
||||
.supports_audio_ports = audio_ports != nullptr,
|
||||
.supports_latency = latency != nullptr,
|
||||
.supports_note_ports = note_ports != nullptr,
|
||||
.supports_params = params != nullptr,
|
||||
.supports_tail = tail != nullptr};
|
||||
@@ -342,6 +345,14 @@ void ClapBridge::run() {
|
||||
.result = std::nullopt};
|
||||
}
|
||||
},
|
||||
[&](clap::ext::latency::plugin::Get& request)
|
||||
-> clap::ext::latency::plugin::Get::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
// We'll ignore the main thread requirement for simple lookups
|
||||
// to avoid the synchronisation costs in hot code paths
|
||||
return instance.extensions.latency->get(instance.plugin.get());
|
||||
},
|
||||
[&](const clap::ext::note_ports::plugin::Count& request)
|
||||
-> clap::ext::note_ports::plugin::Count::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_latency_t* latency = nullptr;
|
||||
const clap_plugin_note_ports_t* note_ports = nullptr;
|
||||
const clap_plugin_params_t* params = nullptr;
|
||||
const clap_plugin_tail_t* tail = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user