2 * Copyright (C) 2010-2016 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef _PIANO_KEYBOARD_H_
21 #define _PIANO_KEYBOARD_H_
24 #include <gtkmm/drawingarea.h>
28 class APianoKeyboard : public Gtk::DrawingArea
34 sigc::signal<void, int, int> NoteOn;
35 sigc::signal<void, int> NoteOff;
36 sigc::signal<void> Rest;
37 sigc::signal<void,bool> SustainChanged;
38 sigc::signal<void, int, bool> PitchBend;
39 sigc::signal<void, bool> SwitchOctave;
50 void sustain_press ();
51 void sustain_release ();
53 void set_note_on (int note);
54 void set_note_off (int note);
56 void set_grand_piano_highlight (bool enabled);
57 void set_annotate_layout (bool enabled);
58 void set_annotate_octave (bool enabled);
60 void set_monophonic (bool monophonic);
61 void set_octave (int octave);
62 void set_octave_range (int octave_range);
63 void set_keyboard_layout (Layout layout);
64 void set_velocities (int min_vel, int max_vel, int key_vel);
67 bool on_key_press_event (GdkEventKey*);
68 bool on_key_release_event (GdkEventKey*);
69 bool on_button_press_event (GdkEventButton*);
70 bool on_button_release_event (GdkEventButton*);
71 bool on_motion_notify_event (GdkEventMotion*);
72 bool on_expose_event (GdkEventExpose*);
74 void on_size_request (Gtk::Requisition*);
75 void on_size_allocate (Gtk::Allocation&);
78 void annotate_layout (cairo_t* cr, int note) const;
79 void annotate_note (cairo_t* cr, int note) const;
80 void draw_note (cairo_t* cr, int note) const;
82 void queue_note_draw (int note);
84 bool handle_fixed_keys (GdkEventKey*);
86 void press_key (int key, int vel);
87 void release_key (int key);
88 void stop_sustained_notes ();
89 void stop_unsustained_notes ();
91 int key_binding (const char* key) const;
92 void bind_key (const char* key, int note);
95 void bind_keys_qwerty ();
96 void bind_keys_qwertz ();
97 void bind_keys_azerty ();
98 void bind_keys_dvorak ();
100 void bind_keys_basic_qwerty ();
101 void bind_keys_basic_qwertz ();
103 int get_note_for_xy (int x, int y) const;
104 int get_velocity_for_note_at_y (int note, int y) const;
106 int is_black (int key) const;
107 double black_key_left_shift (int key) const;
109 void recompute_dimensions ();
121 bool pressed; /* true if key is in pressed down state. */
122 bool sustained; /* true if note is sustained. */
123 bool white; /* true if key is white; 0 otherwise. */
124 int x; /* Distance between the left edge of the key and the left edge of the widget, in pixels. */
125 int w; /* Width of the key, in pixels. */
126 int h; /* Height of the key, in pixels. */
129 bool _sustain_new_notes;
130 bool _highlight_grand_piano_range;
131 bool _annotate_layout;
132 bool _annotate_octave;
135 int _note_being_pressed_using_mouse;
144 PKNote _notes[NNOTES];
146 std::map<std::string, int> _key_bindings; /**< Table used to translate from PC keyboard character to MIDI note number. */
147 std::map<int, std::string> _note_bindings; /**< Table to translate from MIDI note number to PC keyboard character. */
148 std::map<std::string, int> _note_stack;
150 /* these are only valid during expose/draw */
151 PangoFontDescription* _font_cue;
152 PangoFontDescription* _font_octave;