Simplify the opening editor behaviour again

This partially reverts 16fce5577d.
This commit is contained in:
Robbert van der Helm
2020-05-27 14:05:57 +02:00
parent d65281d691
commit 5a0c3c4627
2 changed files with 73 additions and 62 deletions
+28 -11
View File
@@ -33,6 +33,13 @@
#include "../editor.h"
#include "../utils.h"
/**
* A marker struct to indicate that the editor is about to be opened.
*
* @see Vst2Bridge::editor
*/
struct EditorOpening {};
/**
* This hosts a Windows VST2 plugin, forwards messages sent by the Linux VST
* plugin and provides host callback function for the plugin to talk back.
@@ -75,7 +82,9 @@ class Vst2Bridge {
* but in our approach there will be an opportunity to handle events in
* between these two calls. Most plugins will handle this just fine, but
* some plugins end up blocking indefinitely while waiting for the other
* function to be called, hence why this function is needed.
* function to be called, hence why this function is needed. For
* individually hosted plugins this check is done implicitely in
* `Vst2Bridge::handle_win32_events()`.
*/
bool should_skip_message_loop();
@@ -261,17 +270,25 @@ class Vst2Bridge {
* Wine window, and embedding that Wine window into a window provided by the
* host. Should be empty when the editor is not open.
*
* There is some special behavior with regards to message handling when the
* editor is in the process of being opened, see
* `should_postpone_message_loop()`.
* This field can have three possible states:
*
* - `std::nullopt` when the editor is closed.
* - An `Editor` object when the editor is open.
* - `EditorOpening` when the editor is not yet open, but the host has
* already called `effEditGetRect()` and is about to call `effEditOpen()`.
* This is needed because there is a race condition in some bugs that
* cause them to crash or enter an infinite Win32 message loop when
* `effEditGetRect()` gets dispatched and we then enter the message loop
* loop before `effEditOpen()` gets called. Most plugins will handle this
* just fine, but a select few plugins make the assumption that the editor
* is already open once `effEditGetRect()` has been called, even if
* `effEditOpen` has not yet been dispatched. VST hsots on Windows will
* call these two events in sequence, so the bug would never occur there.
* To work around this we'll use this third state to temporarily stop
* processing Windows events in the one or two ticks between these two
* events.
*
* @see should_postpone_message_loop
*/
std::optional<Editor> editor;
/**
* Keeps track of when the editor is being opened during the two-phase
* process of the host calling `effEditOpen()` and `effEditGetRect()`.
*/
bool editor_is_opening = false;
std::variant<std::monostate, Editor, EditorOpening> editor;
};