mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Always honor CLAP main thread requirement
If this ever becomes a bottleneck we can always decide to not do it right there and then.
This commit is contained in:
@@ -88,12 +88,16 @@ ClapPluginBridge::ClapPluginBridge(const ghc::filesystem::path& plugin_path)
|
|||||||
const auto& [plugin_proxy, _] =
|
const auto& [plugin_proxy, _] =
|
||||||
get_proxy(request.owner_instance_id);
|
get_proxy(request.owner_instance_id);
|
||||||
|
|
||||||
// We'll ignore the main thread requirement for
|
return plugin_proxy
|
||||||
// simple lookup functions like this for
|
.run_on_main_thread(
|
||||||
// performance's sake
|
[&, host = plugin_proxy.host_,
|
||||||
return plugin_proxy.extensions_.audio_ports
|
audio_ports = plugin_proxy.extensions_
|
||||||
->is_rescan_flag_supported(plugin_proxy.host_,
|
.audio_ports]() {
|
||||||
request.flag);
|
return audio_ports
|
||||||
|
->is_rescan_flag_supported(
|
||||||
|
host, request.flag);
|
||||||
|
})
|
||||||
|
.get();
|
||||||
},
|
},
|
||||||
[&](const clap::ext::audio_ports::host::Rescan& request)
|
[&](const clap::ext::audio_ports::host::Rescan& request)
|
||||||
-> clap::ext::audio_ports::host::Rescan::Response {
|
-> clap::ext::audio_ports::host::Rescan::Response {
|
||||||
|
|||||||
@@ -222,19 +222,18 @@ void ClapBridge::run() {
|
|||||||
.get();
|
.get();
|
||||||
},
|
},
|
||||||
[&](clap::plugin::Init& request) -> clap::plugin::Init::Response {
|
[&](clap::plugin::Init& request) -> clap::plugin::Init::Response {
|
||||||
return main_context_
|
const auto& [instance, _] = get_instance(request.instance_id);
|
||||||
.run_in_context([&]() {
|
|
||||||
const auto& [instance, _] =
|
|
||||||
get_instance(request.instance_id);
|
|
||||||
|
|
||||||
|
return main_context_
|
||||||
|
.run_in_context([&, plugin = instance.plugin.get(),
|
||||||
|
&instance = instance]() {
|
||||||
// The plugin is allowed to query the same set of
|
// The plugin is allowed to query the same set of
|
||||||
// extensions from our host proxy that the native host
|
// extensions from our host proxy that the native host
|
||||||
// supports
|
// supports
|
||||||
instance.host_proxy->supported_extensions_ =
|
instance.host_proxy->supported_extensions_ =
|
||||||
request.supported_host_extensions;
|
request.supported_host_extensions;
|
||||||
|
|
||||||
const bool result =
|
const bool result = plugin->init(plugin);
|
||||||
instance.plugin->init(instance.plugin.get());
|
|
||||||
if (result) {
|
if (result) {
|
||||||
// This mimics the same behavior we had to implement
|
// This mimics the same behavior we had to implement
|
||||||
// for VST2 and VST3. The Win32 message loop is
|
// for VST2 and VST3. The Win32 message loop is
|
||||||
@@ -248,8 +247,7 @@ void ClapBridge::run() {
|
|||||||
// supports these extensions as booleans to the
|
// supports these extensions as booleans to the
|
||||||
// native plugin side so we can expose these same
|
// native plugin side so we can expose these same
|
||||||
// extensions to the host.
|
// extensions to the host.
|
||||||
instance.extensions =
|
instance.extensions = ClapPluginExtensions(*plugin);
|
||||||
ClapPluginExtensions(*instance.plugin);
|
|
||||||
|
|
||||||
return clap::plugin::InitResponse{
|
return clap::plugin::InitResponse{
|
||||||
.result = result,
|
.result = result,
|
||||||
@@ -280,13 +278,12 @@ void ClapBridge::run() {
|
|||||||
},
|
},
|
||||||
[&](clap::plugin::Activate& request)
|
[&](clap::plugin::Activate& request)
|
||||||
-> clap::plugin::Activate::Response {
|
-> clap::plugin::Activate::Response {
|
||||||
return main_context_
|
const auto& [instance, _] = get_instance(request.instance_id);
|
||||||
.run_in_context([&]() {
|
|
||||||
const auto& [instance, _] =
|
|
||||||
get_instance(request.instance_id);
|
|
||||||
|
|
||||||
const bool result = instance.plugin->activate(
|
return main_context_
|
||||||
instance.plugin.get(), request.sample_rate,
|
.run_in_context([&, plugin = instance.plugin.get()]() {
|
||||||
|
const bool result = plugin->activate(
|
||||||
|
plugin, request.sample_rate,
|
||||||
request.min_frames_count, request.max_frames_count);
|
request.min_frames_count, request.max_frames_count);
|
||||||
|
|
||||||
// TODO: Audio buffer setup
|
// TODO: Audio buffer setup
|
||||||
@@ -302,12 +299,11 @@ void ClapBridge::run() {
|
|||||||
},
|
},
|
||||||
[&](clap::plugin::Deactivate& request)
|
[&](clap::plugin::Deactivate& request)
|
||||||
-> clap::plugin::Deactivate::Response {
|
-> clap::plugin::Deactivate::Response {
|
||||||
return main_context_
|
const auto& [instance, _] = get_instance(request.instance_id);
|
||||||
.run_in_context([&]() {
|
|
||||||
const auto& [instance, _] =
|
|
||||||
get_instance(request.instance_id);
|
|
||||||
|
|
||||||
instance.plugin->deactivate(instance.plugin.get());
|
return main_context_
|
||||||
|
.run_in_context([&, plugin = instance.plugin.get()]() {
|
||||||
|
plugin->deactivate(plugin);
|
||||||
|
|
||||||
return Ack{};
|
return Ack{};
|
||||||
})
|
})
|
||||||
@@ -317,49 +313,65 @@ void ClapBridge::run() {
|
|||||||
-> clap::ext::audio_ports::plugin::Count::Response {
|
-> clap::ext::audio_ports::plugin::Count::Response {
|
||||||
const auto& [instance, _] = get_instance(request.instance_id);
|
const auto& [instance, _] = get_instance(request.instance_id);
|
||||||
|
|
||||||
// We'll ignore the main thread requirement for simple lookup
|
return main_context_
|
||||||
// functions like this for performance's sake
|
.run_in_context(
|
||||||
return instance.extensions.audio_ports->count(
|
[&, plugin = instance.plugin.get(),
|
||||||
instance.plugin.get(), request.is_input);
|
audio_ports = instance.extensions.audio_ports]() {
|
||||||
|
return audio_ports->count(plugin, request.is_input);
|
||||||
|
})
|
||||||
|
.get();
|
||||||
},
|
},
|
||||||
[&](const clap::ext::audio_ports::plugin::Get& request)
|
[&](const clap::ext::audio_ports::plugin::Get& request)
|
||||||
-> clap::ext::audio_ports::plugin::Get::Response {
|
-> clap::ext::audio_ports::plugin::Get::Response {
|
||||||
const auto& [instance, _] = get_instance(request.instance_id);
|
const auto& [instance, _] = get_instance(request.instance_id);
|
||||||
|
|
||||||
|
return main_context_
|
||||||
|
.run_in_context([&, plugin = instance.plugin.get(),
|
||||||
|
audio_ports =
|
||||||
|
instance.extensions.audio_ports]() {
|
||||||
clap_audio_port_info_t info{};
|
clap_audio_port_info_t info{};
|
||||||
if (instance.extensions.audio_ports->get(
|
if (audio_ports->get(plugin, request.index,
|
||||||
instance.plugin.get(), request.index, request.is_input,
|
request.is_input, &info)) {
|
||||||
&info)) {
|
|
||||||
return clap::ext::audio_ports::plugin::GetResponse{
|
return clap::ext::audio_ports::plugin::GetResponse{
|
||||||
.result = info};
|
.result = info};
|
||||||
} else {
|
} else {
|
||||||
return clap::ext::audio_ports::plugin::GetResponse{
|
return clap::ext::audio_ports::plugin::GetResponse{
|
||||||
.result = std::nullopt};
|
.result = std::nullopt};
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.get();
|
||||||
},
|
},
|
||||||
[&](const clap::ext::note_ports::plugin::Count& request)
|
[&](const clap::ext::note_ports::plugin::Count& request)
|
||||||
-> clap::ext::note_ports::plugin::Count::Response {
|
-> clap::ext::note_ports::plugin::Count::Response {
|
||||||
const auto& [instance, _] = get_instance(request.instance_id);
|
const auto& [instance, _] = get_instance(request.instance_id);
|
||||||
|
|
||||||
return instance.extensions.note_ports->count(
|
return main_context_
|
||||||
instance.plugin.get(), request.is_input);
|
.run_in_context(
|
||||||
|
[&, plugin = instance.plugin.get(),
|
||||||
|
note_ports = instance.extensions.note_ports]() {
|
||||||
|
return note_ports->count(plugin, request.is_input);
|
||||||
|
})
|
||||||
|
.get();
|
||||||
},
|
},
|
||||||
[&](const clap::ext::note_ports::plugin::Get& request)
|
[&](const clap::ext::note_ports::plugin::Get& request)
|
||||||
-> clap::ext::note_ports::plugin::Get::Response {
|
-> clap::ext::note_ports::plugin::Get::Response {
|
||||||
const auto& [instance, _] = get_instance(request.instance_id);
|
const auto& [instance, _] = get_instance(request.instance_id);
|
||||||
|
|
||||||
// We'll also ignore the main thread requirement here for
|
return main_context_
|
||||||
// performance's sake
|
.run_in_context([&, plugin = instance.plugin.get(),
|
||||||
|
note_ports =
|
||||||
|
instance.extensions.note_ports]() {
|
||||||
clap_note_port_info_t info{};
|
clap_note_port_info_t info{};
|
||||||
if (instance.extensions.note_ports->get(
|
if (note_ports->get(plugin, request.index,
|
||||||
instance.plugin.get(), request.index, request.is_input,
|
request.is_input, &info)) {
|
||||||
&info)) {
|
return clap::ext::note_ports::plugin::GetResponse{
|
||||||
return clap::ext::note_ports::plugin::GetResponse{.result =
|
.result = info};
|
||||||
info};
|
|
||||||
} else {
|
} else {
|
||||||
return clap::ext::note_ports::plugin::GetResponse{
|
return clap::ext::note_ports::plugin::GetResponse{
|
||||||
.result = std::nullopt};
|
.result = std::nullopt};
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.get();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user