From db08810164e9fd673ac6c8d8a219b2a0f6b3a9c1 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 2 Nov 2019 23:52:29 +0100 Subject: Virtual-keyboard: "Tab" to sustain (still undocumented) --- gtk2_ardour/pianokeyboard.cc | 42 ++++++++++++++++++++++++---------- gtk2_ardour/pianokeyboard.h | 3 ++- gtk2_ardour/virtual_keyboard_window.cc | 3 +++ 3 files changed, 35 insertions(+), 13 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/pianokeyboard.cc b/gtk2_ardour/pianokeyboard.cc index d4a43940dc..d7635cf3c6 100644 --- a/gtk2_ardour/pianokeyboard.cc +++ b/gtk2_ardour/pianokeyboard.cc @@ -211,8 +211,6 @@ APianoKeyboard::press_key (int key, int vel) assert (key >= 0); assert (key < NNOTES); - _maybe_stop_sustained_notes = false; - /* This is for keyboard autorepeat protection. */ if (_notes[key].pressed) { return; @@ -247,8 +245,6 @@ APianoKeyboard::release_key (int key) assert (key >= 0); assert (key < NNOTES); - _maybe_stop_sustained_notes = false; - if (!_notes[key].pressed) { return; } @@ -284,8 +280,10 @@ APianoKeyboard::stop_sustained_notes () { for (int i = 0; i < NNOTES; ++i) { if (_notes[i].sustained) { - _notes[i].pressed = false; _notes[i].sustained = false; + if (_notes[i].pressed) { + continue; + } NoteOff (i); /* EMIT SIGNAL */ queue_note_draw (i); } @@ -322,6 +320,7 @@ APianoKeyboard::bind_keys_qwerty () clear_notes (); bind_key ("space", 128); + bind_key ("Tab", 129); /* Lower keyboard row - "zxcvbnm". */ bind_key ("z", 12); /* C0 */ @@ -375,6 +374,7 @@ APianoKeyboard::bind_keys_azerty () clear_notes (); bind_key ("space", 128); + bind_key ("Tab", 129); /* Lower keyboard row - "wxcvbn,". */ bind_key ("w", 12); /* C0 */ @@ -418,6 +418,7 @@ APianoKeyboard::bind_keys_dvorak () clear_notes (); bind_key ("space", 128); + bind_key ("Tab", 129); /* Lower keyboard row - ";qjkxbm". */ bind_key ("semicolon", 12); /* C0 */ @@ -471,6 +472,7 @@ APianoKeyboard::bind_keys_basic_qwerty () clear_notes (); bind_key ("space", 128); + bind_key ("Tab", 129); /* simple - middle rows only */ bind_key ("a", 12); /* C0 */ @@ -500,6 +502,7 @@ APianoKeyboard::bind_keys_basic_qwertz () clear_notes (); bind_key ("space", 128); + bind_key ("Tab", 129); /* simple - middle rows only */ bind_key ("a", 12); /* C0 */ @@ -552,6 +555,10 @@ APianoKeyboard::on_key_press_event (GdkEventKey* event) /* Rest is used on release */ return false; } + if (note == 129) { + toggle_sustain (); + return true; + } note += _octave * 12; @@ -856,7 +863,6 @@ APianoKeyboard::APianoKeyboard () using namespace Gdk; add_events (KEY_PRESS_MASK | KEY_RELEASE_MASK | BUTTON_PRESS_MASK | BUTTON_RELEASE_MASK | POINTER_MOTION_MASK | POINTER_MOTION_HINT_MASK); - _maybe_stop_sustained_notes = false; _sustain_new_notes = false; _highlight_grand_piano_range = true; _annotate_layout = false; @@ -920,22 +926,34 @@ APianoKeyboard::set_velocities (int min_vel, int max_vel, int key_vel) } } +void +APianoKeyboard::toggle_sustain () +{ + if (_sustain_new_notes) { + sustain_release (); + } else { + sustain_press (); + } +} + void APianoKeyboard::sustain_press () { - if (!_sustain_new_notes) { - _sustain_new_notes = true; - _maybe_stop_sustained_notes = true; + if (_sustain_new_notes) { + return; } + _sustain_new_notes = true; + SustainChanged (true); /* EMIT SIGNAL */ } void APianoKeyboard::sustain_release () { - if (_maybe_stop_sustained_notes) { - stop_sustained_notes (); + stop_sustained_notes (); + if (_sustain_new_notes) { + _sustain_new_notes = false; + SustainChanged (false); /* EMIT SIGNAL */ } - _sustain_new_notes = false; } void diff --git a/gtk2_ardour/pianokeyboard.h b/gtk2_ardour/pianokeyboard.h index d4435e56b2..56c2d2cdf1 100644 --- a/gtk2_ardour/pianokeyboard.h +++ b/gtk2_ardour/pianokeyboard.h @@ -34,6 +34,7 @@ public: sigc::signal NoteOn; sigc::signal NoteOff; sigc::signal Rest; + sigc::signal SustainChanged; enum Layout { QWERTY, @@ -78,6 +79,7 @@ private: void queue_note_draw (int note); + void toggle_sustain (); void press_key (int key, int vel); void release_key (int key); void stop_sustained_notes (); @@ -121,7 +123,6 @@ private: int h; /* Height of the key, in pixels. */ }; - bool _maybe_stop_sustained_notes; bool _sustain_new_notes; bool _highlight_grand_piano_range; bool _annotate_layout; diff --git a/gtk2_ardour/virtual_keyboard_window.cc b/gtk2_ardour/virtual_keyboard_window.cc index c27b2465a6..ad61aeea23 100644 --- a/gtk2_ardour/virtual_keyboard_window.cc +++ b/gtk2_ardour/virtual_keyboard_window.cc @@ -378,6 +378,9 @@ VirtualKeyboardWindow::on_key_press_event (GdkEventKey* ev) _piano.grab_focus (); /* handle up/down */ + // XXX consider to handle these in APianoKeyboard::on_key_press_event + // and use signals. -- also subscribe SustainChanged, indicate sustain. + // TODO: pitch-bend shortcuts if (ev->type == GDK_KEY_PRESS) { if (ev->keyval == GDK_KEY_Left) { _piano_octave_key.set_value (_piano_octave_key.get_value_as_int () - 1); -- cgit v1.2.3