mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Implement the voice-info CLAP extension
This commit is contained in:
@@ -81,7 +81,8 @@ using ClapMainThreadControlRequest =
|
||||
clap::ext::params::plugin::ValueToText,
|
||||
clap::ext::params::plugin::TextToValue,
|
||||
clap::ext::state::plugin::Save,
|
||||
clap::ext::state::plugin::Load>;
|
||||
clap::ext::state::plugin::Load,
|
||||
clap::ext::voice_info::plugin::Get>;
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s, ClapMainThreadControlRequest& payload) {
|
||||
@@ -177,7 +178,8 @@ using ClapMainThreadCallbackRequest =
|
||||
clap::ext::note_ports::host::Rescan,
|
||||
clap::ext::params::host::Rescan,
|
||||
clap::ext::params::host::Clear,
|
||||
clap::ext::state::host::MarkDirty>;
|
||||
clap::ext::state::host::MarkDirty,
|
||||
clap::ext::voice_info::host::Changed>;
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s, ClapMainThreadCallbackRequest& payload) {
|
||||
|
||||
@@ -33,7 +33,7 @@ Yabridge currently tracks CLAP 1.1.1. The implementation status for CLAP's core
|
||||
| `clap.thread-check` | :heavy_check_mark: No bridging involved |
|
||||
| `clap.thread-pool` | :x: Not supported yet |
|
||||
| `clap.timer-support` | :x: Not supported yet |
|
||||
| `clap.voice-info` | :x: Not supported yet |
|
||||
| `clap.voice-info` | :heavy_check_mark: |
|
||||
|
||||
| draft extension | status |
|
||||
| -------------------------------- | --------------------- |
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <clap/ext/params.h>
|
||||
#include <clap/ext/state.h>
|
||||
#include <clap/ext/tail.h>
|
||||
#include <clap/ext/voice-info.h>
|
||||
|
||||
namespace clap {
|
||||
namespace host {
|
||||
@@ -35,7 +36,7 @@ Host::Host(const clap_host_t& original)
|
||||
url(original.url ? std::optional(original.url) : std::nullopt),
|
||||
version((assert(original.version), original.version)) {}
|
||||
|
||||
std::array<std::pair<bool, const char*>, 8> SupportedHostExtensions::list()
|
||||
std::array<std::pair<bool, const char*>, 9> SupportedHostExtensions::list()
|
||||
const noexcept {
|
||||
return {std::pair(supports_audio_ports, CLAP_EXT_AUDIO_PORTS),
|
||||
std::pair(supports_gui, CLAP_EXT_GUI),
|
||||
@@ -44,7 +45,8 @@ std::array<std::pair<bool, const char*>, 8> SupportedHostExtensions::list()
|
||||
std::pair(supports_note_ports, CLAP_EXT_NOTE_PORTS),
|
||||
std::pair(supports_params, CLAP_EXT_PARAMS),
|
||||
std::pair(supports_state, CLAP_EXT_STATE),
|
||||
std::pair(supports_tail, CLAP_EXT_TAIL)};
|
||||
std::pair(supports_tail, CLAP_EXT_TAIL),
|
||||
std::pair(supports_voice_info, CLAP_EXT_VOICE_INFO)};
|
||||
}
|
||||
|
||||
} // namespace host
|
||||
|
||||
@@ -89,12 +89,13 @@ struct SupportedHostExtensions {
|
||||
bool supports_params = false;
|
||||
bool supports_state = false;
|
||||
bool supports_tail = false;
|
||||
bool supports_voice_info = false;
|
||||
|
||||
/**
|
||||
* Get a list of `<bool, extension_name>` tuples for the supported
|
||||
* extensions. Used during logging.
|
||||
*/
|
||||
std::array<std::pair<bool, const char*>, 8> list() const noexcept;
|
||||
std::array<std::pair<bool, const char*>, 9> list() const noexcept;
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s) {
|
||||
@@ -106,6 +107,7 @@ struct SupportedHostExtensions {
|
||||
s.value1b(supports_params);
|
||||
s.value1b(supports_state);
|
||||
s.value1b(supports_tail);
|
||||
s.value1b(supports_voice_info);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <clap/ext/params.h>
|
||||
#include <clap/ext/state.h>
|
||||
#include <clap/ext/tail.h>
|
||||
#include <clap/ext/voice-info.h>
|
||||
|
||||
#include "version.h"
|
||||
|
||||
@@ -82,7 +83,7 @@ const clap_plugin_descriptor_t* Descriptor::get() const {
|
||||
return &clap_descriptor;
|
||||
}
|
||||
|
||||
std::array<std::pair<bool, const char*>, 7> SupportedPluginExtensions::list()
|
||||
std::array<std::pair<bool, const char*>, 8> SupportedPluginExtensions::list()
|
||||
const noexcept {
|
||||
return {std::pair(supports_audio_ports, CLAP_EXT_AUDIO_PORTS),
|
||||
std::pair(supports_gui, CLAP_EXT_GUI),
|
||||
@@ -90,7 +91,8 @@ std::array<std::pair<bool, const char*>, 7> SupportedPluginExtensions::list()
|
||||
std::pair(supports_note_ports, CLAP_EXT_NOTE_PORTS),
|
||||
std::pair(supports_params, CLAP_EXT_PARAMS),
|
||||
std::pair(supports_state, CLAP_EXT_STATE),
|
||||
std::pair(supports_tail, CLAP_EXT_TAIL)};
|
||||
std::pair(supports_tail, CLAP_EXT_TAIL),
|
||||
std::pair(supports_voice_info, CLAP_EXT_VOICE_INFO)};
|
||||
}
|
||||
|
||||
} // namespace plugin
|
||||
|
||||
@@ -122,12 +122,13 @@ struct SupportedPluginExtensions {
|
||||
bool supports_params = false;
|
||||
bool supports_state = false;
|
||||
bool supports_tail = false;
|
||||
bool supports_voice_info = false;
|
||||
|
||||
/**
|
||||
* Get a list of `<bool, extension_name>` tuples for the supported
|
||||
* extensions. Used during logging.
|
||||
*/
|
||||
std::array<std::pair<bool, const char*>, 7> list() const noexcept;
|
||||
std::array<std::pair<bool, const char*>, 8> list() const noexcept;
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s) {
|
||||
@@ -138,6 +139,7 @@ struct SupportedPluginExtensions {
|
||||
s.value1b(supports_params);
|
||||
s.value1b(supports_state);
|
||||
s.value1b(supports_tail);
|
||||
s.value1b(supports_voice_info);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,9 @@ ClapHostExtensions::ClapHostExtensions(const clap_host& host) noexcept
|
||||
state(static_cast<const clap_host_state_t*>(
|
||||
host.get_extension(&host, CLAP_EXT_STATE))),
|
||||
tail(static_cast<const clap_host_tail_t*>(
|
||||
host.get_extension(&host, CLAP_EXT_TAIL))) {}
|
||||
host.get_extension(&host, CLAP_EXT_TAIL))),
|
||||
voice_info(static_cast<const clap_host_voice_info_t*>(
|
||||
host.get_extension(&host, CLAP_EXT_VOICE_INFO))) {}
|
||||
|
||||
ClapHostExtensions::ClapHostExtensions() noexcept {}
|
||||
|
||||
@@ -48,7 +50,8 @@ clap::host::SupportedHostExtensions ClapHostExtensions::supported()
|
||||
.supports_note_ports = note_ports != nullptr,
|
||||
.supports_params = params != nullptr,
|
||||
.supports_state = state != nullptr,
|
||||
.supports_tail = tail != nullptr};
|
||||
.supports_tail = tail != nullptr,
|
||||
.supports_voice_info = voice_info != nullptr};
|
||||
}
|
||||
|
||||
clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
||||
@@ -116,6 +119,9 @@ clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
||||
ext_tail_vtable(clap_plugin_tail_t{
|
||||
.get = ext_tail_get,
|
||||
}),
|
||||
ext_voice_info_vtable(clap_plugin_voice_info_t{
|
||||
.get = ext_voice_info_get,
|
||||
}),
|
||||
// These function objects are relatively large, and we probably won't be
|
||||
// getting that many of them
|
||||
pending_callbacks_(128) {}
|
||||
@@ -309,6 +315,9 @@ clap_plugin_proxy::plugin_get_extension(const struct clap_plugin* plugin,
|
||||
} else if (self->supported_extensions_.supports_tail &&
|
||||
strcmp(id, CLAP_EXT_TAIL) == 0) {
|
||||
extension_ptr = &self->ext_tail_vtable;
|
||||
} else if (self->supported_extensions_.supports_voice_info &&
|
||||
strcmp(id, CLAP_EXT_VOICE_INFO) == 0) {
|
||||
extension_ptr = &self->ext_voice_info_vtable;
|
||||
}
|
||||
|
||||
self->bridge_.logger_.log_extension_query("clap_plugin::get_extension",
|
||||
@@ -757,3 +766,21 @@ uint32_t CLAP_ABI clap_plugin_proxy::ext_tail_get(const clap_plugin_t* plugin) {
|
||||
return self->bridge_.send_audio_thread_message(
|
||||
clap::ext::tail::plugin::Get{.instance_id = self->instance_id()});
|
||||
}
|
||||
|
||||
bool CLAP_ABI clap_plugin_proxy::ext_voice_info_get(const clap_plugin_t* plugin,
|
||||
clap_voice_info_t* info) {
|
||||
assert(plugin && plugin->plugin_data && info);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
const clap::ext::voice_info::plugin::GetResponse response =
|
||||
self->bridge_.send_main_thread_message(
|
||||
clap::ext::voice_info::plugin::Get{.instance_id =
|
||||
self->instance_id()});
|
||||
if (response.result) {
|
||||
*info = *response.result;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <clap/ext/params.h>
|
||||
#include <clap/ext/state.h>
|
||||
#include <clap/ext/tail.h>
|
||||
#include <clap/ext/voice-info.h>
|
||||
#include <clap/plugin.h>
|
||||
#include <rigtorp/MPMCQueue.h>
|
||||
#include <function2/function2.hpp>
|
||||
@@ -71,6 +72,7 @@ struct ClapHostExtensions {
|
||||
const clap_host_params_t* params = nullptr;
|
||||
const clap_host_state_t* state = nullptr;
|
||||
const clap_host_tail_t* tail = nullptr;
|
||||
const clap_host_voice_info_t* voice_info = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -263,6 +265,9 @@ class clap_plugin_proxy {
|
||||
|
||||
static uint32_t CLAP_ABI ext_tail_get(const clap_plugin_t* plugin);
|
||||
|
||||
static bool CLAP_ABI ext_voice_info_get(const clap_plugin_t* plugin,
|
||||
clap_voice_info_t* info);
|
||||
|
||||
private:
|
||||
ClapPluginBridge& bridge_;
|
||||
size_t instance_id_;
|
||||
@@ -326,6 +331,7 @@ class clap_plugin_proxy {
|
||||
const clap_plugin_params_t ext_params_vtable;
|
||||
const clap_plugin_state_t ext_state_vtable;
|
||||
const clap_plugin_tail_t ext_tail_vtable;
|
||||
const clap_plugin_voice_info_t ext_voice_info_vtable;
|
||||
|
||||
/**
|
||||
* The extensions supported by the bridged plugin. Set after a successful
|
||||
|
||||
@@ -259,6 +259,22 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path)
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
[&](const clap::ext::voice_info::host::Changed& request)
|
||||
-> clap::ext::voice_info::host::Changed::Response {
|
||||
const auto& [plugin_proxy, _] =
|
||||
get_proxy(request.owner_instance_id);
|
||||
|
||||
plugin_proxy
|
||||
.run_on_main_thread(
|
||||
[&, host = plugin_proxy.host_,
|
||||
voice_info =
|
||||
plugin_proxy.host_extensions_.voice_info]() {
|
||||
voice_info->changed(host);
|
||||
})
|
||||
.wait();
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -84,6 +84,9 @@ clap_host_proxy::clap_host_proxy(ClapBridge& bridge,
|
||||
ext_thread_check_vtable(clap_host_thread_check_t{
|
||||
.is_main_thread = ext_thread_check_is_main_thread,
|
||||
.is_audio_thread = ext_thread_check_is_audio_thread,
|
||||
}),
|
||||
ext_voice_info_vtable(clap_host_voice_info_t{
|
||||
.changed = ext_voice_info_changed,
|
||||
}) {}
|
||||
|
||||
const void* CLAP_ABI
|
||||
@@ -122,6 +125,9 @@ clap_host_proxy::host_get_extension(const struct clap_host* host,
|
||||
} else if (strcmp(extension_id, CLAP_EXT_THREAD_CHECK) == 0) {
|
||||
// This extension doesn't require any bridging
|
||||
extension_ptr = &self->ext_thread_check_vtable;
|
||||
} else if (self->supported_extensions_.supports_voice_info &&
|
||||
strcmp(extension_id, CLAP_EXT_VOICE_INFO) == 0) {
|
||||
extension_ptr = &self->ext_voice_info_vtable;
|
||||
}
|
||||
|
||||
self->bridge_.logger_.log_extension_query("clap_host::get_extension",
|
||||
@@ -432,3 +438,11 @@ clap_host_proxy::ext_thread_check_is_audio_thread(const clap_host_t* host) {
|
||||
// do audio thread stuff on the GUI thread everything's fine
|
||||
return !self->bridge_.main_context_.is_gui_thread();
|
||||
}
|
||||
|
||||
void CLAP_ABI clap_host_proxy::ext_voice_info_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::voice_info::host::Changed{
|
||||
.owner_instance_id = self->owner_instance_id()});
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <clap/ext/state.h>
|
||||
#include <clap/ext/tail.h>
|
||||
#include <clap/ext/thread-check.h>
|
||||
#include <clap/ext/voice-info.h>
|
||||
#include <clap/host.h>
|
||||
|
||||
#include "../../common/serialization/clap/plugin-factory.h"
|
||||
@@ -121,6 +122,8 @@ class clap_host_proxy {
|
||||
static bool CLAP_ABI
|
||||
ext_thread_check_is_audio_thread(const clap_host_t* host);
|
||||
|
||||
static void CLAP_ABI ext_voice_info_changed(const clap_host_t* host);
|
||||
|
||||
private:
|
||||
ClapBridge& bridge_;
|
||||
size_t owner_instance_id_;
|
||||
@@ -149,6 +152,7 @@ class clap_host_proxy {
|
||||
const clap_host_tail_t ext_tail_vtable;
|
||||
// This is always available regardless of the proxied host
|
||||
const clap_host_thread_check_t ext_thread_check_vtable;
|
||||
const clap_host_voice_info_t ext_voice_info_vtable;
|
||||
|
||||
/**
|
||||
* Keeps track of whether there are pending host callbacks. Used to prevent
|
||||
|
||||
@@ -40,7 +40,9 @@ ClapPluginExtensions::ClapPluginExtensions(const clap_plugin& plugin) noexcept
|
||||
state(static_cast<const clap_plugin_state_t*>(
|
||||
plugin.get_extension(&plugin, CLAP_EXT_STATE))),
|
||||
tail(static_cast<const clap_plugin_tail_t*>(
|
||||
plugin.get_extension(&plugin, CLAP_EXT_TAIL))) {}
|
||||
plugin.get_extension(&plugin, CLAP_EXT_TAIL))),
|
||||
voice_info(static_cast<const clap_plugin_voice_info_t*>(
|
||||
plugin.get_extension(&plugin, CLAP_EXT_VOICE_INFO))) {}
|
||||
|
||||
ClapPluginExtensions::ClapPluginExtensions() noexcept {}
|
||||
|
||||
@@ -53,7 +55,8 @@ clap::plugin::SupportedPluginExtensions ClapPluginExtensions::supported()
|
||||
.supports_note_ports = note_ports != nullptr,
|
||||
.supports_params = params != nullptr,
|
||||
.supports_state = state != nullptr,
|
||||
.supports_tail = tail != nullptr};
|
||||
.supports_tail = tail != nullptr,
|
||||
.supports_voice_info = voice_info != nullptr};
|
||||
}
|
||||
|
||||
ClapPluginInstance::ClapPluginInstance(
|
||||
@@ -736,6 +739,25 @@ void ClapBridge::run() {
|
||||
})
|
||||
.get();
|
||||
},
|
||||
[&](clap::ext::voice_info::plugin::Get& request)
|
||||
-> clap::ext::voice_info::plugin::Get::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
return main_context_
|
||||
.run_in_context([&, plugin = instance.plugin.get(),
|
||||
voice_info =
|
||||
instance.extensions.voice_info]() {
|
||||
clap_voice_info_t info{};
|
||||
if (voice_info->get(plugin, &info)) {
|
||||
return clap::ext::voice_info::plugin::GetResponse{
|
||||
.result = std::move(info)};
|
||||
} else {
|
||||
return clap::ext::voice_info::plugin::GetResponse{
|
||||
.result = std::nullopt};
|
||||
}
|
||||
})
|
||||
.get();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ struct ClapPluginExtensions {
|
||||
const clap_plugin_params_t* params = nullptr;
|
||||
const clap_plugin_state_t* state = nullptr;
|
||||
const clap_plugin_tail_t* tail = nullptr;
|
||||
const clap_plugin_voice_info_t* voice_info = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user