dexed
dexed copied to clipboard
Add option to keep keyboard focussed on the MIDI keyboard
While browsing through patches and carts, I figured it would be very convenient for the computer keyboard to remain focussed on the on-screen MIDI keyboard component so that I could play notes as I clicked through patches. So I've added this functionality, as well as a toggle to configure it on and off. It was mostly for myself, but I figured that others might find it useful too!
Please let me know if you require any changes!
I've fixed the Linux build, but haven't had a chance to look at the macOS build yet!
I have also fixed the macOS build by simply referencing the two new files I added in the project, but for some reason it shuffled around the project file, creating a huge diff! Please let me know if I should revert.
@asb2m10 Any feedback? No rush! Just curious to hear your thoughts.
Good implementation and it is a good idea. The only issue is that Dexed keeps the focus all the time, at least here on Linux. I cannot even rename a cartridge name.
Can we check on what we have lost the focus ? So if it is a sub-component of Dexed, we keep it, but if it an top level window change, we give it...
Sounds good! I'll implement the suggestion.
I've found a way to check which component grabbed focus. Works well on Linux from my tests, but I still want to do a thorough check before updating the PR.
Similar to how I'm checking if the parameters window took focus, I also want to see if the store dialog took focus, since I've noticed that also gets pushed to the back. Will make that change and then do some more testing across platforms when I have some time.
Here is the updated method so far:
void DexedMidiKeyboardComponent::focusLost(FocusChangeType focusChangeType) {
MidiKeyboardComponent::focusLost(focusChangeType);
/* Get the component that grabbed focus away from the keyboard.
* If the method returns null, it is not a Dexed component.
*/
Component *currentlyFocusedComponent = getCurrentlyFocusedComponent();
bool currentlyFocusedComponentIsNotADexedComponent = currentlyFocusedComponent == NULL;
// Return early if focus was lost to another application.
if (currentlyFocusedComponentIsNotADexedComponent == true) {
return;
}
// If the parameters window is opened, grabbing keyboard focus back can push it behind the Dexed window.
bool parmButtonClicked = currentlyFocusedComponent->getName() == "parmButton";
bool shouldGrabKeyboardFocus =
parmButtonClicked != true
&& showKeyboard == true
&& preferMidiKeyboardFocus == true;
if (shouldGrabKeyboardFocus == true) {
grabKeyboardFocus();
}
}
I've updated the focusLost method to check if the keyboard lost focus to a Dexed component, and if it did, only keep focus if the component it lost focus to shouldn't have focus instead. Tested on Windows, Linux and macOS and it seems to be working well!
Also it shouldn't steal the whole keyboard, but just keys used to operate the virtual MIDI keyboard, IMHO.
For example, you should still be able to use arrows and Enter to move around in the browser.