summaryrefslogtreecommitdiff
path: root/gtk2_ardour/pianokeyboard.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2019-12-16 15:02:39 +0100
committerRobin Gareus <robin@gareus.org>2019-12-16 15:02:39 +0100
commit322e6e08c436d98402c430fff7af5196137fe292 (patch)
treef44f55f85a44424b29099fb0b0fad85d4346748c /gtk2_ardour/pianokeyboard.cc
parent2add7302637ba645e946ee127fe87c929b84212e (diff)
Vkeybd: grab all key-events and use timer instead of key-repeat
This fixes an issue with arrow-keys (up/down, left/right). Those were previously only handled when the Virtual Keyboard window itself had focus. Also key-repeat for pitch-bend is now ignored and a dedicated timer is used to queue events. This fixes an issue with the first repeat taking longer than successive ones, and makes this feature independent of any desktop user settings.
Diffstat (limited to 'gtk2_ardour/pianokeyboard.cc')
-rw-r--r--gtk2_ardour/pianokeyboard.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/gtk2_ardour/pianokeyboard.cc b/gtk2_ardour/pianokeyboard.cc
index c68b674742..c41e8dae5a 100644
--- a/gtk2_ardour/pianokeyboard.cc
+++ b/gtk2_ardour/pianokeyboard.cc
@@ -559,11 +559,68 @@ get_keycode (GdkEventKey* event)
}
bool
+APianoKeyboard::handle_fixed_keys (GdkEventKey* ev)
+{
+ if (ev->type == GDK_KEY_PRESS) {
+ switch (ev->keyval) {
+ case GDK_KEY_Left:
+ SwitchOctave (false);
+ return true;
+ case GDK_KEY_Right:
+ SwitchOctave (true);
+ return true;
+ case GDK_KEY_F1:
+ PitchBend (0, false);
+ return true;
+ case GDK_KEY_F2:
+ PitchBend (4096, false);
+ return true;
+ case GDK_KEY_F3:
+ PitchBend (12288, false);
+ return true;
+ case GDK_KEY_F4:
+ PitchBend (16383, false);
+ return true;
+ case GDK_KEY_Down:
+ PitchBend (0, true);
+ return true;
+ case GDK_KEY_Up:
+ PitchBend (16383, true);
+ return true;
+ default:
+ break;
+ }
+ } else if (ev->type == GDK_KEY_RELEASE) {
+ switch (ev->keyval) {
+ case GDK_KEY_F1:
+ /* fallthrough */
+ case GDK_KEY_F2:
+ /* fallthrough */
+ case GDK_KEY_F3:
+ /* fallthrough */
+ case GDK_KEY_F4:
+ /* fallthrough */
+ case GDK_KEY_Up:
+ /* fallthrough */
+ case GDK_KEY_Down:
+ PitchBend (8192, false);
+ return true;
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
+bool
APianoKeyboard::on_key_press_event (GdkEventKey* event)
{
if (Gtkmm2ext::Keyboard::modifier_state_contains (event->state, Gtkmm2ext::Keyboard::PrimaryModifier)) {
return false;
}
+ if (handle_fixed_keys (event)) {
+ return true;
+ }
char const* key = get_keycode (event);
int note = key_binding (key);
@@ -603,6 +660,10 @@ APianoKeyboard::on_key_release_event (GdkEventKey* event)
if (Gtkmm2ext::Keyboard::modifier_state_contains (event->state, Gtkmm2ext::Keyboard::PrimaryModifier)) {
return false;
}
+ if (handle_fixed_keys (event)) {
+ return true;
+ }
+
char const* key = get_keycode (event);
if (!key) {