Fix thinkos in cubasish theme
[ardour.git] / gtk2_ardour / pianokeyboard.h
1 /*
2  * Copyright (C) 2010-2016 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #ifndef _PIANO_KEYBOARD_H_
21 #define _PIANO_KEYBOARD_H_
22
23 #include <map>
24 #include <gtkmm/drawingarea.h>
25
26 #define NNOTES (128)
27
28 class APianoKeyboard : public Gtk::DrawingArea
29 {
30 public:
31         APianoKeyboard ();
32         ~APianoKeyboard ();
33
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;
40
41         enum Layout {
42                 QWERTY,
43                 QWERTZ,
44                 AZERTY,
45                 DVORAK,
46                 S_QWERTY,
47                 S_QWERTZ
48         };
49
50         void sustain_press ();
51         void sustain_release ();
52
53         void set_note_on (int note);
54         void set_note_off (int note);
55         void reset ();
56
57         void set_grand_piano_highlight (bool enabled);
58         void set_annotate_layout (bool enabled);
59         void set_annotate_octave (bool enabled);
60
61         void set_monophonic (bool monophonic);
62         void set_octave (int octave);
63         void set_octave_range (int octave_range);
64         void set_keyboard_layout (Layout layout);
65         void set_velocities (int min_vel, int max_vel, int key_vel);
66
67 protected:
68         bool on_key_press_event (GdkEventKey*);
69         bool on_key_release_event (GdkEventKey*);
70         bool on_button_press_event (GdkEventButton*);
71         bool on_button_release_event (GdkEventButton*);
72         bool on_motion_notify_event (GdkEventMotion*);
73         bool on_expose_event (GdkEventExpose*);
74
75         void on_size_request (Gtk::Requisition*);
76         void on_size_allocate (Gtk::Allocation&);
77
78 private:
79         void annotate_layout (cairo_t* cr, int note) const;
80         void annotate_note (cairo_t* cr, int note) const;
81         void draw_note (cairo_t* cr, int note) const;
82
83         void queue_note_draw (int note);
84
85         bool handle_fixed_keys (GdkEventKey*);
86
87         void press_key (int key, int vel);
88         void release_key (int key);
89         void stop_sustained_notes ();
90         void stop_unsustained_notes ();
91
92         int  key_binding (const char* key) const;
93         void bind_key (const char* key, int note);
94         void clear_notes ();
95
96         void bind_keys_qwerty ();
97         void bind_keys_qwertz ();
98         void bind_keys_azerty ();
99         void bind_keys_dvorak ();
100
101         void bind_keys_basic_qwerty ();
102         void bind_keys_basic_qwertz ();
103
104         int get_note_for_xy (int x, int y) const;
105         int get_velocity_for_note_at_y (int note, int y) const;
106
107         int    is_black (int key) const;
108         double black_key_left_shift (int key) const;
109
110         void recompute_dimensions ();
111
112         struct PKNote {
113                 PKNote ()
114                         : pressed (false)
115                         , sustained (false)
116                         , white (false)
117                         , x (0)
118                         , w (0)
119                         , h (0)
120                 {}
121
122                 bool pressed;   /* true if key is in pressed down state. */
123                 bool sustained; /* true if note is sustained. */
124                 bool white;     /* true if key is white; 0 otherwise. */
125                 int  x;         /* Distance between the left edge of the key and the left edge of the widget, in pixels. */
126                 int  w;         /* Width of the key, in pixels. */
127                 int  h;         /* Height of the key, in pixels. */
128         };
129
130         bool _sustain_new_notes;
131         bool _highlight_grand_piano_range;
132         bool _annotate_layout;
133         bool _annotate_octave;
134         int  _octave;
135         int  _octave_range;
136         int  _note_being_pressed_using_mouse;
137         int  _min_note;
138         int  _max_note;
139         int  _last_key;
140         bool _monophonic;
141         int  _min_velocity;
142         int  _max_velocity;
143         int  _key_velocity;
144
145         PKNote _notes[NNOTES];
146
147         std::map<std::string, int> _key_bindings;  /**< Table used to translate from PC keyboard character to MIDI note number. */
148         std::map<int, std::string> _note_bindings; /**< Table to translate from MIDI note number to PC keyboard character. */
149         std::map<std::string, int> _note_stack;
150
151         /* these are only valid during expose/draw */
152         PangoFontDescription* _font_cue;
153         PangoFontDescription* _font_octave;
154 };
155
156 #endif