mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-16 05:33:07 +02:00
Fully implement the state extension
This commit is contained in:
@@ -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