mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-16 00:13:55 +02:00
Deduplicate CLAP extension support queries
They're only queried once now and the booleans are derived from the stored pointers.
This commit is contained in:
@@ -28,8 +28,5 @@ Host::Host(const clap_host_t& original)
|
|||||||
url(original.url ? std::optional(original.url) : std::nullopt),
|
url(original.url ? std::optional(original.url) : std::nullopt),
|
||||||
version((assert(original.version), original.version)) {}
|
version((assert(original.version), original.version)) {}
|
||||||
|
|
||||||
SupportedHostExtensions::SupportedHostExtensions(const clap_host& host)
|
|
||||||
: supports_audio_ports(host.get_extension(&host, CLAP_EXT_AUDIO_PORTS)) {}
|
|
||||||
|
|
||||||
} // namespace host
|
} // namespace host
|
||||||
} // namespace clap
|
} // namespace clap
|
||||||
|
|||||||
@@ -75,18 +75,11 @@ struct Host {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Extensions supported by the host. This can only be queried in
|
* Extensions supported by the host. This can only be queried in
|
||||||
* `clap_plugin::init()` so it cannot be part of `Host`. We'll create make these
|
* `clap_plugin::init()` so it cannot be part of `Host`. Created by
|
||||||
* same extensions available to the bridged CLAP plugins using proxies.
|
* `ClapHostExtensions::supported()`. We'll create make these same extensions
|
||||||
|
* available to the bridged CLAP plugins using proxies.
|
||||||
*/
|
*/
|
||||||
struct SupportedHostExtensions {
|
struct SupportedHostExtensions {
|
||||||
/**
|
|
||||||
* Read the supported extensions from a native CLAP host. This is only valid
|
|
||||||
* once the native host has called `clap_host::init()`.
|
|
||||||
*/
|
|
||||||
SupportedHostExtensions(const clap_host& host);
|
|
||||||
|
|
||||||
SupportedHostExtensions() noexcept {}
|
|
||||||
|
|
||||||
// Don't forget to add new extensions to the log output
|
// Don't forget to add new extensions to the log output
|
||||||
bool supports_audio_ports = false;
|
bool supports_audio_ports = false;
|
||||||
|
|
||||||
|
|||||||
@@ -76,9 +76,5 @@ const clap_plugin_descriptor_t* Descriptor::get() const {
|
|||||||
return &clap_descriptor;
|
return &clap_descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
SupportedPluginExtensions::SupportedPluginExtensions(const clap_plugin& plugin)
|
|
||||||
: supports_audio_ports(
|
|
||||||
plugin.get_extension(&plugin, CLAP_EXT_AUDIO_PORTS)) {}
|
|
||||||
|
|
||||||
} // namespace plugin
|
} // namespace plugin
|
||||||
} // namespace clap
|
} // namespace clap
|
||||||
|
|||||||
@@ -109,17 +109,10 @@ struct Descriptor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extensions supported by the plugin. Queried after `clap_plugin::init()`.
|
* Extensions supported by the plugin. Queried after `clap_plugin::init()` and
|
||||||
|
* created by `ClapPluginExtensions::supported()`.
|
||||||
*/
|
*/
|
||||||
struct SupportedPluginExtensions {
|
struct SupportedPluginExtensions {
|
||||||
/**
|
|
||||||
* Read the supported extensions from a CLAP plugin. This is only valid
|
|
||||||
* after `clap_plugin::init()` has been called on the plugin.
|
|
||||||
*/
|
|
||||||
SupportedPluginExtensions(const clap_plugin& plugin);
|
|
||||||
|
|
||||||
SupportedPluginExtensions() noexcept {}
|
|
||||||
|
|
||||||
// Don't forget to add new extensions to the log output
|
// Don't forget to add new extensions to the log output
|
||||||
bool supports_audio_ports = false;
|
bool supports_audio_ports = false;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ ClapHostExtensions::ClapHostExtensions(const clap_host& host) noexcept
|
|||||||
|
|
||||||
ClapHostExtensions::ClapHostExtensions() noexcept {}
|
ClapHostExtensions::ClapHostExtensions() noexcept {}
|
||||||
|
|
||||||
|
clap::host::SupportedHostExtensions ClapHostExtensions::supported()
|
||||||
|
const noexcept {
|
||||||
|
return clap::host::SupportedHostExtensions{.supports_audio_ports =
|
||||||
|
audio_ports != nullptr};
|
||||||
|
}
|
||||||
|
|
||||||
clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
clap_plugin_proxy::clap_plugin_proxy(ClapPluginBridge& bridge,
|
||||||
size_t instance_id,
|
size_t instance_id,
|
||||||
clap::plugin::Descriptor descriptor,
|
clap::plugin::Descriptor descriptor,
|
||||||
@@ -65,9 +71,9 @@ bool CLAP_ABI clap_plugin_proxy::plugin_init(const struct clap_plugin* plugin) {
|
|||||||
self->extensions_ = ClapHostExtensions(*self->host_);
|
self->extensions_ = ClapHostExtensions(*self->host_);
|
||||||
|
|
||||||
const clap::plugin::InitResponse response =
|
const clap::plugin::InitResponse response =
|
||||||
self->bridge_.send_main_thread_message(
|
self->bridge_.send_main_thread_message(clap::plugin::Init{
|
||||||
clap::plugin::Init{.instance_id = self->instance_id(),
|
.instance_id = self->instance_id(),
|
||||||
.supported_host_extensions = *self->host_});
|
.supported_host_extensions = self->extensions_.supported()});
|
||||||
|
|
||||||
// This determines which extensions the host is allowed to query in
|
// This determines which extensions the host is allowed to query in
|
||||||
// `clap_plugin::get_extension()`
|
// `clap_plugin::get_extension()`
|
||||||
|
|||||||
@@ -49,6 +49,12 @@ struct ClapHostExtensions {
|
|||||||
*/
|
*/
|
||||||
ClapHostExtensions() noexcept;
|
ClapHostExtensions() noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the supported extensions as boolean values for serialization
|
||||||
|
* purposes.
|
||||||
|
*/
|
||||||
|
clap::host::SupportedHostExtensions supported() const noexcept;
|
||||||
|
|
||||||
const clap_host_audio_ports_t* audio_ports = nullptr;
|
const clap_host_audio_ports_t* audio_ports = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,12 @@ ClapPluginExtensions::ClapPluginExtensions(const clap_plugin& plugin) noexcept
|
|||||||
|
|
||||||
ClapPluginExtensions::ClapPluginExtensions() noexcept {}
|
ClapPluginExtensions::ClapPluginExtensions() noexcept {}
|
||||||
|
|
||||||
|
clap::plugin::SupportedPluginExtensions ClapPluginExtensions::supported()
|
||||||
|
const noexcept {
|
||||||
|
return clap::plugin::SupportedPluginExtensions{.supports_audio_ports =
|
||||||
|
audio_ports != nullptr};
|
||||||
|
}
|
||||||
|
|
||||||
ClapPluginInstance::ClapPluginInstance(
|
ClapPluginInstance::ClapPluginInstance(
|
||||||
const clap_plugin* plugin,
|
const clap_plugin* plugin,
|
||||||
std::unique_ptr<clap_host_proxy> host_proxy) noexcept
|
std::unique_ptr<clap_host_proxy> host_proxy) noexcept
|
||||||
@@ -227,6 +233,12 @@ void ClapBridge::run() {
|
|||||||
const bool result =
|
const bool result =
|
||||||
instance.plugin->init(instance.plugin.get());
|
instance.plugin->init(instance.plugin.get());
|
||||||
if (result) {
|
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;
|
||||||
|
|
||||||
// At this point we should also get the extension
|
// At this point we should also get the extension
|
||||||
// pointers for the plugin's supported extensions.
|
// pointers for the plugin's supported extensions.
|
||||||
// In addition we'll send whether or not the plugin
|
// In addition we'll send whether or not the plugin
|
||||||
@@ -236,18 +248,17 @@ void ClapBridge::run() {
|
|||||||
instance.extensions =
|
instance.extensions =
|
||||||
ClapPluginExtensions(*instance.plugin);
|
ClapPluginExtensions(*instance.plugin);
|
||||||
|
|
||||||
// This mimics the same behavior we had to implement
|
return clap::plugin::InitResponse{
|
||||||
// for VST2 and VST3. The Win32 message loop is
|
.result = result,
|
||||||
// completely blocked while a plugin instance has
|
// Similarly, we'll make the plugin's supported
|
||||||
// been created but not yet initialized.
|
// extensions available to the host
|
||||||
instance.is_initialized = true;
|
.supported_plugin_extensions =
|
||||||
|
instance.extensions.supported()};
|
||||||
|
} else {
|
||||||
|
return clap::plugin::InitResponse{
|
||||||
|
.result = result,
|
||||||
|
.supported_plugin_extensions = {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
.get();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -60,6 +60,12 @@ struct ClapPluginExtensions {
|
|||||||
*/
|
*/
|
||||||
ClapPluginExtensions() noexcept;
|
ClapPluginExtensions() noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the supported extensions as boolean values for serialization
|
||||||
|
* purposes.
|
||||||
|
*/
|
||||||
|
clap::plugin::SupportedPluginExtensions supported() const noexcept;
|
||||||
|
|
||||||
const clap_plugin_audio_ports_t* audio_ports = nullptr;
|
const clap_plugin_audio_ports_t* audio_ports = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user