Ardour  9.10-68-g45485b915a
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 <ytkmm/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:
71 
72  void on_unmap ();
75 
76 private:
77  void annotate_layout (cairo_t* cr, int note) const;
78  void annotate_note (cairo_t* cr, int note) const;
79  void draw_note (cairo_t* cr, int note) const;
80 
81  void queue_note_draw (int note);
82 
84 
85  void press_key (int key, int vel);
86  void release_key (int key);
89 
90  int get_note_for_xy (int x, int y) const;
91  int get_velocity_for_note_at_y (int note, int y) const;
92 
93  int is_black (int key) const;
94  double black_key_left_shift (int key) const;
95 
97 
98  struct PKNote {
99  PKNote ()
100  : pressed (0)
101  , sustained (false)
102  , white (false)
103  , x (0)
104  , w (0)
105  , h (0)
106  {}
107 
108  int pressed; /* >0 if key is in pressed down state; count input sources for this key. */
109  bool sustained; /* true if note is sustained. */
110  bool white; /* true if key is white; 0 otherwise. */
111  int x; /* Distance between the left edge of the key and the left edge of the widget, in pixels. */
112  int w; /* Width of the key, in pixels. */
113  int h; /* Height of the key, in pixels. */
114  };
115 
120  int _octave;
130 
132 
134  std::map<std::string, int> _note_stack;
135  std::map<guint, int> _touched_notes;
136 
137  /* these are only valid during expose/draw */
138  PangoFontDescription* _font_cue;
139  PangoFontDescription* _font_octave;
140 };
141 
142 #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)
bool on_touch_update_event(GdkEventTouch *)
sigc::signal< void > Rest
Definition: pianokeyboard.h:38
void on_unmap()
This is a default handler for the signal signal_unmap().
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()
std::map< guint, int > _touched_notes
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_touch_end_event(GdkEventTouch *)
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().
bool on_touch_begin_event(GdkEventTouch *)
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