Allow creating plugins instances

This commit is contained in:
Robbert van der Helm
2022-09-09 14:52:13 +02:00
parent a9bb60772d
commit c98ca66838
@@ -56,6 +56,43 @@ clap_plugin_factory_proxy::plugin_factory_create_plugin(
const struct clap_plugin_factory* factory,
const clap_host_t* host,
const char* plugin_id) {
// TODO: Implement
return nullptr;
assert(factory && host && plugin_id);
auto self = reinterpret_cast<const clap_plugin_factory_proxy*>(factory);
// We'll need to store another copy of this descriptor in the plugin
// instance
const auto descriptor =
std::find_if(self->descriptors_.begin(), self->descriptors_.end(),
[plugin_id](const auto& descriptor) {
return descriptor.id == plugin_id;
});
if (descriptor == self->descriptors_.end()) {
self->bridge_.logger_.log_trace([&]() {
return "The host tried to create an instance for ID \"" +
std::string(plugin_id) +
"\", but we don't have a descriptor for this plugin.";
});
return nullptr;
}
const clap::plugin_factory::CreateResponse response =
self->bridge_.send_main_thread_message(clap::plugin_factory::Create{
.host = *host, .plugin_id = plugin_id});
if (response.instance_id) {
// This plugin proxy is tied to the instance ID created on the Wine
// side. That way we can link function calls from the host to the
// correct plugin instance, and callbacks made from the plugin to the
// correct host instance.
self->bridge_.register_plugin_proxy(std::make_unique<clap_plugin_proxy>(
self->bridge_, *response.instance_id, *descriptor));
const auto& [plugin_proxy, _] =
self->bridge_.get_proxy(*response.instance_id);
return plugin_proxy.plugin_vtable();
} else {
// The plugin couldn't be created, for whatever reason that might be
return nullptr;
}
}