From 12d4d6daa7178770052970b7b95aa32f92662ac8 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 25 Oct 2019 21:23:27 +0200 Subject: Virtual-keyboard: never-ending details - Fix key-bindings (first propagate to piano, ignore global bindings) - Allow to switch octaves with left/right arrow key - Tweak font-sizes used for annotations --- gtk2_ardour/pianokeyboard.cc | 32 +++++++++++++++---------------- gtk2_ardour/pianokeyboard.h | 8 ++++---- gtk2_ardour/virtual_keyboard_window.cc | 35 +++++++++++++++++++++++++++------- 3 files changed, 47 insertions(+), 28 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/pianokeyboard.cc b/gtk2_ardour/pianokeyboard.cc index 39955dfa9e..85187ce116 100644 --- a/gtk2_ardour/pianokeyboard.cc +++ b/gtk2_ardour/pianokeyboard.cc @@ -108,7 +108,7 @@ APianoKeyboard::annotate_note (cairo_t* cr, int note) const int tw, th; char buf[32]; - sprintf (buf, "C%2d", (note / 12) - 1); + sprintf (buf, "C%d", (note / 12) - 1); PangoLayout* pl = pango_cairo_create_layout (cr); pango_layout_set_font_description (pl, _font_octave); pango_layout_set_text (pl, buf, -1); @@ -179,11 +179,11 @@ APianoKeyboard::draw_note (cairo_t* cr, int note) const cairo_rectangle (cr, x, 0, w, h); cairo_stroke (cr); - if (_print_note_label && (note % 12) == 0) { + if (_annotate_octave && (note % 12) == 0) { annotate_note (cr, note); } - if (_enable_keyboard_cue) { + if (_annotate_layout) { annotate_layout (cr, note); } @@ -482,7 +482,6 @@ APianoKeyboard::on_key_press_event (GdkEventKey* event) key = gdk_keyval_name (gdk_keyval_to_lower (keyval)); if (key == NULL) { - g_message ("gtk_keyval_name() returned NULL; please report this."); return false; } @@ -495,9 +494,9 @@ APianoKeyboard::on_key_press_event (GdkEventKey* event) if (note == 128) { if (event->type == GDK_KEY_RELEASE) { Rest (); /* EMIT SIGNAL */ + return true; } - - return true; + return false; } note += _octave * 12; @@ -510,7 +509,6 @@ APianoKeyboard::on_key_press_event (GdkEventKey* event) } else if (event->type == GDK_KEY_RELEASE) { release_key (note); } - return true; } @@ -644,7 +642,7 @@ APianoKeyboard::on_expose_event (GdkEventExpose* event) char buf[32]; sprintf (buf, "ArdourMono %dpx", MAX (8, MIN (20, _notes[1].w / 2 + 3))); _font_cue = pango_font_description_from_string (buf); - sprintf (buf, "ArdourMono %dpx", MAX (10, MIN (20, MIN (_notes[0].w / 2 + 3, _notes[0].h / 7)))); + sprintf (buf, "ArdourMono %dpx", MAX (8, MIN (20, MIN (_notes[0].w * 11 / 15 , _notes[0].h / 7)))); _font_octave = pango_font_description_from_string (buf); for (int i = 0; i < NNOTES; ++i) { @@ -781,9 +779,9 @@ APianoKeyboard::APianoKeyboard () _maybe_stop_sustained_notes = false; _sustain_new_notes = false; - _enable_keyboard_cue = false; - _highlight_grand_piano_range = false; - _print_note_label = false; + _highlight_grand_piano_range = true; + _annotate_layout = false; + _annotate_octave = false; _octave = 4; _octave_range = 7; _note_being_pressed_using_mouse = -1; @@ -804,23 +802,23 @@ APianoKeyboard::~APianoKeyboard () } void -APianoKeyboard::set_keyboard_cue (bool enabled) +APianoKeyboard::set_grand_piano_highlight (bool enabled) { - _enable_keyboard_cue = enabled; + _highlight_grand_piano_range = enabled; queue_draw (); } void -APianoKeyboard::set_grand_piano_highlight (bool enabled) +APianoKeyboard::set_annotate_layout (bool enabled) { - _highlight_grand_piano_range = enabled; + _annotate_layout = enabled; queue_draw (); } void -APianoKeyboard::show_note_label (bool enabled) +APianoKeyboard::set_annotate_octave (bool enabled) { - _print_note_label = enabled; + _annotate_octave = enabled; queue_draw (); } diff --git a/gtk2_ardour/pianokeyboard.h b/gtk2_ardour/pianokeyboard.h index bcf9c0e1b4..b3089f4d0b 100644 --- a/gtk2_ardour/pianokeyboard.h +++ b/gtk2_ardour/pianokeyboard.h @@ -48,9 +48,9 @@ public: void set_note_on (int note); void set_note_off (int note); - void set_keyboard_cue (bool enabled); void set_grand_piano_highlight (bool enabled); - void show_note_label (bool enabled); + void set_annotate_layout (bool enabled); + void set_annotate_octave (bool enabled); void set_monophonic (bool monophonic); void set_octave (int octave); @@ -118,9 +118,9 @@ private: bool _maybe_stop_sustained_notes; bool _sustain_new_notes; - bool _enable_keyboard_cue; bool _highlight_grand_piano_range; - bool _print_note_label; + bool _annotate_layout; + bool _annotate_octave; int _octave; int _octave_range; int _note_being_pressed_using_mouse; diff --git a/gtk2_ardour/virtual_keyboard_window.cc b/gtk2_ardour/virtual_keyboard_window.cc index d58cffc3d3..dc103c52de 100644 --- a/gtk2_ardour/virtual_keyboard_window.cc +++ b/gtk2_ardour/virtual_keyboard_window.cc @@ -60,7 +60,8 @@ VirtualKeyboardWindow::VirtualKeyboardWindow () _piano.set_flags (Gtk::CAN_FOCUS); _piano.set_keyboard_layout (APianoKeyboard::QWERTY); - _piano.show_note_label (true); + _piano.set_annotate_octave (true); + _piano.set_grand_piano_highlight (false); using namespace Menu_Helpers; _keyboard_layout.AddMenuElem (MenuElem ("QWERTY", @@ -90,11 +91,11 @@ VirtualKeyboardWindow::VirtualKeyboardWindow () _pitchbend->ValueChanged.connect_same_thread (_cc_connections, boost::bind (&VirtualKeyboardWindow::pitch_bend_event_handler, this, _1)); set_tooltip (_highlight_grand_piano, "Shade keys outside the range of a Grand Piano (A0-C8)."); - set_tooltip (_highlight_key_range, "Indicate which notes can be controlled by keyboard-shortcuts."); + set_tooltip (_highlight_key_range, "When enabled, indicate keyboard-shortcuts on the piano-keys."); set_tooltip (_show_note_label, "When enabled, print octave number on C-Keys"); set_tooltip (_yaxis_velocity, "When enabled, mouse-click y-axis position defines the velocity."); - set_tooltip (_piano_octave_key, "The center octave, and lowest octave for keyboard control."); + set_tooltip (_piano_octave_key, "The center octave, and lowest octave for keyboard control. Change with Arrow left/right."); set_tooltip (_piano_octave_range, "Available octave range, centered around the key-octave."); set_tooltip (_keyboard_layout, "Keyboard layout to use for keyboard control."); @@ -326,11 +327,11 @@ VirtualKeyboardWindow::set_state (const XMLNode& root) } if (node->get_property (X_("HighlightKeyRange"), a)) { _highlight_key_range.set_active (a); - _piano.set_keyboard_cue (a); + _piano.set_annotate_layout (a); } if (node->get_property (X_("ShowNoteLabel"), a)) { _show_note_label.set_active (a); - _piano.show_note_label (a); + _piano.set_annotate_octave (a); } int v; @@ -379,6 +380,26 @@ bool VirtualKeyboardWindow::on_key_press_event (GdkEventKey* ev) { _piano.grab_focus (); + + /* try propagate unmodified events first */ + if ((ev->state & 0xf) == 0) { + if (gtk_window_propagate_key_event (gobj(), ev)) { + return true; + } + } + + /* handle up/down */ + 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); + return true; + } + if (ev->keyval == GDK_KEY_Right) { + _piano_octave_key.set_value (_piano_octave_key.get_value_as_int () + 1); + return true; + } + } + return ARDOUR_UI_UTILS::relay_key_press (ev, this); } @@ -458,7 +479,7 @@ VirtualKeyboardWindow::toggle_highlight_key (GdkEventButton*) { bool a = !_highlight_key_range.get_active (); _highlight_key_range.set_active (a); - _piano.set_keyboard_cue (a); + _piano.set_annotate_layout (a); return false; } @@ -467,7 +488,7 @@ VirtualKeyboardWindow::toggle_note_label (GdkEventButton*) { bool a = !_show_note_label.get_active (); _show_note_label.set_active (a); - _piano.show_note_label (a); + _piano.set_annotate_octave (a); return false; } -- cgit v1.2.3