mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-16 21:50:11 +02:00
Handle mutual recursion in context menus
REAPER will call `getState()` while the context menu is open, and that also has to be handled from the GUI thread.
This commit is contained in:
@@ -114,7 +114,10 @@ tresult PLUGIN_API Vst3ContextMenuProxyImpl::removeItem(
|
||||
|
||||
tresult PLUGIN_API Vst3ContextMenuProxyImpl::popup(Steinberg::UCoord x,
|
||||
Steinberg::UCoord y) {
|
||||
return bridge.send_message(
|
||||
// NOTE: This requires mutual recursion, because REAPER will call
|
||||
// `getState()` whle the context menu is open, and `getState()` also
|
||||
// has to be handled from the GUi thread
|
||||
return bridge.send_mutually_recursive_message(
|
||||
YaContextMenu::Popup{.owner_instance_id = owner_instance_id(),
|
||||
.context_menu_id = context_menu_id(),
|
||||
.x = x,
|
||||
|
||||
@@ -253,22 +253,21 @@ void Vst3Bridge::run() {
|
||||
-> Vst3PluginProxy::GetState::Response {
|
||||
// NOTE: The VST3 version of Algonaut Atlas doesn't restore
|
||||
// state unless this function is run from the GUI thread
|
||||
// NOTE: This also requires mutual recursion because REAPER will
|
||||
// call `getState()` while opening a popup menu
|
||||
const tresult result =
|
||||
main_context
|
||||
.run_in_context<tresult>([&]() {
|
||||
// This same function is defined in both
|
||||
// `IComponent` and `IEditController`, so the host
|
||||
// is calling one or the other
|
||||
if (object_instances[request.instance_id]
|
||||
.component) {
|
||||
return object_instances[request.instance_id]
|
||||
.component->getState(&request.state);
|
||||
} else {
|
||||
return object_instances[request.instance_id]
|
||||
.edit_controller->getState(&request.state);
|
||||
}
|
||||
})
|
||||
.get();
|
||||
do_mutual_recursion_on_gui_thread<tresult>([&]() {
|
||||
// This same function is defined in both `IComponent`
|
||||
// and `IEditController`, so the host is calling one or
|
||||
// the other
|
||||
if (object_instances[request.instance_id].component) {
|
||||
return object_instances[request.instance_id]
|
||||
.component->getState(&request.state);
|
||||
} else {
|
||||
return object_instances[request.instance_id]
|
||||
.edit_controller->getState(&request.state);
|
||||
}
|
||||
});
|
||||
|
||||
return Vst3PluginProxy::GetStateResponse{
|
||||
.result = result, .state = std::move(request.state)};
|
||||
|
||||
Reference in New Issue
Block a user