mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 12:10:09 +02:00
Fully implement the state extension
This commit is contained in:
@@ -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{};
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user