unused new actions code for step entry
[ardour.git] / gtk2_ardour / step_entry.cc
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 #include <iostream>
21
22 #include "gtkmm2ext/keyboard.h"
23
24 #include "ardour_ui.h"
25 #include "midi_channel_selector.h"
26 #include "midi_time_axis.h"
27 #include "step_entry.h"
28 #include "utils.h"
29
30 #include "i18n.h"
31
32 using namespace Gtk;
33
34 static void
35 _note_off_event_handler (GtkWidget* widget, int note, gpointer arg)
36 {
37         ((StepEntry*)arg)->note_off_event_handler (note);
38 }
39
40 static void
41 _rest_event_handler (GtkWidget* widget, gpointer arg)
42 {
43         ((StepEntry*)arg)->rest_event_handler ();
44 }
45
46 StepEntry::StepEntry (MidiTimeAxisView& mtv)
47         : ArdourDialog (string_compose (_("Step Entry: %1"), mtv.name()))
48         , triplet_button ("3")
49         , beat_resync_button (_(">beat"))
50         , bar_resync_button (_(">bar"))
51         , sustain_button (_("sustain"))
52         , rest_button (_("rest"))
53         , grid_rest_button (_("g-rest"))
54         , channel_adjustment (1, 1, 16, 0, 1, 4) 
55         , channel_spinner (channel_adjustment)
56         , _piano (0)
57         , piano (0)
58         , _mtv (&mtv)
59 {
60         /* set channel selector to first selected channel. if none
61            are selected, it will remain at the value set in its
62            constructor, above (1)
63         */
64
65         uint16_t chn_mask = _mtv->channel_selector().get_selected_channels();
66         
67         for (uint32_t i = 0; i < 16; ++i) {
68                 if (chn_mask & (1<<i)) {
69                         channel_adjustment.set_value (i+1);
70                         break;
71                 }
72         }
73
74         RadioButtonGroup length_group = length_1_button.get_group();
75         length_2_button.set_group (length_group);
76         length_4_button.set_group (length_group);
77         length_8_button.set_group (length_group);
78         length_12_button.set_group (length_group);
79         length_16_button.set_group (length_group);
80         length_32_button.set_group (length_group);
81         length_64_button.set_group (length_group);
82
83         Widget* w;
84
85         w = manage (new Image (::get_icon (X_("wholenote"))));
86         w->show();
87         length_1_button.add (*w);
88         w = manage (new Image (::get_icon (X_("halfnote"))));
89         w->show();
90         length_2_button.add (*w);
91         w = manage (new Image (::get_icon (X_("quarternote"))));
92         w->show();
93         length_4_button.add (*w);
94         w = manage (new Image (::get_icon (X_("eighthnote"))));
95         w->show();
96         length_8_button.add (*w);
97         w = manage (new Image (::get_icon (X_("sixteenthnote"))));
98         w->show();
99         length_16_button.add (*w);
100         w = manage (new Image (::get_icon (X_("thirtysecondnote"))));
101         w->show();
102         length_32_button.add (*w);
103         w = manage (new Image (::get_icon (X_("sixtyfourthnote"))));
104         w->show();
105         length_64_button.add (*w);
106
107         length_1_button.property_draw_indicator() = false;
108         length_2_button.property_draw_indicator() = false;
109         length_4_button.property_draw_indicator() = false;
110         length_8_button.property_draw_indicator() = false;
111         length_16_button.property_draw_indicator() = false;
112         length_32_button.property_draw_indicator() = false;
113         length_64_button.property_draw_indicator() = false;
114
115         note_length_box.pack_start (length_1_button, false, false);
116         note_length_box.pack_start (length_2_button, false, false);
117         note_length_box.pack_start (length_4_button, false, false);
118         note_length_box.pack_start (length_8_button, false, false);
119         note_length_box.pack_start (length_16_button, false, false);
120         note_length_box.pack_start (length_32_button, false, false);
121         note_length_box.pack_start (length_64_button, false, false);
122
123         ARDOUR_UI::instance()->set_tip (&length_1_button, _("Set note length to a whole note"), "");
124         ARDOUR_UI::instance()->set_tip (&length_2_button, _("Set note length to a half note"), "");
125         ARDOUR_UI::instance()->set_tip (&length_4_button, _("Set note length to a quarter note"), "");
126         ARDOUR_UI::instance()->set_tip (&length_8_button, _("Set note length to a eighth note"), "");
127         ARDOUR_UI::instance()->set_tip (&length_16_button, _("Set note length to a sixteenth note"), "");
128         ARDOUR_UI::instance()->set_tip (&length_32_button, _("Set note length to a thirty-second note"), "");
129         ARDOUR_UI::instance()->set_tip (&length_64_button, _("Set note length to a sixty-fourth note"), "");
130
131         RadioButtonGroup velocity_group = velocity_ppp_button.get_group();
132         velocity_pp_button.set_group (velocity_group);
133         velocity_p_button.set_group (velocity_group);
134         velocity_mp_button.set_group (velocity_group);
135         velocity_mf_button.set_group (velocity_group);
136         velocity_f_button.set_group (velocity_group);
137         velocity_ff_button.set_group (velocity_group);
138         velocity_fff_button.set_group (velocity_group);
139
140         w = manage (new Image (::get_icon (X_("pianississimo"))));
141         w->show();
142         velocity_ppp_button.add (*w);
143         w = manage (new Image (::get_icon (X_("pianissimo"))));
144         w->show();
145         velocity_pp_button.add (*w);
146         w = manage (new Image (::get_icon (X_("piano"))));
147         w->show();
148         velocity_p_button.add (*w);
149         w = manage (new Image (::get_icon (X_("mezzopiano"))));
150         w->show();
151         velocity_mp_button.add (*w);
152         w = manage (new Image (::get_icon (X_("mezzoforte"))));
153         w->show();
154         velocity_mf_button.add (*w);
155         w = manage (new Image (::get_icon (X_("forte"))));
156         w->show();
157         velocity_f_button.add (*w);
158         w = manage (new Image (::get_icon (X_("fortissimo"))));
159         w->show();
160         velocity_ff_button.add (*w);
161         w = manage (new Image (::get_icon (X_("fortississimo"))));
162         w->show();
163         velocity_fff_button.add (*w);
164
165         velocity_ppp_button.property_draw_indicator() = false;
166         velocity_pp_button.property_draw_indicator() = false;
167         velocity_p_button.property_draw_indicator() = false;
168         velocity_mp_button.property_draw_indicator() = false;
169         velocity_mf_button.property_draw_indicator() = false;
170         velocity_f_button.property_draw_indicator() = false;
171         velocity_ff_button.property_draw_indicator() = false;
172         velocity_fff_button.property_draw_indicator() = false;
173
174         ARDOUR_UI::instance()->set_tip (&velocity_ppp_button, _("Set volume (velocity) to pianississimo"), "");
175         ARDOUR_UI::instance()->set_tip (&velocity_pp_button, _("Set volume (velocity) to pianissimo"), "");
176         ARDOUR_UI::instance()->set_tip (&velocity_p_button, _("Set volume (velocity) to piano"), "");
177         ARDOUR_UI::instance()->set_tip (&velocity_mp_button, _("Set volume (velocity) to mezzo-piano"), "");
178         ARDOUR_UI::instance()->set_tip (&velocity_mf_button, _("Set volume (velocity) to mezzo-forte"), "");
179         ARDOUR_UI::instance()->set_tip (&velocity_f_button, _("Set volume (velocity) to forte"), "");
180         ARDOUR_UI::instance()->set_tip (&velocity_ff_button, _("Set volume (velocity) to forteissimo"), "");
181         ARDOUR_UI::instance()->set_tip (&velocity_fff_button, _("Set volume (velocity) to forteississimo"), "");
182
183         note_velocity_box.pack_start (velocity_ppp_button, false, false);
184         note_velocity_box.pack_start (velocity_pp_button, false, false);
185         note_velocity_box.pack_start (velocity_p_button, false, false);
186         note_velocity_box.pack_start (velocity_mp_button, false, false);
187         note_velocity_box.pack_start (velocity_mf_button, false, false);
188         note_velocity_box.pack_start (velocity_f_button, false, false);
189         note_velocity_box.pack_start (velocity_ff_button, false, false);
190         note_velocity_box.pack_start (velocity_fff_button, false, false);
191
192         Label* l = manage (new Label);
193         l->set_markup ("<b><big>.</big></b>");
194         l->show ();
195         dot_button.add (*l);
196
197         w = manage (new Image (::get_icon (X_("chord"))));
198         w->show();
199         chord_button.add (*w);
200
201         rest_box.pack_start (rest_button, false, false);
202         rest_box.pack_start (grid_rest_button, false, false);
203
204         resync_box.pack_start (beat_resync_button, false, false);
205         resync_box.pack_start (bar_resync_button, false, false);
206
207         ARDOUR_UI::instance()->set_tip (&chord_button, _("Stack inserted notes to form a chord"), "");
208         ARDOUR_UI::instance()->set_tip (&sustain_button, _("Extend selected notes by note length"), "");
209         ARDOUR_UI::instance()->set_tip (&dot_button, _("Use dotted note lengths"), "");
210         ARDOUR_UI::instance()->set_tip (&rest_button, _("Insert a note-length's rest"), "");
211         ARDOUR_UI::instance()->set_tip (&grid_rest_button, _("Insert a grid-unit's rest"), "");
212         ARDOUR_UI::instance()->set_tip (&beat_resync_button, _("Insert a rest until the next beat"), "");
213         ARDOUR_UI::instance()->set_tip (&bar_resync_button, _("Insert a rest until the next bar"), "");
214
215         VBox* v = manage (new VBox);
216         l = manage (new Label (_("Channel")));
217         v->set_spacing (6);
218         v->pack_start (*l, false, false);
219         v->pack_start (channel_spinner, false, false);
220
221         upper_box.set_spacing (6);
222         upper_box.pack_start (chord_button, false, false);
223         upper_box.pack_start (note_length_box, false, false, 12);
224         upper_box.pack_start (triplet_button, false, false);
225         upper_box.pack_start (dot_button, false, false);
226         upper_box.pack_start (sustain_button, false, false);
227         upper_box.pack_start (rest_box, false, false);
228         upper_box.pack_start (resync_box, false, false);
229         upper_box.pack_start (note_velocity_box, false, false, 12);
230         upper_box.pack_start (*v, false, false);
231
232         _piano = (PianoKeyboard*) piano_keyboard_new ();
233         piano = Glib::wrap ((GtkWidget*) _piano);
234
235         piano->set_flags (Gtk::CAN_FOCUS);
236
237         g_signal_connect(G_OBJECT(_piano), "note-off", G_CALLBACK(_note_off_event_handler), this);
238         g_signal_connect(G_OBJECT(_piano), "rest", G_CALLBACK(_rest_event_handler), this);
239         
240         rest_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::rest_click));
241         grid_rest_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::grid_rest_click));
242         chord_button.signal_toggled().connect (sigc::mem_fun (*this, &StepEntry::chord_toggled));
243         triplet_button.signal_toggled().connect (sigc::mem_fun (*this, &StepEntry::triplet_toggled));
244         beat_resync_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::beat_resync_click));
245         bar_resync_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::bar_resync_click));
246
247         packer.set_spacing (6);
248         packer.pack_start (upper_box, false, false);
249         packer.pack_start (*piano, false, false);
250         packer.show_all ();
251
252         get_vbox()->add (packer);
253 }
254
255 StepEntry::~StepEntry()
256 {
257 }
258
259 bool
260 StepEntry::on_key_press_event (GdkEventKey* ev)
261 {
262         if (!gtk_window_propagate_key_event (GTK_WINDOW(gobj()), ev)) {
263                 return gtk_window_activate_key (GTK_WINDOW(gobj()), ev);
264         }
265         return true;
266 }
267
268 bool
269 StepEntry::on_key_release_event (GdkEventKey* ev)
270 {
271         if (!gtk_window_propagate_key_event (GTK_WINDOW(gobj()), ev)) {
272                 return gtk_window_activate_key (GTK_WINDOW(gobj()), ev);
273         }
274         return true;
275 }
276
277 void
278 StepEntry::rest_event_handler ()
279 {
280         _mtv->step_edit_rest (0.0);
281 }
282
283 Evoral::MusicalTime
284 StepEntry::note_length () const
285 {
286         Evoral::MusicalTime length = 0.0;
287
288         if (length_64_button.get_active()) {
289                 length = 1.0/64.0;
290         } else if (length_32_button.get_active()) {
291                 length = 1.0/32.0;
292         } else if (length_16_button.get_active()) {
293                 length = 1.0/16.0;
294         } else if (length_8_button.get_active()) {
295                 length = 1.0/8.0;
296         } else if (length_4_button.get_active()) {
297                 length = 1.0/4.0;
298         } else if (length_2_button.get_active()) {
299                 length = 1.0/2.0;
300         } else if (length_1_button.get_active()) {
301                 length = 1.0/1.0;
302         }
303
304         if (dot_button.get_active()) {
305                 length *= 0.5;
306         }
307
308         if (_mtv->step_edit_within_triplet()) {
309                 length *= 2.0/3.0;
310         }
311
312         return length;
313 }
314
315 uint8_t
316 StepEntry::note_velocity () const
317 {
318         uint8_t velocity = 64;
319
320         if (velocity_ppp_button.get_active()) {
321                 velocity = 16;
322         } else if (velocity_pp_button.get_active()) {
323                 velocity = 32;
324         } else if (velocity_p_button.get_active()) {
325                 velocity = 48;
326         } else if (velocity_mp_button.get_active()) {
327                 velocity = 64;
328         } else if (velocity_mf_button.get_active()) {
329                 velocity = 80;
330         } else if (velocity_f_button.get_active()) {
331                 velocity = 96;
332         } else if (velocity_ff_button.get_active()) {
333                 velocity = 112;
334         } else if (velocity_fff_button.get_active()) {
335                 velocity = 127;
336         }
337
338         return velocity;
339 }
340
341 uint8_t 
342 StepEntry::note_channel() const
343 {
344         return channel_adjustment.get_value() - 1;
345 }
346
347 void
348 StepEntry::note_off_event_handler (int note)
349 {
350         _mtv->step_add_note (note_channel(), note, note_velocity(), note_length());
351 }
352
353 void
354 StepEntry::rest_click ()
355 {
356         _mtv->step_edit_rest (note_length());
357 }
358
359 void
360 StepEntry::grid_rest_click ()
361 {
362         _mtv->step_edit_rest (0.0);
363 }
364
365 void
366 StepEntry::triplet_toggled ()
367 {
368         if (triplet_button.get_active () != _mtv->step_edit_within_triplet()) {
369                 _mtv->step_edit_toggle_triplet ();
370         }
371 }
372
373 void
374 StepEntry::chord_toggled ()
375 {
376         if (chord_button.get_active() != _mtv->step_edit_within_chord ()) {
377                 _mtv->step_edit_toggle_chord ();
378         }
379 }
380
381 void
382 StepEntry::on_show ()
383 {
384         ArdourDialog::on_show ();
385         piano->grab_focus ();
386 }
387
388 void
389 StepEntry::beat_resync_click ()
390 {
391         _mtv->step_edit_beat_sync ();
392 }
393
394 void
395 StepEntry::bar_resync_click ()
396 {
397         _mtv->step_edit_bar_sync ();
398 }
399 #if 0
400 void
401 StepEntry::register_actions ()
402 {
403         step_entry_actions = ActionGroup::create (X_("StepEdit"));
404
405         /* non-operative menu items for menu bar */
406
407         ActionManager::register_action (editor_actions, X_("AlignMenu"), _("Align"));
408
409         /* add named actions for the editor */
410
411         ActionManager::register_action (step_entry_actions, "insert-a", _("Insert Note A"), sigc::mem_fun (*this, &StepEntry::insert_a));
412         ActionManager::register_action (step_entry_actions, "insert-bsharp", _("Insert Note A-sharp"), sigc::mem_fun (*this, &StepEntry::insert_asharp));
413         ActionManager::register_action (step_entry_actions, "insert-b", _("Insert Note B"), sigc::mem_fun (*this, &StepEntry::insert_b));
414         ActionManager::register_action (step_entry_actions, "insert-bsharp", _("Insert Note B-sharp"), sigc::mem_fun (*this, &StepEntry::insert_bsharp));
415         ActionManager::register_action (step_entry_actions, "insert-c", _("Insert Note C"), sigc::mem_fun (*this, &StepEntry::insert_c));
416         ActionManager::register_action (step_entry_actions, "insert-csharp", _("Insert Note C-sharp"), sigc::mem_fun (*this, &StepEntry::insert_csharp));
417         ActionManager::register_action (step_entry_actions, "insert-d", _("Insert Note D"), sigc::mem_fun (*this, &StepEntry::insert_d));
418         ActionManager::register_action (step_entry_actions, "insert-dsharp", _("Insert Note D-sharp"), sigc::mem_fun (*this, &StepEntry::insert_dsharp));
419         ActionManager::register_action (step_entry_actions, "insert-e", _("Insert Note E"), sigc::mem_fun (*this, &StepEntry::insert_e));
420         ActionManager::register_action (step_entry_actions, "insert-f", _("Insert Note F"), sigc::mem_fun (*this, &StepEntry::insert_f));
421         ActionManager::register_action (step_entry_actions, "insert-fsharp", _("Insert Note F-sharp"), sigc::mem_fun (*this, &StepEntry::insert_fsharp));
422         ActionManager::register_action (step_entry_actions, "insert-g", _("Insert Note G"), sigc::mem_fun (*this, &StepEntry::insert_g));
423
424         RadioAction::Group note_length_group;
425
426         ActionManager::register_radio_action (step_entry_actions, note_length_group, "note-length-whole", 
427                                               _("Set Note Length to Whole"), sigc::mem_fun (*this, &StepEntry::note_length_whole));
428         ActionManager::register_radio_action (step_entry_actions, note_length_group, "note-length-half", 
429                                               _("Set Note Length to 1/2"), sigc::mem_fun (*this, &StepEntry::note_length_half));
430         ActionManager::register_radio_action (step_entry_actions, note_length_group, "note-length-quarter",
431                                               _("Set Note Length to 1/4"), sigc::mem_fun (*this, &StepEntry::note_length_quarter));
432         ActionManager::register_radio_action (step_entry_actions, note_length_group, "note-length-eighth",
433                                               _("Set Note Length to 1/8"), sigc::mem_fun (*this, &StepEntry::note_length_eighth));
434         ActionManager::register_radio_action (step_entry_actions, note_length_group, "note-length-sixteenth",
435                                               _("Set Note Length to 1/16"), sigc::mem_fun (*this, &StepEntry::note_length_sixteenth));
436         ActionManager::register_radio_action (step_entry_actions, note_length_group, "note-length-thirtysecond",
437                                               _("Set Note Length to 1/32"), sigc::mem_fun (*this, &StepEntry::note_length_thirtysecond));
438         ActionManager::register_radio_action (step_entry_actions, note_length_group, "note-length-sixtyfourth",
439                                               _("Set Note Length to 1/64"), sigc::mem_fun (*this, &StepEntry::note_length_sixtyfourth));
440         
441         RadioAction::Group note_velocity_group;
442         
443         ActionManager::register_radio_action (step_entry_actions, note_velocity_group, "note-velocity-ppp",
444                                               _("Set Note Velocity to Pianississimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_ppp));
445         ActionManager::register_radio_action (step_entry_actions, note_velocity_group, "note-velocity-pp",
446                                               _("Set Note Velocity to Pianissimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_pp));
447         ActionManager::register_radio_action (step_entry_actions, note_velocity_group, "note-velocity-p",
448                                               _("Set Note Velocity to Piano"), sigc::mem_fun (*this, &StepEntry::note_velocity_p));
449         ActionManager::register_radio_action (step_entry_actions, note_velocity_group, "note-velocity-mp",
450                                               _("Set Note Velocity to Mezzo-Piano"), sigc::mem_fun (*this, &StepEntry::note_velocity_mp));
451         ActionManager::register_radio_action (step_entry_actions, note_velocity_group, "note-velocity-mf",
452                                               _("Set Note Velocity to Mezzo-Forte"), sigc::mem_fun (*this, &StepEntry::note_velocity_mf));
453         ActionManager::register_radio_action (step_entry_actions, note_velocity_group, "note-velocity-f",
454                                               _("Set Note Velocity to Forte"), sigc::mem_fun (*this, &StepEntry::note_velocity_f));
455         ActionManager::register_radio_action (step_entry_actions, note_velocity_group, "note-velocity-ff",
456                                               _("Set Note Velocity to Fortississimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_ff));
457         ActionManager::register_radio_action (step_entry_actions, note_velocity_group, "note-velocity-fff",
458                                               _("Set Note Velocity to Fortississimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_fff));
459         
460         uim->insert_action_group (step_entry_actions);
461 }
462 #endif