finished merge of cairocanvas with windows and windows+cc branches
[ardour.git] / gtk2_ardour / midi_region_view.cc
index d681bb43deceb32b4bb74c8e94fd8b5bed5d7aa5..afae96bf2215d485a8206472177e4a25bc5437b2 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);
        }
@@ -3073,7 +3080,7 @@ MidiRegionView::nudge_notes (bool forward)
                return;
        }
 
-       Evoral::MusicalTime delta = region_frames_to_region_beats (fabs (distance));
+       Evoral::MusicalTime delta = region_frames_to_region_beats (fabs ((double)distance));
 
        if (!forward) {
                delta = -delta;
@@ -3291,7 +3298,7 @@ MidiRegionView::selection_as_cut_buffer () const
 {
        Notes notes;
 
-       for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
+       for (Selection::const_iterator i = _selection.begin(); i != _selection.end(); ++i) {
                NoteType* n = (*i)->note().get();
                notes.insert (boost::shared_ptr<NoteType> (new NoteType (*n)));
        }