Implement CLAP note ports extension

This commit is contained in:
Robbert van der Helm
2022-09-13 18:08:08 +02:00
parent 4f514a82ff
commit d5f4d563d4
12 changed files with 172 additions and 13 deletions
+6 -2
View File
@@ -83,7 +83,9 @@ bool ClapLogger::log_request(bool is_host_plugin,
const auto& supported_extensions = request.supported_host_extensions; const auto& supported_extensions = request.supported_host_extensions;
for (const auto& [supported, extension_name] : for (const auto& [supported, extension_name] :
{std::pair(supported_extensions.supports_audio_ports, {std::pair(supported_extensions.supports_audio_ports,
CLAP_EXT_AUDIO_PORTS)}) { CLAP_EXT_AUDIO_PORTS),
std::pair(supported_extensions.supports_note_ports,
CLAP_EXT_NOTE_PORTS)}) {
if (!supported) { if (!supported) {
continue; continue;
} }
@@ -292,7 +294,9 @@ void ClapLogger::log_response(bool is_host_plugin,
const auto& supported_extensions = response.supported_plugin_extensions; const auto& supported_extensions = response.supported_plugin_extensions;
for (const auto& [supported, extension_name] : for (const auto& [supported, extension_name] :
{std::pair(supported_extensions.supports_audio_ports, {std::pair(supported_extensions.supports_audio_ports,
CLAP_EXT_AUDIO_PORTS)}) { CLAP_EXT_AUDIO_PORTS),
std::pair(supported_extensions.supports_note_ports,
CLAP_EXT_NOTE_PORTS)}) {
if (!supported) { if (!supported) {
continue; continue;
} }
+6 -2
View File
@@ -50,7 +50,9 @@ using ClapMainThreadControlRequest =
clap::plugin::Activate, clap::plugin::Activate,
clap::plugin::Deactivate, clap::plugin::Deactivate,
clap::ext::audio_ports::plugin::Count, clap::ext::audio_ports::plugin::Count,
clap::ext::audio_ports::plugin::Get>; clap::ext::audio_ports::plugin::Get,
clap::ext::note_ports::plugin::Count,
clap::ext::note_ports::plugin::Get>;
template <typename S> template <typename S>
void serialize(S& s, ClapMainThreadControlRequest& payload) { void serialize(S& s, ClapMainThreadControlRequest& payload) {
@@ -134,7 +136,9 @@ using ClapMainThreadCallbackRequest =
clap::host::RequestRestart, clap::host::RequestRestart,
clap::host::RequestProcess, clap::host::RequestProcess,
clap::ext::audio_ports::host::IsRescanFlagSupported, clap::ext::audio_ports::host::IsRescanFlagSupported,
clap::ext::audio_ports::host::Rescan>; clap::ext::audio_ports::host::Rescan,
clap::ext::note_ports::host::SupportedDialects,
clap::ext::note_ports::host::Rescan>;
template <typename S> template <typename S>
void serialize(S& s, ClapMainThreadCallbackRequest& payload) { void serialize(S& s, ClapMainThreadCallbackRequest& payload) {
+1 -1
View File
@@ -21,7 +21,7 @@ Yabridge currently tracks CLAP 1.1.1. The implementation status for CLAP's core
| `clap.latency` | :x: Not supported yet | | `clap.latency` | :x: Not supported yet |
| `clap.log` | :x: Not supported yet | | `clap.log` | :x: Not supported yet |
| `clap.note-name` | :x: Not supported yet | | `clap.note-name` | :x: Not supported yet |
| `clap.note-ports` | :x: Not supported yet | | `clap.note-ports` | :heavy_check_mark: |
| `clap.params` | :x: Not supported yet | | `clap.params` | :x: Not supported yet |
| `clap.posix-fd-support` | :x: Not supported yet | | `clap.posix-fd-support` | :x: Not supported yet |
| `clap.render` | :x: Not supported yet | | `clap.render` | :x: Not supported yet |
+4 -1
View File
@@ -80,12 +80,15 @@ struct Host {
* available to the bridged CLAP plugins using proxies. * available to the bridged CLAP plugins using proxies.
*/ */
struct SupportedHostExtensions { struct SupportedHostExtensions {
// Don't forget to add new extensions to the log output // Don't forget to add new extensions to the logger and to the serialize
// method
bool supports_audio_ports = false; bool supports_audio_ports = false;
bool supports_note_ports = false;
template <typename S> template <typename S>
void serialize(S& s) { void serialize(S& s) {
s.value1b(supports_audio_ports); s.value1b(supports_audio_ports);
s.value1b(supports_note_ports);
} }
}; };
+4 -1
View File
@@ -113,12 +113,15 @@ struct Descriptor {
* created by `ClapPluginExtensions::supported()`. * created by `ClapPluginExtensions::supported()`.
*/ */
struct SupportedPluginExtensions { struct SupportedPluginExtensions {
// Don't forget to add new extensions to the log output // Don't forget to add new extensions to the logger and to the serialize
// method
bool supports_audio_ports = false; bool supports_audio_ports = false;
bool supports_note_ports = false;
template <typename S> template <typename S>
void serialize(S& s) { void serialize(S& s) {
s.value1b(supports_audio_ports); s.value1b(supports_audio_ports);
s.value1b(supports_note_ports);
} }
}; };
+47 -3
View File
@@ -20,14 +20,17 @@
ClapHostExtensions::ClapHostExtensions(const clap_host& host) noexcept ClapHostExtensions::ClapHostExtensions(const clap_host& host) noexcept
: audio_ports(static_cast<const clap_host_audio_ports_t*>( : 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 {} ClapHostExtensions::ClapHostExtensions() noexcept {}
clap::host::SupportedHostExtensions ClapHostExtensions::supported() clap::host::SupportedHostExtensions ClapHostExtensions::supported()
const noexcept { const noexcept {
return clap::host::SupportedHostExtensions{.supports_audio_ports = return clap::host::SupportedHostExtensions{
audio_ports != nullptr}; .supports_audio_ports = audio_ports != nullptr,
.supports_note_ports = note_ports != nullptr};
} }
clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge, 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, .count = ext_audio_ports_count,
.get = ext_audio_ports_get, .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 // These function objects are relatively large, and we probably won't be
// getting that many of them // getting that many of them
pending_callbacks_(128) {} 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 && if (self->supported_extensions_.supports_audio_ports &&
strcmp(id, CLAP_EXT_AUDIO_PORTS) == 0) { strcmp(id, CLAP_EXT_AUDIO_PORTS) == 0) {
extension_ptr = &self->ext_audio_ports_vtable; 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", 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; 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 <vector>
#include <clap/ext/audio-ports.h> #include <clap/ext/audio-ports.h>
#include <clap/ext/note-ports.h>
#include <clap/plugin.h> #include <clap/plugin.h>
#include <rigtorp/MPMCQueue.h> #include <rigtorp/MPMCQueue.h>
#include <function2/function2.hpp> #include <function2/function2.hpp>
@@ -56,6 +57,7 @@ struct ClapHostExtensions {
clap::host::SupportedHostExtensions supported() const noexcept; clap::host::SupportedHostExtensions supported() const noexcept;
const clap_host_audio_ports_t* audio_ports = nullptr; 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, bool is_input,
clap_audio_port_info_t* info); 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 * Asynchronously run a function on the host's main thread, returning the
* result as a future. * result as a future.
@@ -186,6 +195,7 @@ class clap_plugin_proxy {
// depends on whether the plugin supported this extension when we called // depends on whether the plugin supported this extension when we called
// `clap_plugin::init()`. // `clap_plugin::init()`.
const clap_plugin_audio_ports ext_audio_ports_vtable; 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 * The extensions supported by the bridged plugin. Set after a successful
+33
View File
@@ -111,6 +111,39 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path)
return Ack{}; 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{};
},
}); });
}); });
} }
@@ -47,6 +47,10 @@ clap_host_proxy::clap_host_proxy(ClapBridge& bridge,
ext_audio_ports_vtable(clap_host_audio_ports_t{ ext_audio_ports_vtable(clap_host_audio_ports_t{
.is_rescan_flag_supported = ext_audio_ports_is_rescan_flag_supported, .is_rescan_flag_supported = ext_audio_ports_is_rescan_flag_supported,
.rescan = ext_audio_ports_rescan, .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 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{ self->bridge_.send_main_thread_message(clap::ext::audio_ports::host::Rescan{
.owner_instance_id = self->owner_instance_id(), .flags = flags}); .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 <atomic>
#include <clap/ext/audio-ports.h> #include <clap/ext/audio-ports.h>
#include <clap/ext/note-ports.h>
#include <clap/host.h> #include <clap/host.h>
#include "../../common/serialization/clap/plugin-factory.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, static void CLAP_ABI ext_audio_ports_rescan(const clap_host_t* host,
uint32_t flags); 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 * The extensions supported by the host, set just before calling
* `clap_plugin::init()` on the bridged plugin. We'll allow the plugin to * `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 // depends on whether the plugin supported this extension when the host
// called `clap_plugin::init()`. // called `clap_plugin::init()`.
const clap_host_audio_ports ext_audio_ports_vtable; 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 * Keeps track of whether there are pending host callbacks. Used to prevent
+30 -3
View File
@@ -28,14 +28,17 @@ namespace fs = ghc::filesystem;
ClapPluginExtensions::ClapPluginExtensions(const clap_plugin& plugin) noexcept ClapPluginExtensions::ClapPluginExtensions(const clap_plugin& plugin) noexcept
: audio_ports(static_cast<const clap_plugin_audio_ports_t*>( : 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 {} ClapPluginExtensions::ClapPluginExtensions() noexcept {}
clap::plugin::SupportedPluginExtensions ClapPluginExtensions::supported() clap::plugin::SupportedPluginExtensions ClapPluginExtensions::supported()
const noexcept { const noexcept {
return clap::plugin::SupportedPluginExtensions{.supports_audio_ports = return clap::plugin::SupportedPluginExtensions{
audio_ports != nullptr}; .supports_audio_ports = audio_ports != nullptr,
.supports_note_ports = note_ports != nullptr};
} }
ClapPluginInstance::ClapPluginInstance( ClapPluginInstance::ClapPluginInstance(
@@ -334,6 +337,30 @@ void ClapBridge::run() {
.result = std::nullopt}; .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};
}
},
}); });
} }
+1
View File
@@ -67,6 +67,7 @@ struct ClapPluginExtensions {
clap::plugin::SupportedPluginExtensions supported() const noexcept; clap::plugin::SupportedPluginExtensions supported() const noexcept;
const clap_plugin_audio_ports_t* audio_ports = nullptr; const clap_plugin_audio_ports_t* audio_ports = nullptr;
const clap_plugin_note_ports_t* note_ports = nullptr;
}; };
/** /**