make StepEntry into a singleton.
[ardour.git] / gtk2_ardour / step_entry.h
1 /*
2     Copyright (C) 2010 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 __gtk2_ardour_step_entry_h__
21 #define __gtk2_ardour_step_entry_h__
22
23 #include <gtkmm/togglebutton.h>
24 #include <gtkmm/radiobutton.h>
25 #include <gtkmm/spinbutton.h>
26 #include <gtkmm/box.h>
27 #include <gtkmm/adjustment.h>
28 #include <gtkmm2ext/bindings.h>
29
30 #include "ardour_window.h"
31 #include "gtk_pianokeyboard.h"
32
33 class StepEditor;
34
35 class StepEntry : public ArdourWindow
36 {
37   public:
38         static StepEntry& instance();
39
40         ~StepEntry ();
41
42         void set_step_editor (StepEditor*);
43
44         void note_off_event_handler (int note);
45         void rest_event_handler ();
46
47         Temporal::Beats note_length();
48         uint8_t note_velocity() const;
49         uint8_t note_channel() const;
50
51         int current_octave () const { return (int) floor (octave_adjustment.get_value()); }
52
53         static void setup_actions_and_bindings ();
54
55   private:
56         static StepEntry* _instance;
57         StepEntry ();
58
59         Temporal::Beats _current_note_length;
60         uint8_t _current_note_velocity;
61
62         Gtk::VBox packer;
63         Gtk::HBox upper_box;
64         Gtk::HBox note_length_box;
65         Gtk::HBox note_velocity_box;
66
67         Gtk::ToggleButton chord_button;
68         Gtk::ToggleButton triplet_button;
69         Gtk::ToggleButton dot0_button;
70         Gtk::ToggleButton dot1_button;
71         Gtk::ToggleButton dot2_button;
72         Gtk::ToggleButton dot3_button;
73         Gtk::Adjustment   dot_adjustment;
74         Gtk::VBox dot_box1;
75         Gtk::VBox dot_box2;
76         Gtk::ToggleButton restart_button;
77
78         Gtk::VBox   resync_box;
79         Gtk::Button beat_resync_button;
80         Gtk::Button bar_resync_button;
81         Gtk::Button resync_button;
82
83         Gtk::Button sustain_button;
84         Gtk::Button rest_button;
85         Gtk::Button grid_rest_button;
86         Gtk::VBox   rest_box;
87
88         Gtk::Button back_button;
89
90         Gtk::RadioButton length_1_button;
91         Gtk::RadioButton length_2_button;
92         Gtk::RadioButton length_4_button;
93         Gtk::RadioButton length_8_button;
94         Gtk::RadioButton length_12_button;
95         Gtk::RadioButton length_16_button;
96         Gtk::RadioButton length_32_button;
97         Gtk::RadioButton length_64_button;
98
99         Gtk::RadioButton velocity_ppp_button;
100         Gtk::RadioButton velocity_pp_button;
101         Gtk::RadioButton velocity_p_button;
102         Gtk::RadioButton velocity_mp_button;
103         Gtk::RadioButton velocity_mf_button;
104         Gtk::RadioButton velocity_f_button;
105         Gtk::RadioButton velocity_ff_button;
106         Gtk::RadioButton velocity_fff_button;
107
108         Gtk::Adjustment channel_adjustment;
109         Gtk::SpinButton channel_spinner;
110
111         Gtk::Adjustment octave_adjustment;
112         Gtk::SpinButton octave_spinner;
113
114         Gtk::Adjustment length_divisor_adjustment;
115         Gtk::SpinButton length_divisor_spinner;
116
117         Gtk::Adjustment velocity_adjustment;
118         Gtk::SpinButton velocity_spinner;
119
120         Gtk::Adjustment bank_adjustment;
121         Gtk::SpinButton bank_spinner;
122         Gtk::Button     bank_button;
123
124         Gtk::Adjustment program_adjustment;
125         Gtk::SpinButton program_spinner;
126         Gtk::Button     program_button;
127
128         void length_changed ();
129         void velocity_changed ();
130         void velocity_value_change ();
131         void length_value_change ();
132
133         PianoKeyboard* _piano;
134         Gtk::Widget* piano;
135         StepEditor*   se;
136
137         void bank_click ();
138         void program_click ();
139         void beat_resync_click ();
140         void bar_resync_click ();
141
142         bool piano_enter_notify_event (GdkEventCrossing *ev);
143         bool on_key_release_event (GdkEventKey*);
144         bool on_key_press_event (GdkEventKey*);
145
146         void on_show ();
147
148         /* actions */
149
150         void insert_note (uint8_t);
151         void insert_rest ();
152         void insert_grid_rest ();
153         void insert_a ();
154         void insert_asharp ();
155         void insert_b ();
156         void insert_c ();
157         void insert_csharp ();
158         void insert_d ();
159         void insert_dsharp ();
160         void insert_e ();
161         void insert_f ();
162         void insert_fsharp ();
163         void insert_g ();
164         void insert_gsharp ();
165         void note_length_change (GtkAction*);
166         void note_velocity_change (GtkAction*);
167         bool radio_button_press (GdkEventButton*);
168         bool radio_button_release (GdkEventButton*, Gtk::RadioButton*, int);
169         void inc_note_velocity ();
170         void dec_note_velocity ();
171         void next_note_velocity ();
172         void prev_note_velocity ();
173         void inc_note_length ();
174         void dec_note_length ();
175         void next_note_length ();
176         void prev_note_length ();
177         void next_octave ();
178         void prev_octave ();
179         void octave_n (int n);
180         void octave_0 () { octave_n (0); }
181         void octave_1 () { octave_n (1); }
182         void octave_2 () { octave_n (2); }
183         void octave_3 () { octave_n (3); }
184         void octave_4 () { octave_n (4); }
185         void octave_5 () { octave_n (5); }
186         void octave_6 () { octave_n (6); }
187         void octave_7 () { octave_n (7); }
188         void octave_8 () { octave_n (8); }
189         void octave_9 () { octave_n (9); }
190         void octave_10 () { octave_n (10); }
191         void dot_change (GtkAction*);
192         void dot_value_change ();
193         void toggle_triplet();
194         void toggle_chord();
195         void do_sustain ();
196         void back();
197         void sync_to_edit_point ();
198
199         /* static versions of action methods, so that we can register actions without
200            having an actual StepEntry object.
201         */
202
203         static void se_insert_rest () { if (_instance) { _instance->insert_rest (); } }
204         static void se_insert_grid_rest () { if (_instance) { _instance->insert_grid_rest (); } }
205         static void se_insert_a () { if (_instance) { _instance->insert_a (); } }
206         static void se_insert_asharp () { if (_instance) { _instance->insert_asharp (); } }
207         static void se_insert_b () { if (_instance) { _instance->insert_b (); } }
208         static void se_insert_c () { if (_instance) { _instance->insert_c (); } }
209         static void se_insert_csharp () { if (_instance) { _instance->insert_csharp (); } }
210         static void se_insert_d () { if (_instance) { _instance->insert_d (); } }
211         static void se_insert_dsharp () { if (_instance) { _instance->insert_dsharp (); } }
212         static void se_insert_e () { if (_instance) { _instance->insert_e (); } }
213         static void se_insert_f () { if (_instance) { _instance->insert_f (); } }
214         static void se_insert_fsharp () { if (_instance) { _instance->insert_fsharp (); } }
215         static void se_insert_g () { if (_instance) { _instance->insert_g (); } }
216         static void se_insert_gsharp () { if (_instance) { _instance->insert_gsharp (); } }
217         static void se_note_length_change (GtkAction* act) { if (_instance) { _instance->note_length_change (act); } }
218         static void se_note_velocity_change (GtkAction* act) { if (_instance) { _instance->note_velocity_change (act); } }
219         static bool se_radio_button_press (GdkEventButton* ev) { if (_instance) { return _instance->radio_button_press (ev); } return false; }
220         static bool se_radio_button_release (GdkEventButton* ev, Gtk::RadioButton* rb, int n) { if (_instance) { return  _instance->radio_button_release (ev, rb, n); } return false; }
221         static void se_inc_note_velocity () { if (_instance) { _instance->inc_note_velocity (); } }
222         static void se_dec_note_velocity () { if (_instance) { _instance->dec_note_velocity (); } }
223         static void se_next_note_velocity () { if (_instance) { _instance->next_note_velocity (); } }
224         static void se_prev_note_velocity () { if (_instance) { _instance->prev_note_velocity (); } }
225         static void se_inc_note_length () { if (_instance) { _instance->inc_note_length (); } }
226         static void se_dec_note_length () { if (_instance) { _instance->dec_note_length (); } }
227         static void se_next_note_length () { if (_instance) { _instance->next_note_length (); } }
228         static void se_prev_note_length () { if (_instance) { _instance->prev_note_length (); } }
229         static void se_next_octave () { if (_instance) { _instance->next_octave (); } }
230         static void se_prev_octave () { if (_instance) { _instance->prev_octave (); } }
231         static void se_octave_n (int n) { if (_instance) { _instance->octave_n (n); } }
232         static void se_octave_0 () { if (_instance) { _instance->octave_0 (); } }
233         static void se_octave_1 () { if (_instance) { _instance->octave_1 (); } }
234         static void se_octave_2 () { if (_instance) { _instance->octave_2 (); } }
235         static void se_octave_3 () { if (_instance) { _instance->octave_3 (); } }
236         static void se_octave_4 () { if (_instance) { _instance->octave_4 (); } }
237         static void se_octave_5 () { if (_instance) { _instance->octave_5 (); } }
238         static void se_octave_6 () { if (_instance) { _instance->octave_6 (); } }
239         static void se_octave_7 () { if (_instance) { _instance->octave_7 (); } }
240         static void se_octave_8 () { if (_instance) { _instance->octave_8 (); } }
241         static void se_octave_9 () { if (_instance) { _instance->octave_9 (); } }
242         static void se_octave_10 () { if (_instance) { _instance->octave_10 (); } }
243         static void se_dot_change (GtkAction* act) { if (_instance) { _instance->dot_change (act); } }
244         static void se_dot_value_change () { if (_instance) { _instance->dot_value_change (); } }
245         static void se_toggle_triplet() { if (_instance) { _instance->toggle_triplet (); } }
246         static void se_toggle_chord() { if (_instance) { _instance->toggle_chord (); } }
247         static void se_do_sustain () { if (_instance) { _instance->do_sustain (); } }
248         static void se_back() { if (_instance) { _instance->back (); } }
249         static void se_sync_to_edit_point () { if (_instance) { _instance->sync_to_edit_point (); } }
250
251         static void load_bindings ();
252         static Gtkmm2ext::Bindings*  bindings;
253         static void register_actions ();
254 };
255
256 #endif /* __gtk2_ardour_step_entry_h__ */