2 Copyright (C) 2010 Paul Davis
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.
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.
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.
22 #include "gtkmm2ext/keyboard.h"
24 #include "ardour_ui.h"
25 #include "midi_channel_selector.h"
26 #include "midi_time_axis.h"
27 #include "step_entry.h"
35 _note_off_event_handler (GtkWidget
* widget
, int note
, gpointer arg
)
37 ((StepEntry
*)arg
)->note_off_event_handler (note
);
41 _rest_event_handler (GtkWidget
* widget
, gpointer arg
)
43 ((StepEntry
*)arg
)->rest_event_handler ();
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, 1, 4)
55 , channel_spinner (channel_adjustment
)
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)
65 uint16_t chn_mask
= _mtv
->channel_selector().get_selected_channels();
67 for (uint32_t i
= 0; i
< 16; ++i
) {
68 if (chn_mask
& (1<<i
)) {
69 channel_adjustment
.set_value (i
+1);
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
);
85 w
= manage (new Image (::get_icon (X_("wholenote"))));
87 length_1_button
.add (*w
);
88 w
= manage (new Image (::get_icon (X_("halfnote"))));
90 length_2_button
.add (*w
);
91 w
= manage (new Image (::get_icon (X_("quarternote"))));
93 length_4_button
.add (*w
);
94 w
= manage (new Image (::get_icon (X_("eighthnote"))));
96 length_8_button
.add (*w
);
97 w
= manage (new Image (::get_icon (X_("sixteenthnote"))));
99 length_16_button
.add (*w
);
100 w
= manage (new Image (::get_icon (X_("thirtysecondnote"))));
102 length_32_button
.add (*w
);
103 w
= manage (new Image (::get_icon (X_("sixtyfourthnote"))));
105 length_64_button
.add (*w
);
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;
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);
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"), "");
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
);
140 w
= manage (new Image (::get_icon (X_("pianississimo"))));
142 velocity_ppp_button
.add (*w
);
143 w
= manage (new Image (::get_icon (X_("pianissimo"))));
145 velocity_pp_button
.add (*w
);
146 w
= manage (new Image (::get_icon (X_("piano"))));
148 velocity_p_button
.add (*w
);
149 w
= manage (new Image (::get_icon (X_("mezzopiano"))));
151 velocity_mp_button
.add (*w
);
152 w
= manage (new Image (::get_icon (X_("mezzoforte"))));
154 velocity_mf_button
.add (*w
);
155 w
= manage (new Image (::get_icon (X_("forte"))));
157 velocity_f_button
.add (*w
);
158 w
= manage (new Image (::get_icon (X_("fortissimo"))));
160 velocity_ff_button
.add (*w
);
161 w
= manage (new Image (::get_icon (X_("fortississimo"))));
163 velocity_fff_button
.add (*w
);
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;
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"), "");
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);
192 Label
* l
= manage (new Label
);
193 l
->set_markup ("<b><big>.</big></b>");
197 w
= manage (new Image (::get_icon (X_("chord"))));
199 chord_button
.add (*w
);
201 rest_box
.pack_start (rest_button
, false, false);
202 rest_box
.pack_start (grid_rest_button
, false, false);
204 resync_box
.pack_start (beat_resync_button
, false, false);
205 resync_box
.pack_start (bar_resync_button
, false, false);
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"), "");
215 VBox
* v
= manage (new VBox
);
216 l
= manage (new Label (_("Channel")));
218 v
->pack_start (*l
, false, false);
219 v
->pack_start (channel_spinner
, false, false);
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);
232 _piano
= (PianoKeyboard
*) piano_keyboard_new ();
233 piano
= Glib::wrap ((GtkWidget
*) _piano
);
235 piano
->set_flags (Gtk::CAN_FOCUS
);
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);
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
));
247 packer
.set_spacing (6);
248 packer
.pack_start (upper_box
, false, false);
249 packer
.pack_start (*piano
, false, false);
252 get_vbox()->add (packer
);
255 StepEntry::~StepEntry()
260 StepEntry::on_key_press_event (GdkEventKey
* ev
)
262 if (!gtk_window_propagate_key_event (GTK_WINDOW(gobj()), ev
)) {
263 return gtk_window_activate_key (GTK_WINDOW(gobj()), ev
);
269 StepEntry::on_key_release_event (GdkEventKey
* ev
)
271 if (!gtk_window_propagate_key_event (GTK_WINDOW(gobj()), ev
)) {
272 return gtk_window_activate_key (GTK_WINDOW(gobj()), ev
);
278 StepEntry::rest_event_handler ()
280 _mtv
->step_edit_rest (0.0);
284 StepEntry::note_length () const
286 Evoral::MusicalTime length
= 0.0;
288 if (length_64_button
.get_active()) {
290 } else if (length_32_button
.get_active()) {
292 } else if (length_16_button
.get_active()) {
294 } else if (length_8_button
.get_active()) {
296 } else if (length_4_button
.get_active()) {
298 } else if (length_2_button
.get_active()) {
300 } else if (length_1_button
.get_active()) {
304 if (dot_button
.get_active()) {
308 if (_mtv
->step_edit_within_triplet()) {
316 StepEntry::note_velocity () const
318 uint8_t velocity
= 64;
320 if (velocity_ppp_button
.get_active()) {
322 } else if (velocity_pp_button
.get_active()) {
324 } else if (velocity_p_button
.get_active()) {
326 } else if (velocity_mp_button
.get_active()) {
328 } else if (velocity_mf_button
.get_active()) {
330 } else if (velocity_f_button
.get_active()) {
332 } else if (velocity_ff_button
.get_active()) {
334 } else if (velocity_fff_button
.get_active()) {
342 StepEntry::note_channel() const
344 return channel_adjustment
.get_value() - 1;
348 StepEntry::note_off_event_handler (int note
)
350 _mtv
->step_add_note (note_channel(), note
, note_velocity(), note_length());
354 StepEntry::rest_click ()
356 _mtv
->step_edit_rest (note_length());
360 StepEntry::grid_rest_click ()
362 _mtv
->step_edit_rest (0.0);
366 StepEntry::triplet_toggled ()
368 if (triplet_button
.get_active () != _mtv
->step_edit_within_triplet()) {
369 _mtv
->step_edit_toggle_triplet ();
374 StepEntry::chord_toggled ()
376 if (chord_button
.get_active() != _mtv
->step_edit_within_chord ()) {
377 _mtv
->step_edit_toggle_chord ();
382 StepEntry::on_show ()
384 ArdourDialog::on_show ();
385 piano
->grab_focus ();
389 StepEntry::beat_resync_click ()
391 _mtv
->step_edit_beat_sync ();
395 StepEntry::bar_resync_click ()
397 _mtv
->step_edit_bar_sync ();
401 StepEntry::register_actions ()
403 step_entry_actions
= ActionGroup::create (X_("StepEdit"));
405 /* non-operative menu items for menu bar */
407 ActionManager::register_action (editor_actions
, X_("AlignMenu"), _("Align"));
409 /* add named actions for the editor */
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
));
424 RadioAction::Group note_length_group
;
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
));
441 RadioAction::Group note_velocity_group
;
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
));
460 uim
->insert_action_group (step_entry_actions
);