Ardour  9.0-pre0-582-g084a23a80d
pianokeyboard.h
Go to the documentation of this file.
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 #include "piano_key_bindings.h"
27 
28 #define NNOTES (128)
29 
31 {
32 public:
35 
36  sigc::signal<void, int, int> NoteOn;
37  sigc::signal<void, int> NoteOff;
38  sigc::signal<void> Rest;
39  sigc::signal<void,bool> SustainChanged;
40  sigc::signal<void, int, bool> PitchBend;
41  sigc::signal<void, int> SetVelocity;
42  sigc::signal<void, bool> SwitchOctave;
43 
44  void sustain_press ();
45  void sustain_release ();
46 
47  void set_note_on (int note);
48  void set_note_off (int note);
49  void reset ();
50 
51  void set_grand_piano_highlight (bool enabled);
52  void set_annotate_layout (bool enabled);
53  void set_annotate_octave (bool enabled);
54 
55  void set_monophonic (bool monophonic);
56  void set_octave (int octave);
57  void set_octave_range (int octave_range);
59  void set_velocities (int min_vel, int max_vel, int key_vel);
60 
61 protected:
68 
71 
72 private:
73  void annotate_layout (cairo_t* cr, int note) const;
74  void annotate_note (cairo_t* cr, int note) const;
75  void draw_note (cairo_t* cr, int note) const;
76 
77  void queue_note_draw (int note);
78 
80 
81  void press_key (int key, int vel);
82  void release_key (int key);
85 
86  int get_note_for_xy (int x, int y) const;
87  int get_velocity_for_note_at_y (int note, int y) const;
88 
89  int is_black (int key) const;
90  double black_key_left_shift (int key) const;
91 
93 
94  struct PKNote {
95  PKNote ()
96  : pressed (false)
97  , sustained (false)
98  , white (false)
99  , x (0)
100  , w (0)
101  , h (0)
102  {}
103 
104  bool pressed; /* true if key is in pressed down state. */
105  bool sustained; /* true if note is sustained. */
106  bool white; /* true if key is white; 0 otherwise. */
107  int x; /* Distance between the left edge of the key and the left edge of the widget, in pixels. */
108  int w; /* Width of the key, in pixels. */
109  int h; /* Height of the key, in pixels. */
110  };
111 
116  int _octave;
126 
128 
130  std::map<std::string, int> _note_stack;
131 
132  /* these are only valid during expose/draw */
133  PangoFontDescription* _font_cue;
134  PangoFontDescription* _font_octave;
135 };
136 
137 #endif
void draw_note(cairo_t *cr, int note) const
int get_note_for_xy(int x, int y) const
void queue_note_draw(int note)
void set_note_on(int note)
sigc::signal< void > Rest
Definition: pianokeyboard.h:38
PKNote _notes[(128)]
sigc::signal< void, bool > SustainChanged
Definition: pianokeyboard.h:39
void release_key(int key)
sigc::signal< void, int > NoteOff
Definition: pianokeyboard.h:37
void sustain_press()
sigc::signal< void, bool > SwitchOctave
Definition: pianokeyboard.h:42
void set_grand_piano_highlight(bool enabled)
int _note_being_pressed_using_mouse
bool on_key_release_event(GdkEventKey *)
This is a default handler for the signal signal_key_release_event().
void set_annotate_layout(bool enabled)
void on_size_request(Gtk::Requisition *)
This is a default handler for the signal signal_size_request().
void annotate_note(cairo_t *cr, int note) const
void recompute_dimensions()
sigc::signal< void, int > SetVelocity
Definition: pianokeyboard.h:41
void set_octave_range(int octave_range)
std::map< std::string, int > _note_stack
void stop_sustained_notes()
void set_octave(int octave)
PangoFontDescription * _font_cue
double black_key_left_shift(int key) const
int is_black(int key) const
sigc::signal< void, int, int > NoteOn
Definition: pianokeyboard.h:36
void set_velocities(int min_vel, int max_vel, int key_vel)
bool handle_fixed_keys(GdkEventKey *)
bool on_button_press_event(GdkEventButton *)
This is a default handler for the signal signal_button_press_event().
bool on_key_press_event(GdkEventKey *)
This is a default handler for the signal signal_key_press_event().
void stop_unsustained_notes()
bool _highlight_grand_piano_range
bool on_expose_event(GdkEventExpose *)
This is a default handler for the signal signal_expose_event().
void set_monophonic(bool monophonic)
void on_size_allocate(Gtk::Allocation &)
This is a default handler for the signal signal_size_allocate().
void set_note_off(int note)
sigc::signal< void, int, bool > PitchBend
Definition: pianokeyboard.h:40
bool on_motion_notify_event(GdkEventMotion *)
This is a default handler for the signal signal_motion_notify_event().
void sustain_release()
PangoFontDescription * _font_octave
void set_annotate_octave(bool enabled)
void annotate_layout(cairo_t *cr, int note) const
void press_key(int key, int vel)
void set_keyboard_layout(PianoKeyBindings::Layout layout)
int get_velocity_for_note_at_y(int note, int y) const
PianoKeyBindings _keyboard_layout
bool on_button_release_event(GdkEventButton *)
This is a default handler for the signal signal_button_release_event().
#define NNOTES
Definition: pianokeyboard.h:28