mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-16 05:33:07 +02:00
Implement CLAP plugin initialization
This commit is contained in:
@@ -60,6 +60,13 @@ class clap_host_proxy {
|
||||
static void CLAP_ABI host_request_process(const struct clap_host* host);
|
||||
static void CLAP_ABI host_request_callback(const struct clap_host* host);
|
||||
|
||||
/**
|
||||
* The extensions supported by the host, set just before calling
|
||||
* `clap_plugin::init()` on the bridged plugin. We'll allow the plugin to
|
||||
* query these extensions through `clap_host::get_extension()`.
|
||||
*/
|
||||
clap::host::SupportedHostExtensions supported_extensions_;
|
||||
|
||||
private:
|
||||
ClapBridge& bridge_;
|
||||
size_t owner_instance_id_;
|
||||
|
||||
@@ -147,7 +147,7 @@ void ClapBridge::run() {
|
||||
.run_in_context([&]() {
|
||||
plugin_factory_ =
|
||||
static_cast<const clap_plugin_factory_t*>(
|
||||
(entry_->get_factory)(CLAP_PLUGIN_FACTORY_ID));
|
||||
entry_->get_factory(CLAP_PLUGIN_FACTORY_ID));
|
||||
if (!plugin_factory_) {
|
||||
return clap::plugin_factory::ListResponse{
|
||||
.descriptors = std::nullopt};
|
||||
@@ -155,11 +155,10 @@ void ClapBridge::run() {
|
||||
|
||||
std::vector<clap::plugin::Descriptor> descriptors;
|
||||
const uint32_t num_plugins =
|
||||
(plugin_factory_->get_plugin_count)(
|
||||
plugin_factory_);
|
||||
plugin_factory_->get_plugin_count(plugin_factory_);
|
||||
for (uint32_t i = 0; i < num_plugins; i++) {
|
||||
const clap_plugin_descriptor_t* descriptor =
|
||||
(plugin_factory_->get_plugin_descriptor)(
|
||||
plugin_factory_->get_plugin_descriptor(
|
||||
plugin_factory_, i);
|
||||
if (!descriptor) {
|
||||
std::cerr << "Plugin returned a null pointer "
|
||||
@@ -209,6 +208,37 @@ void ClapBridge::run() {
|
||||
})
|
||||
.get();
|
||||
},
|
||||
[&](clap::plugin::Init& request) -> clap::plugin::Init::Response {
|
||||
return main_context_
|
||||
.run_in_context([&]() {
|
||||
const auto& [instance, _] =
|
||||
get_instance(request.instance_id);
|
||||
|
||||
// The plugin is allowed to query the same set of
|
||||
// extensions from our host proxy that the native host
|
||||
// supports
|
||||
instance.host_proxy->supported_extensions_ =
|
||||
request.supported_host_extensions;
|
||||
|
||||
const bool result =
|
||||
instance.plugin->init(instance.plugin.get());
|
||||
if (result) {
|
||||
// This mimics the same behavior we had to implement
|
||||
// for VST2 and VST3. The Win32 message loop is
|
||||
// completely blocked while a plugin instance has
|
||||
// been created but not yet initialized.
|
||||
instance.is_initialized = true;
|
||||
}
|
||||
|
||||
return clap::plugin::InitResponse{
|
||||
.result = result,
|
||||
// Similarly, we'll make the plugin's supported
|
||||
// extensions available to the host
|
||||
.supported_plugin_extensions = *instance.plugin};
|
||||
})
|
||||
.get();
|
||||
},
|
||||
|
||||
[&](clap::plugin::Destroy& request)
|
||||
-> clap::plugin::Destroy::Response {
|
||||
return main_context_
|
||||
|
||||
@@ -78,9 +78,12 @@ struct ClapPluginInstance {
|
||||
* A proxy for the native CLAP host. Stored using an `std::unique_ptr`
|
||||
* because it must be created before creating the plugin instance, and the
|
||||
* object cannot move after being created because of the vtable.
|
||||
*
|
||||
* Contains a `clap::host::SupportedHostExtensions` set just before
|
||||
* `clap_plugin::init()` that allows the plugin to query host extensions
|
||||
* also supported by the native host.
|
||||
*/
|
||||
std::unique_ptr<clap_host_proxy> host_proxy;
|
||||
// TODO: Proxies for host extension objects
|
||||
|
||||
/**
|
||||
* A dedicated thread for handling incoming audio thread function calls.
|
||||
|
||||
Reference in New Issue
Block a user