mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Fully implement the state extension
This commit is contained in:
@@ -62,7 +62,9 @@ using ClapMainThreadControlRequest =
|
||||
clap::ext::params::plugin::GetInfo,
|
||||
clap::ext::params::plugin::GetValue,
|
||||
clap::ext::params::plugin::ValueToText,
|
||||
clap::ext::params::plugin::TextToValue>;
|
||||
clap::ext::params::plugin::TextToValue,
|
||||
clap::ext::state::plugin::Save,
|
||||
clap::ext::state::plugin::Load>;
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s, ClapMainThreadControlRequest& payload) {
|
||||
@@ -152,7 +154,8 @@ using ClapMainThreadCallbackRequest =
|
||||
clap::ext::note_ports::host::SupportedDialects,
|
||||
clap::ext::note_ports::host::Rescan,
|
||||
clap::ext::params::host::Rescan,
|
||||
clap::ext::params::host::Clear>;
|
||||
clap::ext::params::host::Clear,
|
||||
clap::ext::state::host::MarkDirty>;
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s, ClapMainThreadCallbackRequest& payload) {
|
||||
|
||||
@@ -26,7 +26,7 @@ Yabridge currently tracks CLAP 1.1.1. The implementation status for CLAP's core
|
||||
| `clap.params` | :heavy_check_mark: |
|
||||
| `clap.posix-fd-support` | :x: Not supported yet |
|
||||
| `clap.render` | :x: Not supported yet |
|
||||
| `clap.state` | :x: Not supported yet |
|
||||
| `clap.state` | :heavy_check_mark: |
|
||||
| `clap.tail` | :heavy_check_mark: |
|
||||
| `clap.thread-check` | :x: Not supported yet |
|
||||
| `clap.thread-pool` | :x: Not supported yet |
|
||||
|
||||
@@ -68,6 +68,7 @@ struct Load {
|
||||
template <typename S>
|
||||
void serialize(S& s) {
|
||||
s.value8b(instance_id);
|
||||
s.object(stream);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <clap/ext/latency.h>
|
||||
#include <clap/ext/note-ports.h>
|
||||
#include <clap/ext/params.h>
|
||||
#include <clap/ext/state.h>
|
||||
#include <clap/ext/tail.h>
|
||||
|
||||
namespace clap {
|
||||
@@ -32,12 +33,13 @@ 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*>, 5> SupportedHostExtensions::list()
|
||||
std::array<std::pair<bool, const char*>, 6> SupportedHostExtensions::list()
|
||||
const noexcept {
|
||||
return {std::pair(supports_audio_ports, CLAP_EXT_AUDIO_PORTS),
|
||||
std::pair(supports_latency, CLAP_EXT_LATENCY),
|
||||
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)};
|
||||
}
|
||||
|
||||
|
||||
@@ -85,13 +85,14 @@ struct SupportedHostExtensions {
|
||||
bool supports_latency = false;
|
||||
bool supports_note_ports = false;
|
||||
bool supports_params = false;
|
||||
bool supports_state = false;
|
||||
bool supports_tail = false;
|
||||
|
||||
/**
|
||||
* Get a list of `<bool, extension_name>` tuples for the supported
|
||||
* extensions. Used during logging.
|
||||
*/
|
||||
std::array<std::pair<bool, const char*>, 5> list() const noexcept;
|
||||
std::array<std::pair<bool, const char*>, 6> list() const noexcept;
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s) {
|
||||
@@ -99,6 +100,7 @@ struct SupportedHostExtensions {
|
||||
s.value1b(supports_latency);
|
||||
s.value1b(supports_note_ports);
|
||||
s.value1b(supports_params);
|
||||
s.value1b(supports_state);
|
||||
s.value1b(supports_tail);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <clap/ext/latency.h>
|
||||
#include <clap/ext/note-ports.h>
|
||||
#include <clap/ext/params.h>
|
||||
#include <clap/ext/state.h>
|
||||
#include <clap/ext/tail.h>
|
||||
|
||||
#include "version.h"
|
||||
@@ -80,12 +81,13 @@ const clap_plugin_descriptor_t* Descriptor::get() const {
|
||||
return &clap_descriptor;
|
||||
}
|
||||
|
||||
std::array<std::pair<bool, const char*>, 5> SupportedPluginExtensions::list()
|
||||
std::array<std::pair<bool, const char*>, 6> SupportedPluginExtensions::list()
|
||||
const noexcept {
|
||||
return {std::pair(supports_audio_ports, CLAP_EXT_AUDIO_PORTS),
|
||||
std::pair(supports_latency, CLAP_EXT_LATENCY),
|
||||
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)};
|
||||
}
|
||||
|
||||
|
||||
@@ -118,13 +118,14 @@ struct SupportedPluginExtensions {
|
||||
bool supports_latency = false;
|
||||
bool supports_note_ports = false;
|
||||
bool supports_params = false;
|
||||
bool supports_state = false;
|
||||
bool supports_tail = false;
|
||||
|
||||
/**
|
||||
* Get a list of `<bool, extension_name>` tuples for the supported
|
||||
* extensions. Used during logging.
|
||||
*/
|
||||
std::array<std::pair<bool, const char*>, 5> list() const noexcept;
|
||||
std::array<std::pair<bool, const char*>, 6> list() const noexcept;
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s) {
|
||||
@@ -132,6 +133,7 @@ struct SupportedPluginExtensions {
|
||||
s.value1b(supports_latency);
|
||||
s.value1b(supports_note_ports);
|
||||
s.value1b(supports_params);
|
||||
s.value1b(supports_state);
|
||||
s.value1b(supports_tail);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -27,6 +27,8 @@ ClapHostExtensions::ClapHostExtensions(const clap_host& host) noexcept
|
||||
host.get_extension(&host, CLAP_EXT_NOTE_PORTS))),
|
||||
params(static_cast<const clap_host_params_t*>(
|
||||
host.get_extension(&host, CLAP_EXT_PARAMS))),
|
||||
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))) {}
|
||||
|
||||
@@ -39,6 +41,7 @@ clap::host::SupportedHostExtensions ClapHostExtensions::supported()
|
||||
.supports_latency = latency != nullptr,
|
||||
.supports_note_ports = note_ports != nullptr,
|
||||
.supports_params = params != nullptr,
|
||||
.supports_state = state != nullptr,
|
||||
.supports_tail = tail != nullptr};
|
||||
}
|
||||
|
||||
@@ -83,6 +86,10 @@ clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
||||
.text_to_value = ext_params_text_to_value,
|
||||
.flush = ext_params_flush,
|
||||
}),
|
||||
ext_state_vtable(clap_plugin_state_t{
|
||||
.save = ext_state_save,
|
||||
.load = ext_state_load,
|
||||
}),
|
||||
ext_tail_vtable(clap_plugin_tail_t{
|
||||
.get = ext_tail_get,
|
||||
}),
|
||||
@@ -225,6 +232,9 @@ clap_plugin_proxy::plugin_get_extension(const struct clap_plugin* plugin,
|
||||
} else if (self->supported_extensions_.supports_params &&
|
||||
strcmp(id, CLAP_EXT_PARAMS) == 0) {
|
||||
extension_ptr = &self->ext_params_vtable;
|
||||
} else if (self->supported_extensions_.supports_state &&
|
||||
strcmp(id, CLAP_EXT_STATE) == 0) {
|
||||
extension_ptr = &self->ext_state_vtable;
|
||||
} else if (self->supported_extensions_.supports_tail &&
|
||||
strcmp(id, CLAP_EXT_TAIL) == 0) {
|
||||
extension_ptr = &self->ext_tail_vtable;
|
||||
@@ -436,6 +446,33 @@ clap_plugin_proxy::ext_params_flush(const clap_plugin_t* plugin,
|
||||
clap::ext::params::plugin::Flush{.instance_id = self->instance_id()});
|
||||
}
|
||||
|
||||
bool CLAP_ABI clap_plugin_proxy::ext_state_save(const clap_plugin_t* plugin,
|
||||
const clap_ostream_t* stream) {
|
||||
assert(plugin && plugin->plugin_data && stream);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
const clap::ext::state::plugin::SaveResponse response =
|
||||
self->bridge_.send_main_thread_message(
|
||||
clap::ext::state::plugin::Save{.instance_id = self->instance_id()});
|
||||
if (response.result) {
|
||||
response.result->write_to_stream(*stream);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CLAP_ABI clap_plugin_proxy::ext_state_load(const clap_plugin_t* plugin,
|
||||
const clap_istream_t* stream) {
|
||||
assert(plugin && plugin->plugin_data && stream);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
return self->bridge_.send_main_thread_message(
|
||||
clap::ext::state::plugin::Load{.instance_id = self->instance_id(),
|
||||
.stream = *stream});
|
||||
}
|
||||
|
||||
uint32_t CLAP_ABI clap_plugin_proxy::ext_tail_get(const clap_plugin_t* plugin) {
|
||||
assert(plugin && plugin->plugin_data);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <clap/ext/latency.h>
|
||||
#include <clap/ext/note-ports.h>
|
||||
#include <clap/ext/params.h>
|
||||
#include <clap/ext/state.h>
|
||||
#include <clap/ext/tail.h>
|
||||
#include <clap/plugin.h>
|
||||
#include <rigtorp/MPMCQueue.h>
|
||||
@@ -64,6 +65,7 @@ struct ClapHostExtensions {
|
||||
const clap_host_latency_t* latency = nullptr;
|
||||
const clap_host_note_ports_t* note_ports = nullptr;
|
||||
const clap_host_params_t* params = nullptr;
|
||||
const clap_host_state_t* state = nullptr;
|
||||
const clap_host_tail_t* tail = nullptr;
|
||||
};
|
||||
|
||||
@@ -216,6 +218,11 @@ class clap_plugin_proxy {
|
||||
const clap_input_events_t* in,
|
||||
const clap_output_events_t* out);
|
||||
|
||||
static bool CLAP_ABI ext_state_save(const clap_plugin_t* plugin,
|
||||
const clap_ostream_t* stream);
|
||||
static bool CLAP_ABI ext_state_load(const clap_plugin_t* plugin,
|
||||
const clap_istream_t* stream);
|
||||
|
||||
static uint32_t CLAP_ABI ext_tail_get(const clap_plugin_t* plugin);
|
||||
|
||||
private:
|
||||
@@ -248,6 +255,7 @@ class clap_plugin_proxy {
|
||||
const clap_plugin_latency_t ext_latency_vtable;
|
||||
const clap_plugin_note_ports_t ext_note_ports_vtable;
|
||||
const clap_plugin_params_t ext_params_vtable;
|
||||
const clap_plugin_state_t ext_state_vtable;
|
||||
const clap_plugin_tail_t ext_tail_vtable;
|
||||
|
||||
/**
|
||||
|
||||
@@ -195,6 +195,21 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path)
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
[&](const clap::ext::state::host::MarkDirty& request)
|
||||
-> clap::ext::state::host::MarkDirty::Response {
|
||||
const auto& [plugin_proxy, _] =
|
||||
get_proxy(request.owner_instance_id);
|
||||
|
||||
plugin_proxy
|
||||
.run_on_main_thread(
|
||||
[&, host = plugin_proxy.host_,
|
||||
state = plugin_proxy.host_extensions_.state]() {
|
||||
state->mark_dirty(host);
|
||||
})
|
||||
.wait();
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ clap_host_proxy::clap_host_proxy(ClapBridge& bridge,
|
||||
.clear = ext_params_clear,
|
||||
.request_flush = ext_params_request_flush,
|
||||
}),
|
||||
ext_state_vtable(clap_host_state_t{
|
||||
.mark_dirty = ext_state_mark_dirty,
|
||||
}),
|
||||
ext_tail_vtable(clap_host_tail_t{
|
||||
.changed = ext_tail_changed,
|
||||
}) {}
|
||||
@@ -83,6 +86,9 @@ clap_host_proxy::host_get_extension(const struct clap_host* host,
|
||||
} else if (self->supported_extensions_.supports_params &&
|
||||
strcmp(extension_id, CLAP_EXT_PARAMS) == 0) {
|
||||
extension_ptr = &self->ext_params_vtable;
|
||||
} else if (self->supported_extensions_.supports_state &&
|
||||
strcmp(extension_id, CLAP_EXT_STATE) == 0) {
|
||||
extension_ptr = &self->ext_state_vtable;
|
||||
} else if (self->supported_extensions_.supports_tail &&
|
||||
strcmp(extension_id, CLAP_EXT_TAIL) == 0) {
|
||||
extension_ptr = &self->ext_tail_vtable;
|
||||
@@ -222,6 +228,14 @@ clap_host_proxy::ext_params_request_flush(const clap_host_t* host) {
|
||||
self->owner_instance_id()});
|
||||
}
|
||||
|
||||
void CLAP_ABI clap_host_proxy::ext_state_mark_dirty(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::state::host::MarkDirty{
|
||||
.owner_instance_id = self->owner_instance_id()});
|
||||
}
|
||||
|
||||
void CLAP_ABI clap_host_proxy::ext_tail_changed(const clap_host_t* host) {
|
||||
assert(host && host->host_data);
|
||||
auto self = static_cast<const clap_host_proxy*>(host->host_data);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <clap/ext/latency.h>
|
||||
#include <clap/ext/note-ports.h>
|
||||
#include <clap/ext/params.h>
|
||||
#include <clap/ext/state.h>
|
||||
#include <clap/ext/tail.h>
|
||||
#include <clap/host.h>
|
||||
|
||||
@@ -95,6 +96,8 @@ class clap_host_proxy {
|
||||
clap_param_clear_flags flags);
|
||||
static void CLAP_ABI ext_params_request_flush(const clap_host_t* host);
|
||||
|
||||
static void CLAP_ABI ext_state_mark_dirty(const clap_host_t* host);
|
||||
|
||||
static void CLAP_ABI ext_tail_changed(const clap_host_t* host);
|
||||
|
||||
private:
|
||||
@@ -116,6 +119,7 @@ class clap_host_proxy {
|
||||
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_state_t ext_state_vtable;
|
||||
const clap_host_tail_t ext_tail_vtable;
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,6 +35,8 @@ ClapPluginExtensions::ClapPluginExtensions(const clap_plugin& plugin) noexcept
|
||||
plugin.get_extension(&plugin, CLAP_EXT_NOTE_PORTS))),
|
||||
params(static_cast<const clap_plugin_params_t*>(
|
||||
plugin.get_extension(&plugin, CLAP_EXT_PARAMS))),
|
||||
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))) {}
|
||||
|
||||
@@ -47,6 +49,7 @@ clap::plugin::SupportedPluginExtensions ClapPluginExtensions::supported()
|
||||
.supports_latency = latency != nullptr,
|
||||
.supports_note_ports = note_ports != nullptr,
|
||||
.supports_params = params != nullptr,
|
||||
.supports_state = state != nullptr,
|
||||
.supports_tail = tail != nullptr};
|
||||
}
|
||||
|
||||
@@ -454,6 +457,35 @@ void ClapBridge::run() {
|
||||
.result = std::nullopt};
|
||||
}
|
||||
},
|
||||
[&](clap::ext::state::plugin::Save& request)
|
||||
-> clap::ext::state::plugin::Save::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
return main_context_
|
||||
.run_in_context([&, plugin = instance.plugin.get(),
|
||||
state = instance.extensions.state]() {
|
||||
clap::stream::Stream stream{};
|
||||
if (state->save(plugin, stream.ostream())) {
|
||||
return clap::ext::state::plugin::SaveResponse{
|
||||
.result = std::move(stream)};
|
||||
} else {
|
||||
return clap::ext::state::plugin::SaveResponse{
|
||||
.result = std::nullopt};
|
||||
}
|
||||
})
|
||||
.get();
|
||||
},
|
||||
[&](clap::ext::state::plugin::Load& request)
|
||||
-> clap::ext::state::plugin::Load::Response {
|
||||
const auto& [instance, _] = get_instance(request.instance_id);
|
||||
|
||||
return main_context_
|
||||
.run_in_context([&, plugin = instance.plugin.get(),
|
||||
state = instance.extensions.state]() {
|
||||
return state->load(plugin, request.stream.istream());
|
||||
})
|
||||
.get();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ struct ClapPluginExtensions {
|
||||
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_state_t* state = nullptr;
|
||||
const clap_plugin_tail_t* tail = nullptr;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user