Run all other lifecycle events on main thread

This is probably where plugins instantiate timers for their GUI updates.
This commit is contained in:
Robbert van der Helm
2020-12-20 12:29:59 +01:00
parent f2153148b2
commit b38f272013
+34 -8
View File
@@ -86,20 +86,35 @@ void Vst3Bridge::run() {
// Even though we're requesting a specific interface (to mimic // Even though we're requesting a specific interface (to mimic
// what the host is doing), we're immediately upcasting it to an // what the host is doing), we're immediately upcasting it to an
// `FUnknown` so we can create a perfect proxy object. // `FUnknown` so we can create a perfect proxy object.
Steinberg::IPtr<Steinberg::FUnknown> object; // We create the object from the GUI thread in case it
// immediatly starts timers or something (even though it
// shouldn't)
Steinberg::IPtr<Steinberg::FUnknown> object =
main_context
.run_in_context<Steinberg::IPtr<Steinberg::FUnknown>>(
[&]() -> Steinberg::IPtr<Steinberg::FUnknown> {
switch (request.requested_interface) { switch (request.requested_interface) {
case Vst3PluginProxy::Construct::Interface::IComponent: case Vst3PluginProxy::Construct::Interface::
object = IComponent:
module->getFactory() return module->getFactory()
.createInstance<Steinberg::Vst::IComponent>( .createInstance<
Steinberg::Vst::IComponent>(
cid); cid);
break; break;
case Vst3PluginProxy::Construct::Interface::IEditController: case Vst3PluginProxy::Construct::Interface::
object = module->getFactory() IEditController:
return module->getFactory()
.createInstance< .createInstance<
Steinberg::Vst::IEditController>(cid); Steinberg::Vst::
IEditController>(cid);
break;
default:
// Unreachable
return nullptr;
break; break;
} }
})
.get();
if (object) { if (object) {
std::lock_guard lock(object_instances_mutex); std::lock_guard lock(object_instances_mutex);
@@ -490,15 +505,26 @@ void Vst3Bridge::run() {
nullptr; nullptr;
} }
// XXX: Should `IPlugView::{initialize,terminate}` be run from
// the main UI thread? I can see how plugins would want to
// start timers from here.
return main_context
.run_in_context<tresult>([&]() {
return object_instances[request.instance_id] return object_instances[request.instance_id]
.plugin_base->initialize( .plugin_base->initialize(
object_instances[request.instance_id] object_instances[request.instance_id]
.host_context_proxy); .host_context_proxy);
})
.get();
}, },
[&](const YaPluginBase::Terminate& request) [&](const YaPluginBase::Terminate& request)
-> YaPluginBase::Terminate::Response { -> YaPluginBase::Terminate::Response {
return main_context
.run_in_context<tresult>([&]() {
return object_instances[request.instance_id] return object_instances[request.instance_id]
.plugin_base->terminate(); .plugin_base->terminate();
})
.get();
}, },
[&](const YaPluginFactory::Construct&) [&](const YaPluginFactory::Construct&)
-> YaPluginFactory::Construct::Response { -> YaPluginFactory::Construct::Response {