X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fstep_entry.cc;h=fd53fd55ff3704fb912c8514ab9a8f644389387a;hb=82be348d429b97f3e223b3a5b1c6807d23fcdaa0;hp=011fadc3c49025f16e49aa611a0b693f31a47c16;hpb=aac46a38fbd3b979dd1d352a4d1454ac8a70793f;p=ardour.git diff --git a/gtk2_ardour/step_entry.cc b/gtk2_ardour/step_entry.cc index 011fadc3c4..fd53fd55ff 100644 --- a/gtk2_ardour/step_entry.cc +++ b/gtk2_ardour/step_entry.cc @@ -19,7 +19,6 @@ #include -#include "pbd/filesystem.h" #include "pbd/file_utils.h" #include "gtkmm2ext/keyboard.h" @@ -31,6 +30,7 @@ #include "ardour_ui.h" #include "midi_channel_selector.h" #include "midi_time_axis.h" +#include "step_editor.h" #include "step_entry.h" #include "utils.h" @@ -44,30 +44,33 @@ using namespace PBD; using namespace ARDOUR; static void -_note_off_event_handler (GtkWidget* widget, int note, gpointer arg) +_note_off_event_handler (GtkWidget* /*widget*/, int note, gpointer arg) { ((StepEntry*)arg)->note_off_event_handler (note); } static void -_rest_event_handler (GtkWidget* widget, gpointer arg) +_rest_event_handler (GtkWidget* /*widget*/, gpointer arg) { ((StepEntry*)arg)->rest_event_handler (); } -StepEntry::StepEntry (MidiTimeAxisView& mtv) - : ArdourDialog (string_compose (_("Step Entry: %1"), mtv.name())) +StepEntry::StepEntry (StepEditor& seditor) + : ArdourWindow (string_compose (_("Step Entry: %1"), seditor.name())) , _current_note_length (1.0) , _current_note_velocity (64) , triplet_button ("3") + , dot_adjustment (0.0, 0.0, 3.0, 1.0, 1.0) , beat_resync_button (_(">beat")) , bar_resync_button (_(">bar")) + , resync_button (_(">EP")) , sustain_button (_("sustain")) , rest_button (_("rest")) , grid_rest_button (_("g-rest")) - , channel_adjustment (1, 1, 16, 1, 4) + , back_button (_("back")) + , channel_adjustment (1, 1, 16, 1, 4) , channel_spinner (channel_adjustment) - , octave_adjustment (4, 1, 11, 1, 4) // start in octave 4 + , octave_adjustment (4, 0, 10, 1, 4) // start in octave 4 , octave_spinner (octave_adjustment) , length_divisor_adjustment (1.0, 1.0, 128, 1.0, 4.0) , length_divisor_spinner (length_divisor_adjustment) @@ -81,18 +84,19 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) , program_button (_("+")) , _piano (0) , piano (0) - , _mtv (&mtv) + , se (&seditor) { register_actions (); load_bindings (); +#if 0 /* set channel selector to first selected channel. if none are selected, it will remain at the value set in its constructor, above (1) */ - uint16_t chn_mask = _mtv->channel_selector().get_selected_channels(); - + uint16_t chn_mask = se->channel_selector().get_selected_channels(); + for (uint32_t i = 0; i < 16; ++i) { if (chn_mask & (1<set_markup ("-"); + l->show (); + dot0_button.add (*l); + + l = manage (new Label); l->set_markup ("."); l->show (); - dot_button.add (*l); + dot1_button.add (*l); + + l = manage (new Label); + l->set_markup (".."); + l->show (); + dot2_button.add (*l); + + l = manage (new Label); + l->set_markup ("..."); + l->show (); + dot3_button.add (*l); w = manage (new Image (::get_icon (X_("chord")))); w->show(); chord_button.add (*w); + dot_box1.pack_start (dot0_button, true, false); + dot_box1.pack_start (dot1_button, true, false); + dot_box2.pack_start (dot2_button, true, false); + dot_box2.pack_start (dot3_button, true, false); + rest_box.pack_start (rest_button, true, false); rest_box.pack_start (grid_rest_button, true, false); + rest_box.pack_start (back_button, true, false); resync_box.pack_start (beat_resync_button, true, false); resync_box.pack_start (bar_resync_button, true, false); + resync_box.pack_start (resync_button, true, false); ARDOUR_UI::instance()->set_tip (&chord_button, _("Stack inserted notes to form a chord"), ""); ARDOUR_UI::instance()->set_tip (&sustain_button, _("Extend selected notes by note length"), ""); - ARDOUR_UI::instance()->set_tip (&dot_button, _("Use dotted note lengths"), ""); + ARDOUR_UI::instance()->set_tip (&dot0_button, _("Use undotted note lengths"), ""); + ARDOUR_UI::instance()->set_tip (&dot1_button, _("Use dotted (* 1.5) note lengths"), ""); + ARDOUR_UI::instance()->set_tip (&dot2_button, _("Use double-dotted (* 1.75) note lengths"), ""); + ARDOUR_UI::instance()->set_tip (&dot3_button, _("Use triple-dotted (* 1.875) note lengths"), ""); ARDOUR_UI::instance()->set_tip (&rest_button, _("Insert a note-length's rest"), ""); ARDOUR_UI::instance()->set_tip (&grid_rest_button, _("Insert a grid-unit's rest"), ""); ARDOUR_UI::instance()->set_tip (&beat_resync_button, _("Insert a rest until the next beat"), ""); ARDOUR_UI::instance()->set_tip (&bar_resync_button, _("Insert a rest until the next bar"), ""); ARDOUR_UI::instance()->set_tip (&bank_button, _("Insert a bank change message"), ""); ARDOUR_UI::instance()->set_tip (&program_button, _("Insert a program change message"), ""); - + ARDOUR_UI::instance()->set_tip (&back_button, _("Move Insert Position Back by Note Length"), ""); + ARDOUR_UI::instance()->set_tip (&resync_button, _("Move Insert Position to Edit Point"), ""); + + act = myactions.find_action ("StepEditing/back"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (back_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (back_button.gobj()), act->gobj()); + act = myactions.find_action ("StepEditing/sync-to-edit-point"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (resync_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (resync_button.gobj()), act->gobj()); act = myactions.find_action ("StepEditing/toggle-triplet"); gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (triplet_button.gobj()), false); gtk_activatable_set_related_action (GTK_ACTIVATABLE (triplet_button.gobj()), act->gobj()); + act = myactions.find_action ("StepEditing/no-dotted"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dot0_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (dot0_button.gobj()), act->gobj()); act = myactions.find_action ("StepEditing/toggle-dotted"); - gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dot_button.gobj()), false); - gtk_activatable_set_related_action (GTK_ACTIVATABLE (dot_button.gobj()), act->gobj()); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dot1_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (dot1_button.gobj()), act->gobj()); + act = myactions.find_action ("StepEditing/toggle-double-dotted"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dot2_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (dot2_button.gobj()), act->gobj()); + act = myactions.find_action ("StepEditing/toggle-triple-dotted"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (dot3_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (dot3_button.gobj()), act->gobj()); act = myactions.find_action ("StepEditing/toggle-chord"); gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (chord_button.gobj()), false); gtk_activatable_set_related_action (GTK_ACTIVATABLE (chord_button.gobj()), act->gobj()); @@ -327,12 +375,13 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) act = myactions.find_action ("StepEditing/sustain"); gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (sustain_button.gobj()), false); gtk_activatable_set_related_action (GTK_ACTIVATABLE (sustain_button.gobj()), act->gobj()); - + upper_box.set_spacing (6); upper_box.pack_start (chord_button, false, false); upper_box.pack_start (note_length_box, false, false, 12); upper_box.pack_start (triplet_button, false, false); - upper_box.pack_start (dot_button, false, false); + upper_box.pack_start (dot_box1, false, false); + upper_box.pack_start (dot_box2, false, false); upper_box.pack_start (sustain_button, false, false); upper_box.pack_start (rest_box, false, false); upper_box.pack_start (resync_box, false, false); @@ -386,6 +435,7 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) velocity_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &StepEntry::velocity_value_change)); length_divisor_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &StepEntry::length_value_change)); + dot_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &StepEntry::dot_value_change)); _piano = (PianoKeyboard*) piano_keyboard_new (); piano = wrap ((GtkWidget*) _piano); @@ -394,7 +444,7 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) g_signal_connect(G_OBJECT(_piano), "note-off", G_CALLBACK(_note_off_event_handler), this); g_signal_connect(G_OBJECT(_piano), "rest", G_CALLBACK(_rest_event_handler), this); - + program_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::program_click)); bank_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::bank_click)); beat_resync_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::beat_resync_click)); @@ -407,7 +457,19 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) packer.pack_start (*piano, false, false); packer.show_all (); - get_vbox()->add (packer); + add (packer); + + /* initial settings: quarter note and mezzo forte */ + + act = myactions.find_action ("StepEditing/note-length-quarter"); + RefPtr r = RefPtr::cast_dynamic (act); + assert (r); + r->set_active (true); + + act = myactions.find_action ("StepEditing/note-velocity-mf"); + r = RefPtr::cast_dynamic (act); + assert (r); + r->set_active (true); } StepEntry::~StepEntry() @@ -432,11 +494,11 @@ StepEntry::on_key_press_event (GdkEventKey* ev) /* focus widget gets first shot, then bindings, otherwise forward to main window */ - + if (!gtk_window_propagate_key_event (GTK_WINDOW(gobj()), ev)) { KeyboardKey k (ev->state, ev->keyval); - if (bindings.activate (k, KeyboardKey::Press)) { + if (bindings.activate (k, Bindings::Press)) { return true; } } @@ -450,11 +512,11 @@ StepEntry::on_key_release_event (GdkEventKey* ev) if (!gtk_window_propagate_key_event (GTK_WINDOW(gobj()), ev)) { KeyboardKey k (ev->state, ev->keyval); - if (bindings.activate (k, KeyboardKey::Release)) { + if (bindings.activate (k, Bindings::Release)) { return true; } } - + /* don't forward releases */ return true; @@ -463,28 +525,27 @@ StepEntry::on_key_release_event (GdkEventKey* ev) void StepEntry::rest_event_handler () { - _mtv->step_edit_rest (0.0); + se->step_edit_rest (0.0); } Evoral::MusicalTime StepEntry::note_length () { - Evoral::MusicalTime base_time = 1.0 / (Evoral::MusicalTime) length_divisor_adjustment.get_value(); - + Evoral::MusicalTime base_time = 4.0 / (Evoral::MusicalTime) length_divisor_adjustment.get_value(); + RefPtr act = myactions.find_action ("StepEditing/toggle-triplet"); RefPtr tact = RefPtr::cast_dynamic (act); bool triplets = tact->get_active (); - act = myactions.find_action ("StepEditing/toggle-dotted"); - tact = RefPtr::cast_dynamic (act); - bool dotted = tact->get_active (); - if (triplets) { base_time *= (2.0/3.0); } - if (dotted) { - base_time *= 1.5; // add support for multiple dots sometime + double dots = dot_adjustment.get_value (); + + if (dots > 0) { + dots = pow (2.0, dots); + base_time *= 1 + ((dots - 1.0)/dots); } return base_time; @@ -496,7 +557,7 @@ StepEntry::note_velocity () const return (Evoral::MusicalTime) velocity_adjustment.get_value(); } -uint8_t +uint8_t StepEntry::note_channel() const { return channel_adjustment.get_value() - 1; @@ -512,20 +573,20 @@ StepEntry::note_off_event_handler (int note) void StepEntry::on_show () { - ArdourDialog::on_show (); + ArdourWindow::on_show (); //piano->grab_focus (); } void StepEntry::beat_resync_click () { - _mtv->step_edit_beat_sync (); + se->step_edit_beat_sync (); } void StepEntry::bar_resync_click () { - _mtv->step_edit_bar_sync (); + se->step_edit_bar_sync (); } void @@ -576,13 +637,14 @@ StepEntry::register_actions () myactions.register_action ("StepEditing", "octave-9", _("Switch to the 10th octave"), sigc::mem_fun (*this, &StepEntry::octave_9)); myactions.register_action ("StepEditing", "octave-10", _("Switch to the 11th octave"), sigc::mem_fun (*this, &StepEntry::octave_10)); - RadioAction::Group note_length_group; - myactions.register_radio_action ("StepEditing", note_length_group, "note-length-whole", + myactions.register_radio_action ("StepEditing", note_length_group, "note-length-whole", _("Set Note Length to Whole"), sigc::mem_fun (*this, &StepEntry::note_length_change), 1); - myactions.register_radio_action ("StepEditing", note_length_group, "note-length-half", + myactions.register_radio_action ("StepEditing", 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 ("StepEditing", 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 ("StepEditing", 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 ("StepEditing", note_length_group, "note-length-eighth", @@ -614,77 +676,135 @@ StepEntry::register_actions () _("Set Note Velocity to Fortississimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 127); myactions.register_toggle_action ("StepEditing", "toggle-triplet", _("Toggle Triple Notes"), - sigc::mem_fun (*this, &StepEntry::toggle_dotted)); - myactions.register_toggle_action ("StepEditing", "toggle-dotted", _("Toggled Dotted Notes"), sigc::mem_fun (*this, &StepEntry::toggle_triplet)); + + RadioAction::Group dot_group; + + myactions.register_radio_action ("StepEditing", dot_group, "no-dotted", _("No Dotted Notes"), + sigc::mem_fun (*this, &StepEntry::dot_change), 0); + myactions.register_radio_action ("StepEditing", dot_group, "toggle-dotted", _("Toggled Dotted Notes"), + sigc::mem_fun (*this, &StepEntry::dot_change), 1); + myactions.register_radio_action ("StepEditing", dot_group, "toggle-double-dotted", _("Toggled Double-Dotted Notes"), + sigc::mem_fun (*this, &StepEntry::dot_change), 2); + myactions.register_radio_action ("StepEditing", dot_group, "toggle-triple-dotted", _("Toggled Triple-Dotted Notes"), + sigc::mem_fun (*this, &StepEntry::dot_change), 3); + myactions.register_toggle_action ("StepEditing", "toggle-chord", _("Toggle Chord Entry"), sigc::mem_fun (*this, &StepEntry::toggle_chord)); myactions.register_action ("StepEditing", "sustain", _("Sustain Selected Notes by Note Length"), sigc::mem_fun (*this, &StepEntry::do_sustain)); + + myactions.register_action ("StepEditing", "sync-to-edit-point", _("Move Insert Position to Edit Point"), + sigc::mem_fun (*this, &StepEntry::sync_to_edit_point)); + myactions.register_action ("StepEditing", "back", _("Move Insert Position Back by Note Length"), + sigc::mem_fun (*this, &StepEntry::back)); } void StepEntry::load_bindings () { /* XXX move this to a better place */ - KeyboardKey::set_ignored_state (GDK_LOCK_MASK|GDK_MOD2_MASK|GDK_MOD3_MASK); bindings.set_action_map (myactions); - sys::path binding_file; - SearchPath spath = ardour_search_path() + user_config_directory() + system_config_search_path(); + std::string binding_file; - if (find_file_in_search_path (spath, "step_editing.bindings", binding_file)) { - bindings.load (binding_file.to_string()); + if (find_file_in_search_path (ardour_config_search_path(), "step_editing.bindings", binding_file)) { + bindings.load (binding_file); } } void StepEntry::toggle_triplet () { - // nowt to be done + se->set_step_edit_cursor_width (note_length()); } void StepEntry::toggle_chord () { - _mtv->step_edit_toggle_chord (); + se->step_edit_toggle_chord (); } void -StepEntry::toggle_dotted () +StepEntry::dot_change (GtkAction* act) { - // nowt to be done + 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 act; + RefPtr ract; + double val = dot_adjustment.get_value(); + bool inconsistent = true; + vector 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::iterator i = dot_actions.begin(); i != dot_actions.end(); ++i) { + + act = myactions.find_action (*i); + + if (act) { + ract = RefPtr::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 () { - _mtv->step_add_program_change (note_channel(), (int8_t) floor (program_adjustment.get_value())); + se->step_add_program_change (note_channel(), (int8_t) floor (program_adjustment.get_value())); } void StepEntry::bank_click () { - _mtv->step_add_bank_change (note_channel(), (int8_t) floor (bank_adjustment.get_value())); + se->step_add_bank_change (note_channel(), (int8_t) floor (bank_adjustment.get_value())); } void StepEntry::insert_rest () { - _mtv->step_edit_rest (note_length()); + se->step_edit_rest (note_length()); } void StepEntry::insert_grid_rest () { - _mtv->step_edit_rest (0.0); + se->step_edit_rest (0.0); } void StepEntry::insert_note (uint8_t note) { - _mtv->step_add_note (note_channel(), note, note_velocity(), note_length()); + if (note > 127) { + return; + } + + se->step_add_note (note_channel(), note, note_velocity(), note_length()); } void StepEntry::insert_c () @@ -759,7 +879,7 @@ StepEntry::note_length_change (GtkAction* act) 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); @@ -776,7 +896,7 @@ StepEntry::note_velocity_change (GtkAction* act) 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); @@ -804,11 +924,11 @@ StepEntry::velocity_value_change () for (vector::iterator i = velocity_actions.begin(); i != velocity_actions.end(); ++i) { act = myactions.find_action (*i); - + if (act) { ract = RefPtr::cast_dynamic (act); - if (ract) { + if (ract) { if (ract->property_value() == val) { ract->set_active (true); inconsistent = false; @@ -848,11 +968,11 @@ StepEntry::length_value_change () for (vector::iterator i = length_actions.begin(); i != length_actions.end(); ++i) { act = myactions.find_action (*i); - + if (act) { ract = RefPtr::cast_dynamic (act); - if (ract) { + if (ract) { if (ract->property_value() == val) { ract->set_active (true); inconsistent = false; @@ -870,7 +990,7 @@ StepEntry::length_value_change () length_32_button.set_inconsistent (inconsistent); length_64_button.set_inconsistent (inconsistent); - _mtv->set_step_edit_cursor_width (note_length()); + se->set_step_edit_cursor_width (note_length()); } bool @@ -878,7 +998,7 @@ StepEntry::radio_button_press (GdkEventButton* ev) { if (ev->button == 1) { return true; - } + } return false; } @@ -888,13 +1008,13 @@ 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; } @@ -991,7 +1111,7 @@ StepEntry::next_note_velocity () } else if (l < 127) { l = 127; } - + velocity_adjustment.set_value (l); } @@ -1017,7 +1137,7 @@ StepEntry::prev_note_velocity () } else { l = 1; } - + velocity_adjustment.set_value (l); } @@ -1030,5 +1150,17 @@ StepEntry::octave_n (int n) void StepEntry::do_sustain () { - _mtv->step_edit_sustain (note_length()); + se->step_edit_sustain (note_length()); +} + +void +StepEntry::back () +{ + se->move_step_edit_beat_pos (-note_length()); +} + +void +StepEntry::sync_to_edit_point () +{ + se->resync_step_edit_to_edit_point (); }