The problem is easy to reproduce (i used Windows 8 and ableton 9 Demo) and its related to the keyboard hook fix for ableton live:
Load a VSTi Synth and make sure it has the focus. Then press a Keyboard key that LIVE consumes (for example ‘e’) and keep it. Now click somewhere into the plugin UI. After that the LIVE UI and the plugin does note response to mouse events anymore. The only thing you can do is to quit live with a task kill.
The debugger shows me that the program spends a lot of time in the keyboardHookCallback method while the UI does not response anymore:
I’m experiencing the same problem: press a key ‘c’ while the juce based plugin has focus and Live will hang. Very dramatic. This happens using the Juce tip and either Live 8.1.4 32bit or 9.0.5 64bit.
The culprit seems to be the SendMessage() call in keyboardHookCallback() in juce_VST_Wrapper.cpp. Every time this is called this leads to at least one more WM_CHAR message received by the hook, causing an infinite loop.
It’s not a code reentrancy problem and switching to PostMessage() does not help either.
The best solution is probably to not register the hook at all for Ableton 8 and 9.
A relatively elegant solution could be to change line 1341 in juce_VST_Wrapper.cpp to this:
#if JucePlugin_EditorRequiresKeyboardFocus
if (PluginHostType().isAbletonLive())
registerKeyboardHook();
#endif
The dev can then control whether the hook is installed or not using the IntroJucer parameter “Plugin editor requires keyboard focus”
Of course, without the hook the plugin does no longer receive keystrokes. This can be solved by having the user create an Options.txt file in the Live preferences directory at
c:\Users<user>\AppData\Roaming\Ableton\Live n.n.n\Preferences\
In order for the plugin to receive keystrokes the options file should contain this switch:
-_EnsureKeyMessagesForPlugins
Of course you then lose global keystrokes in Live itself when the plugin has focus, such as space to start/stop the transport. But we cannot have everything in life, can we…
Excellent idea about wrapping that hook in the JucePlugin_EditorRequiresKeyboardFocus macro - I’ll get that sorted out. And thanks for the clear explanation of Live’s setting files too!
btw while at it, you might perhaps remove the whole keyboard hook as well, since it has no real added value any more because of the way Live conflicts with it. People can always enable keystrokes with the Live options.txt file if they must have it.
Unless I overlook cases where it really is necessary to have the hook?
TBH I can’t remember all the details, but I certainly wouldn’t have added it for no reason! But if it definitely screws up in Live 8 + 9, then perhaps I should leave it in there just for v7 and earlier?
I only tested on 8 & 9. For all I know Live 7 could have the same problem…
I guess the hook was originally added as a workaround to Live’s default behaviour of not passing keystrokes to plugins? Maybe before there was an Options.txt switch to change that behaviour?
Btw the hook seems to induce an additional problem besides the hang/crash : when displaying a juce dialog window containing an edit box, any keystrokes entered there are duplicated 3 or 4 times.
Hmm, it does sound problematic. Doing a search, it seems that someone sent me the hook code back in 2009. I guess that unless anyone has an objection, I should just get rid of it?