Fix crash when closing session, recursive mon-section removal
[ardour.git] / gtk2_ardour / gtk_pianokeyboard.h
1 /*
2     Copyright (C) 2012 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __PIANO_KEYBOARD_H__
21 #define __PIANO_KEYBOARD_H__
22
23 #include <glib.h>
24 #include <gtk/gtkdrawingarea.h>
25
26 G_BEGIN_DECLS
27
28 #define TYPE_PIANO_KEYBOARD                     (piano_keyboard_get_type ())
29 #define PIANO_KEYBOARD(obj)                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PIANO_KEYBOARD, PianoKeyboard))
30 #define PIANO_KEYBOARD_CLASS(klass)             (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PIANO_KEYBOARD, PianoKeyboardClass))
31 #define IS_PIANO_KEYBOARD(obj)                  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PIANO_KEYBOARD))
32 #define IS_PIANO_KEYBOARD_CLASS(klass)          (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PIANO_KEYBOARD))
33 #define PIANO_KEYBOARD_GET_CLASS(obj)           (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PIANO_KEYBOARD, PianoKeyboardClass))
34
35 typedef struct  _PianoKeyboard                  PianoKeyboard;
36 typedef struct  _PianoKeyboardClass             PianoKeyboardClass;
37
38 #define NNOTES                  127
39
40 #define OCTAVE_MIN      -1
41 #define OCTAVE_MAX      7
42
43 struct PKNote {
44         int                     pressed;                /* 1 if key is in pressed down state. */
45         int                     sustained;              /* 1 if note is sustained. */
46         int                     x;                      /* Distance between the left edge of the key
47                                                          * and the left edge of the widget, in pixels. */
48         int                     w;                      /* Width of the key, in pixels. */
49         int                     h;                      /* Height of the key, in pixels. */
50         int                     white;                  /* 1 if key is white; 0 otherwise. */
51 };
52
53 struct _PianoKeyboard
54 {
55         GtkDrawingArea          da;
56         int                     maybe_stop_sustained_notes;
57         int                     sustain_new_notes;
58         int                     enable_keyboard_cue;
59         int                     octave;
60         int                     widget_margin;
61         int                     note_being_pressed_using_mouse;
62         int         last_key;
63         gboolean    monophonic;
64         struct PKNote   notes[NNOTES];
65         /* Table used to translate from PC keyboard character to MIDI note number. */
66         GHashTable              *key_bindings;
67 };
68
69 struct _PianoKeyboardClass
70 {
71         GtkDrawingAreaClass     parent_class;
72 };
73
74 GType           piano_keyboard_get_type         (void) G_GNUC_CONST;
75 GtkWidget*      piano_keyboard_new              (void);
76 void            piano_keyboard_sustain_press    (PianoKeyboard *pk);
77 void            piano_keyboard_sustain_release  (PianoKeyboard *pk);
78 void            piano_keyboard_set_note_on      (PianoKeyboard *pk, int note);
79 void            piano_keyboard_set_note_off     (PianoKeyboard *pk, int note);
80 void            piano_keyboard_set_keyboard_cue (PianoKeyboard *pk, int enabled);
81 void            piano_keyboard_set_monophonic (PianoKeyboard *pk, gboolean monophonic);
82 void            piano_keyboard_set_octave (PianoKeyboard *pk, int octave);
83 gboolean        piano_keyboard_set_keyboard_layout (PianoKeyboard *pk, const char *layout);
84
85 G_END_DECLS
86
87 #endif /* __PIANO_KEYBOARD_H__ */
88