diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-08-12 21:02:01 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-08-12 21:02:01 +0000 |
commit | 9196535878dfe2a6eb7bde909b0b2312ade8ad29 (patch) | |
tree | 96ff27d4f43a23fce93b30781e9957eb7ce457ab /gtk2_ardour | |
parent | eee61a9f9bf297d454e07bd2e2b9d3d1824b8272 (diff) |
lotsa keybindings for nearly everything in the step editor
git-svn-id: svn://localhost/ardour2/branches/3.0@7610 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r-- | gtk2_ardour/midi_time_axis.cc | 21 | ||||
-rw-r--r-- | gtk2_ardour/step_editing.bindings | 57 | ||||
-rw-r--r-- | gtk2_ardour/step_entry.cc | 279 | ||||
-rw-r--r-- | gtk2_ardour/step_entry.h | 39 |
4 files changed, 338 insertions, 58 deletions
diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc index 1fddbe1f08..e62bd6223c 100644 --- a/gtk2_ardour/midi_time_axis.cc +++ b/gtk2_ardour/midi_time_axis.cc @@ -922,7 +922,12 @@ MidiTimeAxisView::start_step_editing () framecnt_t frames_from_start = _editor.get_preferred_edit_position() - step_edit_region->position(); - assert (frames_from_start >= 0); + if (frames_from_start < 0) { + /* this can happen with snap enabled, and the edit point == Playhead. we snap the + position of the new region, and it can end up after the edit point. + */ + frames_from_start = 0; + } step_edit_beat_pos = step_edit_region_view->frames_to_beats (frames_from_start); @@ -1097,6 +1102,8 @@ MidiTimeAxisView::step_edit_toggle_chord () _step_edit_triplet_countdown = 0; _step_edit_within_chord = true; } + + cerr << "Within chord now: " << _step_edit_within_chord << endl; } void @@ -1130,7 +1137,7 @@ MidiTimeAxisView::step_edit_bar_sync () return; } - nframes64_t fpos = step_edit_region->position() + + framepos_t fpos = step_edit_region->position() + step_edit_region_view->beats_to_frames (step_edit_beat_pos); fpos = _session->tempo_map().round_to_bar (fpos, 1); step_edit_beat_pos = ceil (step_edit_region_view->frames_to_beats (fpos - step_edit_region->position())); @@ -1145,11 +1152,9 @@ MidiTimeAxisView::add_region (framepos_t pos) real_editor->begin_reversible_command (_("create region")); playlist()->clear_history (); - framepos_t start = pos; - real_editor->snap_to (start, 0); - cerr << "Snap backwards from " << pos << " gave us " << start << endl; - const Meter& m = _session->tempo_map().meter_at(start); - const Tempo& t = _session->tempo_map().tempo_at(start); + real_editor->snap_to (pos, 0); + const Meter& m = _session->tempo_map().meter_at(pos); + const Tempo& t = _session->tempo_map().tempo_at(pos); double length = floor (m.frames_per_bar(t, _session->frame_rate())); boost::shared_ptr<Source> src = _session->create_midi_source_for_session (view()->trackview().track().get(), @@ -1162,7 +1167,7 @@ MidiTimeAxisView::add_region (framepos_t pos) boost::shared_ptr<Region> region = (RegionFactory::create (src, plist)); - playlist()->add_region (region, start); + playlist()->add_region (region, pos); _session->add_command (new StatefulDiffCommand (playlist())); real_editor->commit_reversible_command(); diff --git a/gtk2_ardour/step_editing.bindings b/gtk2_ardour/step_editing.bindings index d7e8df14b1..59a3b2e4d6 100644 --- a/gtk2_ardour/step_editing.bindings +++ b/gtk2_ardour/step_editing.bindings @@ -1,7 +1,58 @@ <?xml version="1.0" encoding="UTF-8"?> -<Bindings name="qwerty"> +<Bindings name="logic"> <Press> - <Binding key="a" action="StepEditing/insert-a"/> - <Binding key="Primary-a" action="StepEditing/insert-b"/> + <Binding key="1" action="StepEditing/octave-0"/> + <Binding key="2" action="StepEditing/octave-1"/> + <Binding key="3" action="StepEditing/octave-2"/> + <Binding key="4" action="StepEditing/octave-3"/> + <Binding key="5" action="StepEditing/octave-4"/> + <Binding key="6" action="StepEditing/octave-5"/> + <Binding key="7" action="StepEditing/octave-6"/> + <Binding key="8" action="StepEditing/octave-7"/> + <Binding key="9" action="StepEditing/octave-8"/> + <Binding key="0" action="StepEditing/octave-9"/> + <Binding key="Minus" action="StepEditing/octave-10"/> + + <Binding key="F1" action="StepEditing/note-length-whole"/> + <Binding key="F2" action="StepEditing/note-length-half"/> + <Binding key="F3" action="StepEditing/note-length-quarter"/> + <Binding key="F4" action="StepEditing/note-length-eighth"/> + <Binding key="F5" action="StepEditing/note-length-sixteenth"/> + <Binding key="F6" action="StepEditing/note-length-thirtysecond"/> + <Binding key="F7" action="StepEditing/note-length-sixtyfourth"/> + + <Binding key="a" action="StepEditing/insert-c"/> + <Binding key="w" action="StepEditing/insert-csharp"/> + <Binding key="s" action="StepEditing/insert-d"/> + <Binding key="e" action="StepEditing/insert-dsharp"/> + <Binding key="d" action="StepEditing/insert-e"/> + <Binding key="f" action="StepEditing/insert-f"/> + <Binding key="t" action="StepEditing/insert-fsharp"/> + <Binding key="g" action="StepEditing/insert-g"/> + <Binding key="y" action="StepEditing/insert-gsharp"/> + <Binding key="h" action="StepEditing/insert-a"/> + <Binding key="j" action="StepEditing/insert-asharp"/> + <Binding key="k" action="StepEditing/insert-b"/> + + <Binding key="Tab" action="StepEditing/insert-rest"/> + <Binding key="Primary-Tab" action="StepEditing/insert-snap-rest"/> + + <Binding key="x" action="StepEditing/note-velocity-ppp"/> + <Binding key="c" action="StepEditing/note-velocity-pp"/> + <Binding key="v" action="StepEditing/note-velocity-p"/> + <Binding key="b" action="StepEditing/note-velocity-mp"/> + <Binding key="n" action="StepEditing/note-velocity-mf"/> + <Binding key="m" action="StepEditing/note-velocity-f"/> + <Binding key="comma" action="StepEditing/note-velocity-ff"/> + <Binding key="slash" action="StepEditing/note-velocity-fff"/> + + <Binding key="Up" action="StepEditing/next-note-velocity"/> + <Binding key="Down" action="StepEditing/prev-note-velocity"/> + <Binding key="Primary-Up" action="StepEditing/next-note-length"/> + <Binding key="Primary-Down" action="StepEditing/prev-note-length"/> + + <Binding key="apostrophe" action="StepEditing/toggle-triplet"/> + <Binding key="period" action="StepEditing/toggle-dotted"/> + <Binding key="bar" action="StepEditing/toggle-chord"/> </Press> </Bindings> diff --git a/gtk2_ardour/step_entry.cc b/gtk2_ardour/step_entry.cc index 7787ec006d..7481565363 100644 --- a/gtk2_ardour/step_entry.cc +++ b/gtk2_ardour/step_entry.cc @@ -67,7 +67,7 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) , grid_rest_button (_("g-rest")) , channel_adjustment (1, 1, 16, 1, 4) , channel_spinner (channel_adjustment) - , octave_adjustment (0, 1, 11, 1, 4) + , octave_adjustment (4, 1, 11, 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) @@ -309,6 +309,25 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) ARDOUR_UI::instance()->set_tip (&bank_button, _("Insert a bank change message"), ""); ARDOUR_UI::instance()->set_tip (&program_button, _("Insert a program change message"), ""); + 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/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()); + 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()); + act = myactions.find_action ("StepEditing/insert-rest"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (rest_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (rest_button.gobj()), act->gobj()); + act = myactions.find_action ("StepEditing/insert-snap-rest"); + gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (grid_rest_button.gobj()), false); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (grid_rest_button.gobj()), act->gobj()); + 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); @@ -378,10 +397,6 @@ StepEntry::StepEntry (MidiTimeAxisView& mtv) program_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::program_click)); bank_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::bank_click)); - rest_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::rest_click)); - grid_rest_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::grid_rest_click)); - chord_button.signal_toggled().connect (sigc::mem_fun (*this, &StepEntry::chord_toggled)); - triplet_button.signal_toggled().connect (sigc::mem_fun (*this, &StepEntry::triplet_toggled)); beat_resync_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::beat_resync_click)); bar_resync_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::bar_resync_click)); @@ -432,10 +447,6 @@ StepEntry::on_key_press_event (GdkEventKey* ev) bool StepEntry::on_key_release_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); @@ -443,8 +454,10 @@ StepEntry::on_key_release_event (GdkEventKey* ev) return true; } } + + /* don't forward releases */ - return forward_key_press (ev); + return true; } void @@ -454,9 +467,27 @@ StepEntry::rest_event_handler () } Evoral::MusicalTime -StepEntry::note_length () const +StepEntry::note_length () { - return 1.0 / (Evoral::MusicalTime) length_divisor_adjustment.get_value(); + Evoral::MusicalTime base_time = 1.0 / (Evoral::MusicalTime) length_divisor_adjustment.get_value(); + + RefPtr<Action> act = myactions.find_action ("StepEditing/toggle-triplet"); + RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act); + bool triplets = tact->get_active (); + + act = myactions.find_action ("StepEditing/toggle-dotted"); + tact = RefPtr<ToggleAction>::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 + } + + return base_time; } uint8_t @@ -477,39 +508,12 @@ StepEntry::note_off_event_handler (int note) insert_note (note); } -void -StepEntry::rest_click () -{ - insert_rest (); -} - -void -StepEntry::grid_rest_click () -{ - insert_grid_rest (); -} - -void -StepEntry::triplet_toggled () -{ - if (triplet_button.get_active () != _mtv->step_edit_within_triplet()) { - _mtv->step_edit_toggle_triplet (); - } -} - -void -StepEntry::chord_toggled () -{ - if (chord_button.get_active() != _mtv->step_edit_within_chord ()) { - _mtv->step_edit_toggle_chord (); - } -} void StepEntry::on_show () { ArdourDialog::on_show (); - piano->grab_focus (); + //piano->grab_focus (); } void @@ -542,6 +546,37 @@ StepEntry::register_actions () myactions.register_action ("StepEditing", "insert-g", _("Insert Note G"), sigc::mem_fun (*this, &StepEntry::insert_g)); myactions.register_action ("StepEditing", "insert-gsharp", _("Insert Note G-sharp"), sigc::mem_fun (*this, &StepEntry::insert_gsharp)); + myactions.register_action ("StepEditing", "insert-rest", _("Insert a Note-length Rest"), sigc::mem_fun (*this, &StepEntry::insert_rest)); + myactions.register_action ("StepEditing", "insert-snap-rest", _("Insert a Snap-length Rest"), sigc::mem_fun (*this, &StepEntry::insert_grid_rest)); + + myactions.register_action ("StepEditing", "next-octave", _("Move to next octave"), sigc::mem_fun (*this, &StepEntry::next_octave)); + myactions.register_action ("StepEditing", "prev-octave", _("Move to next octave"), sigc::mem_fun (*this, &StepEntry::prev_octave)); + + myactions.register_action ("StepEditing", "next-note-length", _("Move to Next Note Length"), sigc::mem_fun (*this, &StepEntry::next_note_length)); + myactions.register_action ("StepEditing", "prev-note-length", _("Move to Previous Note Length"), sigc::mem_fun (*this, &StepEntry::prev_note_length)); + + myactions.register_action ("StepEditing", "inc-note-length", _("Increase Note Length"), sigc::mem_fun (*this, &StepEntry::inc_note_length)); + myactions.register_action ("StepEditing", "dec-note-length", _("Decrease Note Length"), sigc::mem_fun (*this, &StepEntry::dec_note_length)); + + myactions.register_action ("StepEditing", "next-note-velocity", _("Move to Next Note Velocity"), sigc::mem_fun (*this, &StepEntry::next_note_velocity)); + myactions.register_action ("StepEditing", "prev-note-velocity", _("Move to Previous Note Velocity"), sigc::mem_fun (*this, &StepEntry::prev_note_velocity)); + + myactions.register_action ("StepEditing", "inc-note-velocity", _("Increase Note Velocity"), sigc::mem_fun (*this, &StepEntry::inc_note_velocity)); + myactions.register_action ("StepEditing", "dec-note-velocity", _("Decrease Note Velocity"), sigc::mem_fun (*this, &StepEntry::dec_note_velocity)); + + myactions.register_action ("StepEditing", "octave-0", _("Switch to the 1st octave"), sigc::mem_fun (*this, &StepEntry::octave_0)); + myactions.register_action ("StepEditing", "octave-1", _("Switch to the 2nd octave"), sigc::mem_fun (*this, &StepEntry::octave_1)); + myactions.register_action ("StepEditing", "octave-2", _("Switch to the 3rd octave"), sigc::mem_fun (*this, &StepEntry::octave_2)); + myactions.register_action ("StepEditing", "octave-3", _("Switch to the 4th octave"), sigc::mem_fun (*this, &StepEntry::octave_3)); + myactions.register_action ("StepEditing", "octave-4", _("Switch to the 5th octave"), sigc::mem_fun (*this, &StepEntry::octave_4)); + myactions.register_action ("StepEditing", "octave-5", _("Switch to the 6th octave"), sigc::mem_fun (*this, &StepEntry::octave_5)); + myactions.register_action ("StepEditing", "octave-6", _("Switch to the 7th octave"), sigc::mem_fun (*this, &StepEntry::octave_6)); + myactions.register_action ("StepEditing", "octave-7", _("Switch to the 8th octave"), sigc::mem_fun (*this, &StepEntry::octave_7)); + myactions.register_action ("StepEditing", "octave-8", _("Switch to the 9th octave"), sigc::mem_fun (*this, &StepEntry::octave_8)); + 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", @@ -577,11 +612,23 @@ StepEntry::register_actions () _("Set Note Velocity to Fortississimo"), sigc::mem_fun (*this, &StepEntry::note_velocity_change), 112); myactions.register_radio_action ("StepEditing", note_velocity_group, "note-velocity-fff", _("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)); + 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)); } 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; @@ -593,6 +640,24 @@ StepEntry::load_bindings () } void +StepEntry::toggle_triplet () +{ + // nowt to be done +} + +void +StepEntry::toggle_chord () +{ + _mtv->step_edit_toggle_chord (); +} + +void +StepEntry::toggle_dotted () +{ + // nowt to be done +} + +void StepEntry::program_click () { _mtv->step_add_program_change (note_channel(), (int8_t) floor (program_adjustment.get_value())); @@ -714,7 +779,6 @@ StepEntry::note_velocity_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)); - cerr << "Velocity reset to " << v << endl; velocity_adjustment.set_value (v); } } @@ -834,3 +898,136 @@ StepEntry::radio_button_release (GdkEventButton* ev, RadioButton* btn, int v) 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; + } else { + l = 1; + } + + velocity_adjustment.set_value (l); +} + +void +StepEntry::octave_n (int n) +{ + octave_adjustment.set_value (n); +} + +void +StepEntry::do_sustain () +{ +} diff --git a/gtk2_ardour/step_entry.h b/gtk2_ardour/step_entry.h index 0fd7d6f121..c627b9575f 100644 --- a/gtk2_ardour/step_entry.h +++ b/gtk2_ardour/step_entry.h @@ -41,7 +41,7 @@ class StepEntry : public ArdourDialog void note_off_event_handler (int note); void rest_event_handler (); - Evoral::MusicalTime note_length() const; + Evoral::MusicalTime note_length(); uint8_t note_velocity() const; uint8_t note_channel() const; @@ -119,11 +119,6 @@ class StepEntry : public ArdourDialog void bank_click (); void program_click (); - void rest_click (); - void grid_rest_click (); - void sustain_click (); - void chord_toggled (); - void triplet_toggled (); void beat_resync_click (); void bar_resync_click (); @@ -163,6 +158,38 @@ class StepEntry : public ArdourDialog void load_bindings (); Gtkmm2ext::Bindings bindings; + + void inc_note_velocity (); + void dec_note_velocity (); + void next_note_velocity (); + void prev_note_velocity (); + + void inc_note_length (); + void dec_note_length (); + void next_note_length (); + void prev_note_length (); + + void next_octave (); + void prev_octave (); + + void octave_n (int n); + void octave_0 () { octave_n (0); } + void octave_1 () { octave_n (1); } + void octave_2 () { octave_n (2); } + void octave_3 () { octave_n (3); } + void octave_4 () { octave_n (4); } + void octave_5 () { octave_n (5); } + void octave_6 () { octave_n (6); } + void octave_7 () { octave_n (7); } + void octave_8 () { octave_n (8); } + void octave_9 () { octave_n (9); } + void octave_10 () { octave_n (10); } + + void toggle_dotted(); + void toggle_triplet(); + void toggle_chord(); + + void do_sustain (); }; #endif /* __gtk2_ardour_step_entry_h__ */ |