Implement IPlugView::onKeyDown with Editor::on_key_down hook#267
Open
paravozz wants to merge 1 commit intorobbert-vdh:masterfrom
Open
Implement IPlugView::onKeyDown with Editor::on_key_down hook#267paravozz wants to merge 1 commit intorobbert-vdh:masterfrom
paravozz wants to merge 1 commit intorobbert-vdh:masterfrom
Conversation
Previously the VST3 wrapper's `IPlugView::onKeyDown` returned `kNotImplemented` unconditionally. In REAPER on macOS this causes the host to intercept keys it has bound as accelerators — most visibly the space bar toggles transport instead of inserting a space in focused text inputs, even when the plugin editor has keyboard focus. Add a new `Editor::on_key_down(Option<char>) -> bool` trait method (default impl returns `false`, backwards compatible) and call it from the VST3 wrapper for keys with a non-zero VST3 virtual key code. Keys without a virtual key code (letters, digits, symbols) continue to flow through AppKit's normal `keyDown:` path so NSTextInputContext handles them — consuming them here would break letter input. This matches the mechanism VSTGUI already implements (and that Serum relies on), and the fix shape documented on the JUCE forum for the equivalent JUCE bug.
Author
|
FYI, also filed on the new maintained fork at BillyDM/nih-plug#9 (Codeberg), since |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements
IPlugView::onKeyDownin the VST3 wrapper, forwarding to a newEditor::on_key_down(Option<char>) -> booltrait method. The editor returnstruewhen it consumes the key (e.g. a text input has focus); the wrapper then returnskResultOkand the host skips its own accelerator. Otherwise the wrapper returnskResultFalseand the host processes the key normally.Motivation
On macOS REAPER, pressing space while a nih-plug plugin's text input has focus toggles REAPER's transport instead of inserting a space. This is because REAPER calls
IPlugView::onKeyDownfirst for keys bound to its accelerator table; if the plugin returnskResultTrueREAPER skips the accelerator, if it returnskNotImplemented(nih-plug's current default) REAPER runs it.This is a long-standing issue in JUCE for the same reason — JUCE's VST3 wrapper also returns
kNotImplemented. Commercial plugins that work in REAPER either use VSTGUI (which implementsonKeyDown) or ship patched JUCE forks.I verified the fix shape end-to-end with a probe JUCE plugin (applied the same override to
JuceVST3Editor, observed space typed into ajuce::TextEditor, no transport toggle, letters unaffected) before porting to nih-plug.Design notes
falseso existing editors remain source-compatible.key_code != 0are forwarded. VST3 populateskey_codewith a virtual key code for non-character keys (space →KEY_SPACE=7, return →KEY_RETURN=2, etc.) and leaves it zero for plain character keys. Character keys already reach the native view'skeyDown:and are handled viaNSTextInputContext— an earlier iteration that returnedkResultOkonkey_code == 0dropped all letter input.kResultOkon consume.vst3-sysre-exports onlykResultOk; the VST3 spec treatskResultTrueandkResultOkas identical.Option<char>is enough to close the space-bar gap.Test
Editor::on_key_downinto the focused textbox.Companion work
A vizia-plug implementation of
Editor::on_key_downlives atparavozz/vizia-plug#fix/vst3-on-key-down. I'll open it as a PR againstvizia/vizia-plugonce this trait method lands so it has a real API to implement against.