+ insert_note (note);
+}
+
+
+void
+StepEntry::on_show ()
+{
+ ArdourWindow::on_show ();
+ //piano->grab_focus ();
+}
+
+void
+StepEntry::beat_resync_click ()
+{
+ se->step_edit_beat_sync ();
+}
+
+void
+StepEntry::bar_resync_click ()
+{
+ se->step_edit_bar_sync ();
+}
+
+void
+StepEntry::register_actions ()
+{
+ /* add named actions for the step editor */
+
+ Glib::RefPtr<ActionGroup> group = myactions.create_action_group (X_("StepEditing"));
+
+ myactions.register_action (group, "insert-a", _("Insert Note A"), sigc::mem_fun (*this, &StepEntry::insert_a));
+ myactions.register_action (group, "insert-asharp", _("Insert Note A-sharp"), sigc::mem_fun (*this, &StepEntry::insert_asharp));
+ myactions.register_action (group, "insert-b", _("Insert Note B"), sigc::mem_fun (*this, &StepEntry::insert_b));
+ myactions.register_action (group, "insert-c", _("Insert Note C"), sigc::mem_fun (*this, &StepEntry::insert_c));
+ myactions.register_action (group, "insert-csharp", _("Insert Note C-sharp"), sigc::mem_fun (*this, &StepEntry::insert_csharp));
+ myactions.register_action (group, "insert-d", _("Insert Note D"), sigc::mem_fun (*this, &StepEntry::insert_d));
+ myactions.register_action (group, "insert-dsharp", _("Insert Note D-sharp"), sigc::mem_fun (*this, &StepEntry::insert_dsharp));
+ myactions.register_action (group, "insert-e", _("Insert Note E"), sigc::mem_fun (*this, &StepEntry::insert_e));
+ myactions.register_action (group, "insert-f", _("Insert Note F"), sigc::mem_fun (*this, &StepEntry::insert_f));
+ myactions.register_action (group, "insert-fsharp", _("Insert Note F-sharp"), sigc::mem_fun (*this, &StepEntry::insert_fsharp));
+ myactions.register_action (group, "insert-g", _("Insert Note G"), sigc::mem_fun (*this, &StepEntry::insert_g));
+ myactions.register_action (group, "insert-gsharp", _("Insert Note G-sharp"), sigc::mem_fun (*this, &StepEntry::insert_gsharp));
+
+ myactions.register_action (group, "insert-rest", _("Insert a Note-length Rest"), sigc::mem_fun (*this, &StepEntry::insert_rest));
+ myactions.register_action (group, "insert-snap-rest", _("Insert a Snap-length Rest"), sigc::mem_fun (*this, &StepEntry::insert_grid_rest));
+
+ myactions.register_action (group, "next-octave", _("Move to next octave"), sigc::mem_fun (*this, &StepEntry::next_octave));
+ myactions.register_action (group, "prev-octave", _("Move to next octave"), sigc::mem_fun (*this, &StepEntry::prev_octave));
+
+ myactions.register_action (group, "next-note-length", _("Move to Next Note Length"), sigc::mem_fun (*this, &StepEntry::next_note_length));
+ myactions.register_action (group, "prev-note-length", _("Move to Previous Note Length"), sigc::mem_fun (*this, &StepEntry::prev_note_length));
+
+ myactions.register_action (group, "inc-note-length", _("Increase Note Length"), sigc::mem_fun (*this, &StepEntry::inc_note_length));
+ myactions.register_action (group, "dec-note-length", _("Decrease Note Length"), sigc::mem_fun (*this, &StepEntry::dec_note_length));
+
+ myactions.register_action (group, "next-note-velocity", _("Move to Next Note Velocity"), sigc::mem_fun (*this, &StepEntry::next_note_velocity));
+ myactions.register_action (group, "prev-note-velocity", _("Move to Previous Note Velocity"), sigc::mem_fun (*this, &StepEntry::prev_note_velocity));
+
+ myactions.register_action (group, "inc-note-velocity", _("Increase Note Velocity"), sigc::mem_fun (*this, &StepEntry::inc_note_velocity));
+ myactions.register_action (group, "dec-note-velocity", _("Decrease Note Velocity"), sigc::mem_fun (*this, &StepEntry::dec_note_velocity));
+
+ myactions.register_action (group, "octave-0", _("Switch to the 1st octave"), sigc::mem_fun (*this, &StepEntry::octave_0));
+ myactions.register_action (group, "octave-1", _("Switch to the 2nd octave"), sigc::mem_fun (*this, &StepEntry::octave_1));
+ myactions.register_action (group, "octave-2", _("Switch to the 3rd octave"), sigc::mem_fun (*this, &StepEntry::octave_2));
+ myactions.register_action (group, "octave-3", _("Switch to the 4th octave"), sigc::mem_fun (*this, &StepEntry::octave_3));
+ myactions.register_action (group, "octave-4", _("Switch to the 5th octave"), sigc::mem_fun (*this, &StepEntry::octave_4));
+ myactions.register_action (group, "octave-5", _("Switch to the 6th octave"), sigc::mem_fun (*this, &StepEntry::octave_5));
+ myactions.register_action (group, "octave-6", _("Switch to the 7th octave"), sigc::mem_fun (*this, &StepEntry::octave_6));
+ myactions.register_action (group, "octave-7", _("Switch to the 8th octave"), sigc::mem_fun (*this, &StepEntry::octave_7));
+ myactions.register_action (group, "octave-8", _("Switch to the 9th octave"), sigc::mem_fun (*this, &StepEntry::octave_8));
+ myactions.register_action (group, "octave-9", _("Switch to the 10th octave"), sigc::mem_fun (*this, &StepEntry::octave_9));
+ myactions.register_action (group, "octave-10", _("Switch to the 11th octave"), sigc::mem_fun (*this, &StepEntry::octave_10));
+
+ myactions.register_toggle_action (group, "toggle-triplet", _("Toggle Triple Notes"),
+ sigc::mem_fun (*this, &StepEntry::toggle_triplet));
+
+ myactions.register_toggle_action (group, "toggle-chord", _("Toggle Chord Entry"),
+ sigc::mem_fun (*this, &StepEntry::toggle_chord));
+ myactions.register_action (group, "sustain", _("Sustain Selected Notes by Note Length"),
+ sigc::mem_fun (*this, &StepEntry::do_sustain));
+
+ myactions.register_action (group, "sync-to-edit-point", _("Move Insert Position to Edit Point"),
+ sigc::mem_fun (*this, &StepEntry::sync_to_edit_point));
+ myactions.register_action (group, "back", _("Move Insert Position Back by Note Length"),
+ sigc::mem_fun (*this, &StepEntry::back));
+ RadioAction::Group note_length_group;
+
+ myactions.register_radio_action (group, note_length_group, "note-length-whole",
+ _("Set Note Length to Whole"), sigc::mem_fun (*this, &StepEntry::note_length_change), 1);
+ myactions.register_radio_action (group, note_length_group, "note-length-half",
+ _("Set Note Length to 1/2"), sigc::mem_fun (*this, &StepEntry::note_length_change), 2);
+ myactions.register_radio_action (group, note_length_group, "note-length-third",
+ _("Set Note Length to 1/3"), sigc::mem_fun (*this, &StepEntry::note_length_change), 3);
+ myactions.register_radio_action (group, note_length_group, "note-length-quarter",
+ _("Set Note Length to 1/4"), sigc::mem_fun (*this, &StepEntry::note_length_change), 4);
+ myactions.register_radio_action (group, note_length_group, "note-length-eighth",
+ _("Set Note Length to 1/8"), sigc::mem_fun (*this, &StepEntry::note_length_change), 8);
+ myactions.register_radio_action (group, note_length_group, "note-length-sixteenth",
+ _("Set Note Length to 1/16"), sigc::mem_fun (*this, &StepEntry::note_length_change), 16);
+ myactions.register_radio_action (group, note_length_group, "note-length-thirtysecond",
+ _("Set Note Length to 1/32"), sigc::mem_fun (*this, &StepEntry::note_length_change), 32);
+ myactions.register_radio_action (group, note_length_group, "note-length-sixtyfourth",
+ _("Set Note Length to 1/64"), sigc::mem_fun (*this, &StepEntry::note_length_change), 64);
+
+ RadioAction::Group note_velocity_group;
+
+ myactions.register_radio_action (group, note_velocity_group, "note-velocity-ppp",
+ _("Set Note Velocity to Pianississimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 1);
+ myactions.register_radio_action (group, note_velocity_group, "note-velocity-pp",
+ _("Set Note Velocity to Pianissimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 16);
+ myactions.register_radio_action (group, note_velocity_group, "note-velocity-p",
+ _("Set Note Velocity to Piano"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 32);
+ myactions.register_radio_action (group, note_velocity_group, "note-velocity-mp",
+ _("Set Note Velocity to Mezzo-Piano"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 64);
+ myactions.register_radio_action (group, note_velocity_group, "note-velocity-mf",
+ _("Set Note Velocity to Mezzo-Forte"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 80);
+ myactions.register_radio_action (group, note_velocity_group, "note-velocity-f",
+ _("Set Note Velocity to Forte"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 96);
+ myactions.register_radio_action (group, note_velocity_group, "note-velocity-ff",
+ _("Set Note Velocity to Fortississimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 112);
+ myactions.register_radio_action (group, note_velocity_group, "note-velocity-fff",
+ _("Set Note Velocity to Fortississimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 127);
+
+
+ RadioAction::Group dot_group;
+
+ myactions.register_radio_action (group, dot_group, "no-dotted", _("No Dotted Notes"), sigc::mem_fun (*this, &StepEntry::dot_change), 0);
+ myactions.register_radio_action (group, dot_group, "toggle-dotted", _("Toggled Dotted Notes"), sigc::mem_fun (*this, &StepEntry::dot_change), 1);
+ myactions.register_radio_action (group, dot_group, "toggle-double-dotted", _("Toggled Double-Dotted Notes"), sigc::mem_fun (*this, &StepEntry::dot_change), 2);
+ myactions.register_radio_action (group, dot_group, "toggle-triple-dotted", _("Toggled Triple-Dotted Notes"), sigc::mem_fun (*this, &StepEntry::dot_change), 3);
+}
+
+void
+StepEntry::load_bindings ()
+{
+ bindings = Bindings::get_bindings (X_("Step Editing"), myactions);
+ set_data ("ardour-bindings", bindings);
+}
+
+void
+StepEntry::toggle_triplet ()
+{
+ se->set_step_edit_cursor_width (note_length());
+}
+
+void
+StepEntry::toggle_chord ()
+{
+ se->step_edit_toggle_chord ();
+}
+
+void
+StepEntry::dot_change (GtkAction* act)
+{
+ if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION(act))) {
+ gint v = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (act));
+ dot_adjustment.set_value (v);
+ }
+}
+
+void
+StepEntry::dot_value_change ()
+{
+ RefPtr<Action> act;
+ RefPtr<RadioAction> ract;
+ double val = dot_adjustment.get_value();
+ bool inconsistent = true;
+ vector<const char*> dot_actions;
+
+ dot_actions.push_back ("StepEditing/no-dotted");
+ dot_actions.push_back ("StepEditing/toggle-dotted");
+ dot_actions.push_back ("StepEditing/toggle-double-dotted");
+ dot_actions.push_back ("StepEditing/toggle-triple-dotted");
+
+ for (vector<const char*>::iterator i = dot_actions.begin(); i != dot_actions.end(); ++i) {
+
+ act = myactions.find_action (*i);
+
+ if (act) {
+ ract = RefPtr<RadioAction>::cast_dynamic (act);
+
+ if (ract) {
+ if (ract->property_value() == val) {
+ ract->set_active (true);
+ inconsistent = false;
+ break;
+ }
+ }
+ }
+ }
+
+ dot1_button.set_inconsistent (inconsistent);
+ dot2_button.set_inconsistent (inconsistent);
+ dot3_button.set_inconsistent (inconsistent);
+
+ se->set_step_edit_cursor_width (note_length());
+}
+
+void
+StepEntry::program_click ()
+{
+ se->step_add_program_change (note_channel(), (int8_t) floor (program_adjustment.get_value()));
+}
+
+void
+StepEntry::bank_click ()
+{
+ se->step_add_bank_change (note_channel(), (int8_t) floor (bank_adjustment.get_value()));
+}
+
+void
+StepEntry::insert_rest ()
+{
+ se->step_edit_rest (note_length());
+}
+
+void
+StepEntry::insert_grid_rest ()
+{
+ se->step_edit_rest (Evoral::Beats());
+}
+
+void
+StepEntry::insert_note (uint8_t note)
+{
+ if (note > 127) {
+ return;
+ }
+
+ se->step_add_note (note_channel(), note, note_velocity(), note_length());
+}
+void
+StepEntry::insert_c ()
+{
+ insert_note (0 + (current_octave() * 12));
+}
+void
+StepEntry::insert_csharp ()
+{
+ insert_note (1 + (current_octave() * 12));
+}
+void
+StepEntry::insert_d ()
+{
+ insert_note (2 + (current_octave() * 12));
+}
+void
+StepEntry::insert_dsharp ()
+{
+ insert_note (3 + (current_octave() * 12));
+}
+void
+StepEntry::insert_e ()
+{
+ insert_note (4 + (current_octave() * 12));
+}
+void
+StepEntry::insert_f ()
+{
+ insert_note (5 + (current_octave() * 12));
+}
+void
+StepEntry::insert_fsharp ()
+{
+ insert_note (6 + (current_octave() * 12));
+}
+void
+StepEntry::insert_g ()
+{
+ insert_note (7 + (current_octave() * 12));
+}
+void
+StepEntry::insert_gsharp ()
+{
+ insert_note (8 + (current_octave() * 12));
+}
+
+void
+StepEntry::insert_a ()
+{
+ insert_note (9 + (current_octave() * 12));
+}
+
+void
+StepEntry::insert_asharp ()
+{
+ insert_note (10 + (current_octave() * 12));
+}
+void
+StepEntry::insert_b ()
+{
+ insert_note (11 + (current_octave() * 12));
+}
+
+void
+StepEntry::note_length_change (GtkAction* act)
+{
+ /* it doesn't matter which note length action we look up - we are interested
+ in the current_value which is global across the whole group of note length
+ actions. this method is called twice for every user operation,
+ once for the action that became "inactive" and once for the action that
+ becaome "active". so ... only bother to actually change the value when this
+ is called for the "active" action.
+ */
+
+ if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION(act))) {
+ gint v = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (act));
+ length_divisor_adjustment.set_value (v);
+ }
+}
+
+void
+StepEntry::note_velocity_change (GtkAction* act)
+{
+ /* it doesn't matter which note length action we look up - we are interested
+ in the current_value which is global across the whole group of note length
+ actions. this method is called twice for every user operation,
+ once for the action that became "inactive" and once for the action that
+ becaome "active". so ... only bother to actually change the value when this
+ is called for the "active" action.
+ */
+
+ if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION(act))) {
+ gint v = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (act));
+ velocity_adjustment.set_value (v);
+ }
+}
+
+void
+StepEntry::velocity_value_change ()
+{
+ RefPtr<Action> act;
+ RefPtr<RadioAction> ract;
+ double val = velocity_adjustment.get_value();
+ bool inconsistent = true;
+ vector<const char*> velocity_actions;
+
+ velocity_actions.push_back ("StepEditing/note-velocity-ppp");
+ velocity_actions.push_back ("StepEditing/note-velocity-pp");
+ velocity_actions.push_back ("StepEditing/note-velocity-p");
+ velocity_actions.push_back ("StepEditing/note-velocity-mp");
+ velocity_actions.push_back ("StepEditing/note-velocity-mf");
+ velocity_actions.push_back ("StepEditing/note-velocity-f");
+ velocity_actions.push_back ("StepEditing/note-velocity-ff");
+ velocity_actions.push_back ("StepEditing/note-velocity-fff");
+
+ for (vector<const char*>::iterator i = velocity_actions.begin(); i != velocity_actions.end(); ++i) {
+
+ act = myactions.find_action (*i);
+
+ if (act) {
+ ract = RefPtr<RadioAction>::cast_dynamic (act);
+
+ if (ract) {
+ if (ract->property_value() == val) {
+ ract->set_active (true);
+ inconsistent = false;
+ break;
+ }
+ }
+ }
+ }
+
+ velocity_ppp_button.set_inconsistent (inconsistent);
+ velocity_pp_button.set_inconsistent (inconsistent);
+ velocity_p_button.set_inconsistent (inconsistent);
+ velocity_mp_button.set_inconsistent (inconsistent);
+ velocity_mf_button.set_inconsistent (inconsistent);
+ velocity_f_button.set_inconsistent (inconsistent);
+ velocity_ff_button.set_inconsistent (inconsistent);
+ velocity_fff_button.set_inconsistent (inconsistent);
+}
+
+void
+StepEntry::length_value_change ()
+{
+ RefPtr<Action> act;
+ RefPtr<RadioAction> ract;
+ double val = length_divisor_adjustment.get_value();
+ bool inconsistent = true;
+ vector<const char*> length_actions;
+
+ length_actions.push_back ("StepEditing/note-length-whole");
+ length_actions.push_back ("StepEditing/note-length-half");
+ length_actions.push_back ("StepEditing/note-length-quarter");
+ length_actions.push_back ("StepEditing/note-length-eighth");
+ length_actions.push_back ("StepEditing/note-length-sixteenth");
+ length_actions.push_back ("StepEditing/note-length-thirtysecond");
+ length_actions.push_back ("StepEditing/note-length-sixtyfourth");
+
+ for (vector<const char*>::iterator i = length_actions.begin(); i != length_actions.end(); ++i) {
+
+ act = myactions.find_action (*i);
+
+ if (act) {
+ ract = RefPtr<RadioAction>::cast_dynamic (act);
+
+ if (ract) {
+ if (ract->property_value() == val) {
+ ract->set_active (true);
+ inconsistent = false;
+ break;
+ }
+ }
+ }
+ }
+
+ length_1_button.set_inconsistent (inconsistent);
+ length_2_button.set_inconsistent (inconsistent);
+ length_4_button.set_inconsistent (inconsistent);
+ length_8_button.set_inconsistent (inconsistent);
+ length_16_button.set_inconsistent (inconsistent);
+ length_32_button.set_inconsistent (inconsistent);
+ length_64_button.set_inconsistent (inconsistent);
+
+ se->set_step_edit_cursor_width (note_length());
+}
+
+bool
+StepEntry::radio_button_press (GdkEventButton* ev)
+{
+ if (ev->button == 1) {
+ return true;
+ }
+
+ return false;
+}
+
+bool
+StepEntry::radio_button_release (GdkEventButton* ev, RadioButton* btn, int v)
+{
+ if (ev->button == 1) {
+ GtkAction* act = gtk_activatable_get_related_action (GTK_ACTIVATABLE (btn->gobj()));
+
+ if (act) {
+ gtk_radio_action_set_current_value (GTK_RADIO_ACTION(act), v);
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
+void
+StepEntry::next_octave ()
+{
+ octave_adjustment.set_value (octave_adjustment.get_value() + 1.0);
+}
+
+void
+StepEntry::prev_octave ()
+{
+ octave_adjustment.set_value (octave_adjustment.get_value() - 1.0);
+}
+
+void
+StepEntry::inc_note_length ()
+{
+ length_divisor_adjustment.set_value (length_divisor_adjustment.get_value() - 1.0);
+}
+
+void
+StepEntry::dec_note_length ()
+{
+ length_divisor_adjustment.set_value (length_divisor_adjustment.get_value() + 1.0);
+}
+
+void
+StepEntry::prev_note_length ()
+{
+ double l = length_divisor_adjustment.get_value();
+ int il = (int) lrintf (l); // round to nearest integer
+ il = (il/2) * 2; // round to power of 2
+
+ if (il == 0) {
+ il = 1;
+ }
+
+ il *= 2; // double
+
+ length_divisor_adjustment.set_value (il);
+}
+
+void
+StepEntry::next_note_length ()
+{
+ double l = length_divisor_adjustment.get_value();
+ int il = (int) lrintf (l); // round to nearest integer
+ il = (il/2) * 2; // round to power of 2
+
+ if (il == 0) {
+ il = 1;
+ }
+
+ il /= 2; // half
+
+ if (il > 0) {
+ length_divisor_adjustment.set_value (il);
+ }
+}
+
+void
+StepEntry::inc_note_velocity ()
+{
+ velocity_adjustment.set_value (velocity_adjustment.get_value() + 1.0);
+}
+
+void
+StepEntry::dec_note_velocity ()
+{
+ velocity_adjustment.set_value (velocity_adjustment.get_value() - 1.0);
+}
+
+void
+StepEntry::next_note_velocity ()
+{
+ double l = velocity_adjustment.get_value ();
+
+ if (l < 16) {
+ l = 16;
+ } else if (l < 32) {
+ l = 32;
+ } else if (l < 48) {
+ l = 48;
+ } else if (l < 64) {
+ l = 64;
+ } else if (l < 80) {
+ l = 80;
+ } else if (l < 96) {
+ l = 96;
+ } else if (l < 112) {
+ l = 112;
+ } else if (l < 127) {
+ l = 127;
+ }
+
+ velocity_adjustment.set_value (l);
+}
+
+void
+StepEntry::prev_note_velocity ()
+{
+ double l = velocity_adjustment.get_value ();
+
+ if (l > 112) {
+ l = 112;
+ } else if (l > 96) {
+ l = 96;
+ } else if (l > 80) {
+ l = 80;
+ } else if (l > 64) {
+ l = 64;
+ } else if (l > 48) {
+ l = 48;
+ } else if (l > 32) {
+ l = 32;
+ } else if (l > 16) {
+ l = 16;