mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 20:10:13 +02:00
Implement CLAP note ports extension
This commit is contained in:
@@ -20,14 +20,17 @@
|
||||
|
||||
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))) {}
|
||||
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))) {}
|
||||
|
||||
ClapHostExtensions::ClapHostExtensions() noexcept {}
|
||||
|
||||
clap::host::SupportedHostExtensions ClapHostExtensions::supported()
|
||||
const noexcept {
|
||||
return clap::host::SupportedHostExtensions{.supports_audio_ports =
|
||||
audio_ports != nullptr};
|
||||
return clap::host::SupportedHostExtensions{
|
||||
.supports_audio_ports = audio_ports != nullptr,
|
||||
.supports_note_ports = note_ports != nullptr};
|
||||
}
|
||||
|
||||
clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
||||
@@ -56,6 +59,10 @@ clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
||||
.count = ext_audio_ports_count,
|
||||
.get = ext_audio_ports_get,
|
||||
}),
|
||||
ext_note_ports_vtable(clap_plugin_note_ports_t{
|
||||
.count = ext_note_ports_count,
|
||||
.get = ext_note_ports_get,
|
||||
}),
|
||||
// These function objects are relatively large, and we probably won't be
|
||||
// getting that many of them
|
||||
pending_callbacks_(128) {}
|
||||
@@ -178,6 +185,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_note_ports &&
|
||||
strcmp(id, CLAP_EXT_NOTE_PORTS) == 0) {
|
||||
extension_ptr = &self->ext_note_ports_vtable;
|
||||
}
|
||||
|
||||
self->bridge_.logger_.log_extension_query("clap_plugin::get_extension",
|
||||
@@ -232,3 +242,37 @@ clap_plugin_proxy::ext_audio_ports_get(const clap_plugin_t* plugin,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t CLAP_ABI
|
||||
clap_plugin_proxy::ext_note_ports_count(const clap_plugin_t* plugin,
|
||||
bool is_input) {
|
||||
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::note_ports::plugin::Count{.instance_id = self->instance_id(),
|
||||
.is_input = is_input});
|
||||
}
|
||||
|
||||
bool CLAP_ABI
|
||||
clap_plugin_proxy::ext_note_ports_get(const clap_plugin_t* plugin,
|
||||
uint32_t index,
|
||||
bool is_input,
|
||||
clap_note_port_info_t* info) {
|
||||
assert(plugin && plugin->plugin_data && info);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
const clap::ext::note_ports::plugin::GetResponse response =
|
||||
self->bridge_.send_main_thread_message(
|
||||
clap::ext::note_ports::plugin::Get{
|
||||
.instance_id = self->instance_id(),
|
||||
.index = index,
|
||||
.is_input = is_input});
|
||||
if (response.result) {
|
||||
response.result->reconstruct(*info);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <clap/ext/audio-ports.h>
|
||||
#include <clap/ext/note-ports.h>
|
||||
#include <clap/plugin.h>
|
||||
#include <rigtorp/MPMCQueue.h>
|
||||
#include <function2/function2.hpp>
|
||||
@@ -56,6 +57,7 @@ struct ClapHostExtensions {
|
||||
clap::host::SupportedHostExtensions supported() const noexcept;
|
||||
|
||||
const clap_host_audio_ports_t* audio_ports = nullptr;
|
||||
const clap_host_note_ports_t* note_ports = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -130,6 +132,13 @@ class clap_plugin_proxy {
|
||||
bool is_input,
|
||||
clap_audio_port_info_t* info);
|
||||
|
||||
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,
|
||||
uint32_t index,
|
||||
bool is_input,
|
||||
clap_note_port_info_t* info);
|
||||
|
||||
/**
|
||||
* Asynchronously run a function on the host's main thread, returning the
|
||||
* result as a future.
|
||||
@@ -186,6 +195,7 @@ class clap_plugin_proxy {
|
||||
// depends on whether the plugin supported this extension when we called
|
||||
// `clap_plugin::init()`.
|
||||
const clap_plugin_audio_ports ext_audio_ports_vtable;
|
||||
const clap_plugin_note_ports ext_note_ports_vtable;
|
||||
|
||||
/**
|
||||
* The extensions supported by the bridged plugin. Set after a successful
|
||||
|
||||
@@ -111,6 +111,39 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path)
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
[&](const clap::ext::note_ports::host::SupportedDialects&
|
||||
request)
|
||||
-> clap::ext::note_ports::host::SupportedDialects::
|
||||
Response {
|
||||
const auto& [plugin_proxy, _] =
|
||||
get_proxy(request.owner_instance_id);
|
||||
|
||||
return plugin_proxy
|
||||
.run_on_main_thread(
|
||||
[host = plugin_proxy.host_,
|
||||
note_ports = plugin_proxy.extensions_
|
||||
.note_ports]() {
|
||||
return note_ports->supported_dialects(
|
||||
host);
|
||||
})
|
||||
.get();
|
||||
},
|
||||
[&](const clap::ext::note_ports::host::Rescan& request)
|
||||
-> clap::ext::note_ports::host::Rescan::Response {
|
||||
const auto& [plugin_proxy, _] =
|
||||
get_proxy(request.owner_instance_id);
|
||||
|
||||
plugin_proxy
|
||||
.run_on_main_thread(
|
||||
[&, host = plugin_proxy.host_,
|
||||
note_ports =
|
||||
plugin_proxy.extensions_.note_ports]() {
|
||||
note_ports->rescan(host, request.flags);
|
||||
})
|
||||
.wait();
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user