make middle-click on piano roll track header more usefully select/unselect notes
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 23 Oct 2013 14:38:50 +0000 (10:38 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 23 Oct 2013 14:38:50 +0000 (10:38 -0400)
gtk2_ardour/midi_region_view.cc
gtk2_ardour/piano_roll_header.cc

index d681bb43deceb32b4bb74c8e94fd8b5bed5d7aa5..ffd09b76a875d392c534ca0dd2afa4ee1ad74c29 100644 (file)
@@ -2135,32 +2135,39 @@ MidiRegionView::invert_selection ()
 void
 MidiRegionView::select_matching_notes (uint8_t notenum, uint16_t channel_mask, bool add, bool extend)
 {
+       bool have_selection = !_selection.empty();
        uint8_t low_note = 127;
        uint8_t high_note = 0;
        MidiModel::Notes& notes (_model->notes());
        _optimization_iterator = _events.begin();
+       
+       if (extend && !have_selection) {
+               extend = false;
+       }
 
+       /* scan existing selection to get note range */
+       
+       for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
+               if ((*i)->note()->note() < low_note) {
+                       low_note = (*i)->note()->note();
+               }
+               if ((*i)->note()->note() > high_note) {
+                       high_note = (*i)->note()->note();
+               }
+       }
+       
        if (!add) {
                clear_selection ();
-       }
 
-       if (extend && _selection.empty()) {
-               extend = false;
+               if (!extend && (low_note == high_note) && (high_note == notenum)) {
+                       /* only note previously selected is the one we are
+                        * reselecting. treat this as cancelling the selection.
+                        */
+                       return;
+               }
        }
 
        if (extend) {
-
-               /* scan existing selection to get note range */
-
-               for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
-                       if ((*i)->note()->note() < low_note) {
-                               low_note = (*i)->note()->note();
-                       }
-                       if ((*i)->note()->note() > high_note) {
-                               high_note = (*i)->note()->note();
-                       }
-               }
-
                low_note = min (low_note, notenum);
                high_note = max (high_note, notenum);
        }
index 3243f893c7622a9d27dfcf6b38c263e1b4000b29..e784242ff1247319ab2bf0e56f641d466b262ccb 100644 (file)
@@ -514,31 +514,27 @@ PianoRollHeader::on_button_press_event (GdkEventButton* ev)
 {
        int note = _view.y_to_note(ev->y);
 
-       if (ev->button != 1) {
-               return false;
-       }
-
-       if (editor().current_mouse_mode() == Editing::MouseRange) {
+       if (ev->button == 2 && ev->type == GDK_BUTTON_PRESS) {
                if (Keyboard::no_modifiers_active (ev->state)) {
                        SetNoteSelection (note); // EMIT SIGNAL
+                       return true;
                }
+               return false;
+       }
+       
+       if (ev->button == 1 && ev->type == GDK_BUTTON_PRESS && note >= 0 && note < 128) {
+               
+               add_modal_grab();
                _dragging = true;
-       } else {
-
-               if (ev->type == GDK_BUTTON_PRESS && note >= 0 && note < 128) {
-
-                       add_modal_grab();
-                       _dragging = true;
-
-                       if (!_active_notes[note]) {
-                               _active_notes[note] = true;
-                               _clicked_note = note;
-                               send_note_on(note);
-
-                               invalidate_note_range(note, note);
-                       } else {
-                               reset_clicked_note(note);
-                       }
+               
+               if (!_active_notes[note]) {
+                       _active_notes[note] = true;
+                       _clicked_note = note;
+                       send_note_on(note);
+                       
+                       invalidate_note_range(note, note);
+               } else {
+                       reset_clicked_note(note);
                }
        }