mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-15 13:00:02 +02:00
Implement CLAP note ports extension
This commit is contained in:
@@ -47,6 +47,10 @@ clap_host_proxy::clap_host_proxy(ClapBridge& bridge,
|
||||
ext_audio_ports_vtable(clap_host_audio_ports_t{
|
||||
.is_rescan_flag_supported = ext_audio_ports_is_rescan_flag_supported,
|
||||
.rescan = ext_audio_ports_rescan,
|
||||
}),
|
||||
ext_note_ports_vtable(clap_host_note_ports_t{
|
||||
.supported_dialects = ext_note_ports_supported_dialects,
|
||||
.rescan = ext_note_ports_rescan,
|
||||
}) {}
|
||||
|
||||
const void* CLAP_ABI
|
||||
@@ -135,3 +139,22 @@ void CLAP_ABI clap_host_proxy::ext_audio_ports_rescan(const clap_host_t* host,
|
||||
self->bridge_.send_main_thread_message(clap::ext::audio_ports::host::Rescan{
|
||||
.owner_instance_id = self->owner_instance_id(), .flags = flags});
|
||||
}
|
||||
|
||||
uint32_t CLAP_ABI
|
||||
clap_host_proxy::ext_note_ports_supported_dialects(const clap_host_t* host) {
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<clap_host_proxy*>(host->host_data);
|
||||
|
||||
return self->bridge_.send_main_thread_message(
|
||||
clap::ext::note_ports::host::SupportedDialects{
|
||||
.owner_instance_id = self->owner_instance_id()});
|
||||
}
|
||||
|
||||
void CLAP_ABI clap_host_proxy::ext_note_ports_rescan(const clap_host_t* host,
|
||||
uint32_t flags) {
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<clap_host_proxy*>(host->host_data);
|
||||
|
||||
self->bridge_.send_main_thread_message(clap::ext::note_ports::host::Rescan{
|
||||
.owner_instance_id = self->owner_instance_id(), .flags = flags});
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <atomic>
|
||||
|
||||
#include <clap/ext/audio-ports.h>
|
||||
#include <clap/ext/note-ports.h>
|
||||
#include <clap/host.h>
|
||||
|
||||
#include "../../common/serialization/clap/plugin-factory.h"
|
||||
@@ -69,6 +70,11 @@ class clap_host_proxy {
|
||||
static void CLAP_ABI ext_audio_ports_rescan(const clap_host_t* host,
|
||||
uint32_t flags);
|
||||
|
||||
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,
|
||||
uint32_t flags);
|
||||
|
||||
/**
|
||||
* The extensions supported by the host, set just before calling
|
||||
* `clap_plugin::init()` on the bridged plugin. We'll allow the plugin to
|
||||
@@ -92,6 +98,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 ext_audio_ports_vtable;
|
||||
const clap_host_note_ports ext_note_ports_vtable;
|
||||
|
||||
/**
|
||||
* Keeps track of whether there are pending host callbacks. Used to prevent
|
||||
|
||||
@@ -28,14 +28,17 @@ 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))) {}
|
||||
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))) {}
|
||||
|
||||
ClapPluginExtensions::ClapPluginExtensions() noexcept {}
|
||||
|
||||
clap::plugin::SupportedPluginExtensions ClapPluginExtensions::supported()
|
||||
const noexcept {
|
||||
return clap::plugin::SupportedPluginExtensions{.supports_audio_ports =
|
||||
audio_ports != nullptr};
|
||||
return clap::plugin::SupportedPluginExtensions{
|
||||
.supports_audio_ports = audio_ports != nullptr,
|
||||
.supports_note_ports = note_ports != nullptr};
|
||||
}
|
||||
|
||||
ClapPluginInstance::ClapPluginInstance(
|
||||
@@ -334,6 +337,30 @@ void ClapBridge::run() {
|
||||
.result = std::nullopt};
|
||||
}
|
||||
},
|
||||
[&](const clap::ext::note_ports::plugin::Count& request)
|
||||
-> clap::ext::note_ports::plugin::Count::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
return instance.extensions.note_ports->count(
|
||||
instance.plugin.get(), request.is_input);
|
||||
},
|
||||
[&](const clap::ext::note_ports::plugin::Get& request)
|
||||
-> clap::ext::note_ports::plugin::Get::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
// We'll also ignore the main thread requirement here for
|
||||
// performance's sake
|
||||
clap_note_port_info_t info{};
|
||||
if (instance.extensions.note_ports->get(
|
||||
instance.plugin.get(), request.index, request.is_input,
|
||||
&info)) {
|
||||
return clap::ext::note_ports::plugin::GetResponse{.result =
|
||||
info};
|
||||
} else {
|
||||
return clap::ext::note_ports::plugin::GetResponse{
|
||||
.result = std::nullopt};
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ struct ClapPluginExtensions {
|
||||
clap::plugin::SupportedPluginExtensions supported() const noexcept;
|
||||
|
||||
const clap_plugin_audio_ports_t* audio_ports = nullptr;
|
||||
const clap_plugin_note_ports_t* note_ports = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user