change selection behaviour for track header context click
[ardour.git] / gtk2_ardour / editor_mouse.cc
index 172f71d4a7b0071f70b20d4d2e8ccd7ead39f14b..e9b71e4e859e604b2925028e46b3d7d59f5c4b03 100644 (file)
@@ -15,7 +15,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #include <cassert>
@@ -301,7 +300,9 @@ Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType it
 
        if (((mouse_mode != MouseObject) &&
             (mouse_mode != MouseAudition || item_type != RegionItem) &&
-            (mouse_mode != MouseTimeFX || item_type != RegionItem)) ||
+            (mouse_mode != MouseTimeFX || item_type != RegionItem) &&
+            (mouse_mode != MouseRange)) ||
+
            (event->type != GDK_BUTTON_PRESS && event->type != GDK_BUTTON_RELEASE || event->button.button > 3)) {
                
                return;
@@ -311,9 +312,11 @@ Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType it
 
                if ((event->button.state & Keyboard::RelevantModifierKeyMask) && event->button.button != 1) {
                        
-                       /* no selection action on modified button-2 or button-3 events */
-                       
-                       return;
+                       /* almost no selection action on modified button-2 or button-3 events */
+               
+                       if (item_type != RegionItem && event->button.button != 2) {
+                               return;
+                       }
                }
        }
            
@@ -324,29 +327,48 @@ Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType it
 
        switch (item_type) {
        case RegionItem:
-               commit = set_selected_regionview_from_click (press, op, true);
+               if (mouse_mode != MouseRange) {
+                       commit = set_selected_regionview_from_click (press, op, true);
+               } else if (event->type == GDK_BUTTON_PRESS) {
+                       commit = set_selected_track_from_click (press, op, false);
+               }
                break;
                
        case RegionViewNameHighlight:
        case RegionViewName:
-               commit = set_selected_regionview_from_click (press, op, true);
+               if (mouse_mode != MouseRange) {
+                       commit = set_selected_regionview_from_click (press, op, true);
+               } else if (event->type == GDK_BUTTON_PRESS) {
+                       commit = set_selected_track_from_click (press, op, false);
+               }
                break;
 
        case FadeInHandleItem:
        case FadeInItem:
        case FadeOutHandleItem:
        case FadeOutItem:
-               commit = set_selected_regionview_from_click (press, op, true);
+               if (mouse_mode != MouseRange) {
+                       commit = set_selected_regionview_from_click (press, op, true);
+               } else if (event->type == GDK_BUTTON_PRESS) {
+                       commit = set_selected_track_from_click (press, op, false);
+               }
                break;
                
        case GainAutomationControlPointItem:
        case PanAutomationControlPointItem:
        case RedirectAutomationControlPointItem:
-               commit = set_selected_control_point_from_click (op, false);
+               if (mouse_mode != MouseRange) {
+                       commit = set_selected_control_point_from_click (op, false);
+               }
                break;
                
        case StreamItem:
-               // commit = set_selected_track_from_click (press, op, true);
+               /* for context click or range selection, select track */
+               if (event->button.button == 3) {
+                       commit = set_selected_track_from_click (press, op, true);
+               } else if (event->type == GDK_BUTTON_PRESS && mouse_mode == MouseRange) {
+                       commit = set_selected_track_from_click (press, op, false);
+               }
                break;
                    
        case AutomationTrackItem:
@@ -357,26 +379,6 @@ Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType it
                break;
        }
        
-#define SELECT_TRACK_FROM_CANVAS_IN_RANGE_MODE
-#ifdef  SELECT_TRACK_FROM_CANVAS_IN_RANGE_MODE
-       /* in range mode, button 1/2/3 press potentially selects a track */
-
-       if (mouse_mode == MouseRange && 
-           event->type == GDK_BUTTON_PRESS && 
-           event->button.button <= 3) {
-               
-               switch (item_type) {
-               case StreamItem:
-               case RegionItem:
-               case AutomationTrackItem:
-                       commit = set_selected_track_from_click (true, op, true);
-                       break;
-
-               default:
-                       break;
-               }
-       }
-#endif
        if (commit) {
                commit_reversible_command ();
        }
@@ -385,8 +387,6 @@ Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType it
 bool
 Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type)
 {
-       nframes_t where = event_frame (event, 0, 0);
-
        track_canvas.grab_focus();
 
        if (session && session->actively_recording()) {
@@ -744,79 +744,6 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
        case 3:
                break;
 
-       case 4:
-               switch (mouse_mode) {
-               case MouseZoom:
-                       //temporal_zoom_to_frame (true, where);
-                       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
-                               temporal_zoom_to_frame (true, where);
-                       }
-                       else {
-                               temporal_zoom_step (true);
-                       }
-                       break;
-               default:
-                       
-                       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::ModifierMask(Keyboard::Alt))) {
-                               scroll_backward (0.6f);
-                               return true;
-                       }
-                       else if (Keyboard::no_modifier_keys_pressed (&event->button)) {
-                               scroll_tracks_up_line ();
-                       } else {
-                               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Shift)) {
-                                       if (clicked_trackview) {
-                                               if (!current_stepping_trackview) {
-                                                 step_timeout = Glib::signal_timeout().connect (mem_fun(*this, &Editor::track_height_step_timeout), 500);
-                                                       current_stepping_trackview = clicked_trackview;
-                                               }
-                                               gettimeofday (&last_track_height_step_timestamp, 0);
-                                               current_stepping_trackview->step_height (true);
-                                       }
-                               }
-                               else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
-                                       temporal_zoom_to_frame (true, where);
-                               }
-                       }
-               }
-               break;
-
-       case 5:
-               switch (mouse_mode) {
-               case MouseZoom:
-                       // temporal_zoom_to_frame (false, where);
-                       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
-                               temporal_zoom_to_frame (false, where);
-                       }
-                       else {
-                               temporal_zoom_step (false);
-                       }
-                       break;
-               default:
-
-                       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::ModifierMask(Keyboard::Alt))) {
-                               scroll_forward (0.6f);
-                               return true;
-                       }
-                       else if (Keyboard::no_modifier_keys_pressed (&event->button)) {
-                               scroll_tracks_down_line ();
-                       } else {
-                               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Shift)) {
-                                       if (clicked_trackview) {
-                                               if (!current_stepping_trackview) {
-                                                 step_timeout = Glib::signal_timeout().connect (mem_fun(*this, &Editor::track_height_step_timeout), 500);
-                                                       current_stepping_trackview = clicked_trackview;
-                                               }
-                                               gettimeofday (&last_track_height_step_timestamp, 0);
-                                               current_stepping_trackview->step_height (false);
-                                       }
-                               } else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
-                                       temporal_zoom_to_frame (false, where);
-                               }
-                       }
-               }
-               break;
-
        default:
                break;
 
@@ -1173,23 +1100,25 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
        case GainAutomationControlPointItem:
        case PanAutomationControlPointItem:
        case RedirectAutomationControlPointItem:
-               cp = static_cast<ControlPoint*>(item->get_data ("control_point"));
-               cp->set_visible (true);
-               
-               double at_x, at_y;
-               at_x = cp->get_x();
-               at_y = cp->get_y ();
-               cp->item->i2w (at_x, at_y);
-               at_x += 20.0;
-               at_y += 20.0;
-
-               fraction = 1.0 - (cp->get_y() / cp->line.height());
-       
-               set_verbose_canvas_cursor (cp->line.get_verbose_cursor_string (fraction), at_x, at_y);
-               show_verbose_canvas_cursor ();
-               
-               if (is_drawable()) {
-                       track_canvas.get_window()->set_cursor (*fader_cursor);
+               if (mouse_mode == MouseGain || mouse_mode == MouseObject) {
+                       cp = static_cast<ControlPoint*>(item->get_data ("control_point"));
+                       cp->set_visible (true);
+
+                       double at_x, at_y;
+                       at_x = cp->get_x();
+                       at_y = cp->get_y ();
+                       cp->item->i2w (at_x, at_y);
+                       at_x += 20.0;
+                       at_y += 20.0;
+
+                       fraction = 1.0 - (cp->get_y() / cp->line.height());
+
+                       set_verbose_canvas_cursor (cp->line.get_verbose_cursor_string (fraction), at_x, at_y);
+                       show_verbose_canvas_cursor ();
+
+                       if (is_drawable()) {
+                               track_canvas.get_window()->set_cursor (*fader_cursor);
+                       }
                }
                break;
                
@@ -1207,13 +1136,15 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
        case GainAutomationLineItem:
        case RedirectAutomationLineItem:
        case PanAutomationLineItem:
-               {
-                       ArdourCanvas::Line *line = dynamic_cast<ArdourCanvas::Line *> (item);
-                       if (line)
-                               line->property_fill_color_rgba() = color_map[cEnteredAutomationLine];
-               }
-               if (is_drawable()) {
-                       track_canvas.get_window()->set_cursor (*fader_cursor);
+               if (mouse_mode == MouseGain || mouse_mode == MouseObject) {
+                       {
+                               ArdourCanvas::Line *line = dynamic_cast<ArdourCanvas::Line *> (item);
+                               if (line)
+                                       line->property_fill_color_rgba() = color_map[cEnteredAutomationLine];
+                       }
+                       if (is_drawable()) {
+                               track_canvas.get_window()->set_cursor (*fader_cursor);
+                       }
                }
                break;
                
@@ -1514,7 +1445,10 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
                */
                if (!drag_info.move_threshold_passed) {
 
-                       drag_info.move_threshold_passed = (abs ((int) (drag_info.current_pointer_x - drag_info.grab_x)) > 4);
+                       bool x_threshold_passed =  (abs ((int) (drag_info.current_pointer_x - drag_info.grab_x)) > 4);
+                       bool y_threshold_passed =  (abs ((int) (drag_info.current_pointer_y - drag_info.grab_y)) > 4);
+
+                       drag_info.move_threshold_passed = (x_threshold_passed || y_threshold_passed);
                        
                        // and change the initial grab loc/frame if this drag info wants us to
 
@@ -2824,65 +2758,33 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
                drag_info.want_move_threshold = false; // don't copy again
 
-               /* this is committed in the grab finished callback. */
-               
-               begin_reversible_command (_("Drag region copy"));
-               
                /* duplicate the region(s) */
                
                vector<RegionView*> new_regionviews;
                
-               set<boost::shared_ptr<Playlist> > affected_playlists;
-               pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
-               
                for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) {
                        RegionView* rv;
-                       
+                       RegionView* nrv;
+                       AudioRegionView* arv;
+
                        rv = (*i);
-                       
-                       boost::shared_ptr<Playlist> to_playlist = rv->region()->playlist();
-                       RouteTimeAxisView* atv = dynamic_cast<RouteTimeAxisView*>(&rv->get_time_axis_view());
 
-                       insert_result = affected_playlists.insert (to_playlist);
-                       if (insert_result.second) {
-                               session->add_command (new MementoCommand<Playlist>(*to_playlist, &to_playlist->get_state(), 0));
-                       }
-                       
-                       latest_regionview = 0;
-                       
-                       sigc::connection c = atv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
                        
-                       /* create a new region with the same name. */
-                       
-                       // FIXME: ew.  need a (virtual) Region::duplicate() or something?
-
-                       boost::shared_ptr<Region> newregion;
-                       boost::shared_ptr<Region> ar;
-
-                       if ((ar = boost::dynamic_pointer_cast<AudioRegion>(rv->region())) != 0) {
-                               newregion = RegionFactory::create (ar);
+                       if ((arv = dynamic_cast<AudioRegionView*>(rv)) == 0) {
+                               /* XXX handle MIDI here */
+                               continue;
                        }
-                       assert(newregion != 0);
 
-                       /* if the original region was locked, we don't care */
-                       
-                       newregion->set_locked (false);
-                       
-                       to_playlist->add_region (newregion, (nframes_t) (rv->region()->position() * atv->get_diskstream()->speed()));
-                       
-                       c.disconnect ();
-                       
-                       if (latest_regionview) {
-                               new_regionviews.push_back (latest_regionview);
-                       }
+                       nrv = new AudioRegionView (*arv);
+                       nrv->get_canvas_group()->show ();
+
+                       new_regionviews.push_back (nrv);
                }
 
-               
-               
                if (new_regionviews.empty()) {
                        return;
                }
-               
+
                /* reset selection to new regionviews */
                
                selection->set (new_regionviews);
@@ -2890,6 +2792,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                /* reset drag_info data to reflect the fact that we are dragging the copies */
                
                drag_info.data = new_regionviews.front();
+               
                swap_grab (new_regionviews.front()->get_canvas_group (), 0, event->motion.time);
        }
 
@@ -3168,149 +3071,147 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                         MOTION                                                               
        ************************************************************/
 
-       pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
-       const list<RegionView*>& layered_regions = selection->regions.by_layer();
+       bool do_move;
+
+       if (drag_info.first_move) {
+               if (drag_info.move_threshold_passed) {
+                       do_move = true;
+               } else {
+                       do_move = false;
+               }
+       } else {
+               do_move = true;
+       }
 
-       for (list<RegionView*>::const_iterator i = layered_regions.begin(); i != layered_regions.end(); ++i) {
+       if (do_move) {
+
+               pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
+               const list<RegionView*>& layered_regions = selection->regions.by_layer();
+
+               for (list<RegionView*>::const_iterator i = layered_regions.begin(); i != layered_regions.end(); ++i) {
            
-               RegionView* rv = (*i);
-               double ix1, ix2, iy1, iy2;
-               int32_t temp_pointer_y_span = pointer_y_span;
+                       RegionView* rv = (*i);
+                       double ix1, ix2, iy1, iy2;
+                       int32_t temp_pointer_y_span = pointer_y_span;
 
-               /* get item BBox, which will be relative to parent. so we have
-                  to query on a child, then convert to world coordinates using
-                  the parent.
-               */
+                       /* get item BBox, which will be relative to parent. so we have
+                          to query on a child, then convert to world coordinates using
+                          the parent.
+                       */
 
-               rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
-               rv->get_canvas_group()->i2w (ix1, iy1);
-               TimeAxisView* tvp2 = trackview_by_y_position (iy1);
-               AudioTimeAxisView* canvas_atv = dynamic_cast<AudioTimeAxisView*>(tvp2);
-               AudioTimeAxisView* temp_atv;
-
-               if ((pointer_y_span != 0) && !clamp_y_axis) {
-                       y_delta = 0;
-                       int32_t x = 0;
-                       for (j = height_list.begin(); j!= height_list.end(); j++) {     
-                               if (x == canvas_atv->order) {
-                                       /* we found the track the region is on */
-                                       if (x != original_pointer_order) {
-                                               /*this isn't from the same track we're dragging from */
-                                               temp_pointer_y_span = canvas_pointer_y_span;
-                                       }                 
-                                       while (temp_pointer_y_span > 0) {
-                                               /* we're moving up canvas-wise,
-                                                  so  we need to find the next track height
-                                               */
-                                               if (j != height_list.begin()) {           
-                                                       j--;
-                                               }
-                                               if (x != original_pointer_order) { 
-                                                       /* we're not from the dragged track, so ignore hidden tracks. */              
-                                                       if ((*j) == 0) {
-                                                               temp_pointer_y_span++;
-                                                       }
-                                               }          
-                                               y_delta -= (*j);        
-                                               temp_pointer_y_span--;  
-                                       }
-                                       while (temp_pointer_y_span < 0) {                 
-                                               y_delta += (*j);
-                                               if (x != original_pointer_order) { 
-                                                       if ((*j) == 0) {
-                                                               temp_pointer_y_span--;
+                       rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
+                       rv->get_canvas_group()->i2w (ix1, iy1);
+                       TimeAxisView* tvp2 = trackview_by_y_position (iy1);
+                       AudioTimeAxisView* canvas_atv = dynamic_cast<AudioTimeAxisView*>(tvp2);
+                       AudioTimeAxisView* temp_atv;
+
+                       if ((pointer_y_span != 0) && !clamp_y_axis) {
+                               y_delta = 0;
+                               int32_t x = 0;
+                               for (j = height_list.begin(); j!= height_list.end(); j++) {     
+                                       if (x == canvas_atv->order) {
+                                               /* we found the track the region is on */
+                                               if (x != original_pointer_order) {
+                                                       /*this isn't from the same track we're dragging from */
+                                                       temp_pointer_y_span = canvas_pointer_y_span;
+                                               }                 
+                                               while (temp_pointer_y_span > 0) {
+                                                       /* we're moving up canvas-wise,
+                                                          so  we need to find the next track height
+                                                       */
+                                                       if (j != height_list.begin()) {           
+                                                               j--;
                                                        }
-                                               }          
+                                                       if (x != original_pointer_order) { 
+                                                               /* we're not from the dragged track, so ignore hidden tracks. */              
+                                                               if ((*j) == 0) {
+                                                                       temp_pointer_y_span++;
+                                                               }
+                                                       }          
+                                                       y_delta -= (*j);        
+                                                       temp_pointer_y_span--;  
+                                               }
+                                               while (temp_pointer_y_span < 0) {                 
+                                                       y_delta += (*j);
+                                                       if (x != original_pointer_order) { 
+                                                               if ((*j) == 0) {
+                                                                       temp_pointer_y_span--;
+                                                               }
+                                                       }          
                    
-                                               if (j != height_list.end()) {                 
-                                                       j++;
+                                                       if (j != height_list.end()) {                 
+                                                               j++;
+                                                       }
+                                                       temp_pointer_y_span++;
                                                }
-                                               temp_pointer_y_span++;
-                                       }
-                                       /* find out where we'll be when we move and set height accordingly */
+                                               /* find out where we'll be when we move and set height accordingly */
                  
-                                       tvp2 = trackview_by_y_position (iy1 + y_delta);
-                                       temp_atv = dynamic_cast<AudioTimeAxisView*>(tvp2);
-                                       rv->set_height (temp_atv->height);
+                                               tvp2 = trackview_by_y_position (iy1 + y_delta);
+                                               temp_atv = dynamic_cast<AudioTimeAxisView*>(tvp2);
+                                               rv->set_height (temp_atv->height);
        
-                                       /*   if you un-comment the following, the region colours will follow the track colours whilst dragging,
-                                            personally, i think this can confuse things, but never mind.
-                                       */
+                                               /*   if you un-comment the following, the region colours will follow the track colours whilst dragging,
+                                                    personally, i think this can confuse things, but never mind.
+                                               */
                                  
-                                       //const GdkColor& col (temp_atv->view->get_region_color());
-                                       //rv->set_color (const_cast<GdkColor&>(col));
-                                       break;          
+                                               //const GdkColor& col (temp_atv->view->get_region_color());
+                                               //rv->set_color (const_cast<GdkColor&>(col));
+                                               break;          
+                                       }
+                                       x++;
                                }
-                               x++;
                        }
-               }
          
-               /* prevent the regionview from being moved to before 
-                  the zero position on the canvas.
-               */
-               /* clamp */
+                       /* prevent the regionview from being moved to before 
+                          the zero position on the canvas.
+                       */
+                       /* clamp */
                
-               if (x_delta < 0) {
-                       if (-x_delta > ix1) {
-                               x_delta = -ix1;
+                       if (x_delta < 0) {
+                               if (-x_delta > ix1) {
+                                       x_delta = -ix1;
+                               }
+                       } else if ((x_delta > 0) &&(rv->region()->last_frame() > max_frames - x_delta)) {
+                               x_delta = max_frames - rv->region()->last_frame();
                        }
-               } else if ((x_delta > 0) &&(rv->region()->last_frame() > max_frames - x_delta)) {
-                       x_delta = max_frames - rv->region()->last_frame();
-               }
-                       
-               if (drag_info.first_move) {
-
-                       /* hide any dependent views */
 
-                       rv->get_time_axis_view().hide_dependent_views (*rv);
-                               
-                       /* this is subtle. raising the regionview itself won't help,
-                          because raise_to_top() just puts the item on the top of
-                          its parent's stack. so, we need to put the trackview canvas_display group
-                          on the top, since its parent is the whole canvas.
-                       */
+                       if (drag_info.first_move) {
 
-                       rv->get_canvas_group()->raise_to_top();
-                       rv->get_time_axis_view().canvas_display->raise_to_top();
-                       cursor_group->raise_to_top();
+                               /* hide any dependent views */
+                       
+                               rv->get_time_axis_view().hide_dependent_views (*rv);
+                       
+                               /* this is subtle. raising the regionview itself won't help,
+                                  because raise_to_top() just puts the item on the top of
+                                  its parent's stack. so, we need to put the trackview canvas_display group
+                                  on the top, since its parent is the whole canvas.
+                               */
+                       
+                               rv->get_canvas_group()->raise_to_top();
+                               rv->get_time_axis_view().canvas_display->raise_to_top();
+                               cursor_group->raise_to_top();
 
-                       /* freeze the playlists from notifying till
-                          the motion is done.
-                       */
+                               rv->fake_set_opaque (true);
+                       }
+                       
+                       if (drag_info.brushing) {
+                               mouse_brush_insert_region (rv, pending_region_position);
+                       } else {
+                               rv->move (x_delta, y_delta);                    
+                       }
 
-                       AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&rv->get_time_axis_view());
-                       if (atv && atv->is_audio_track()) {
-                               boost::shared_ptr<AudioPlaylist> pl = boost::dynamic_pointer_cast<AudioPlaylist>(atv->get_diskstream()->playlist());
-                               if (pl) {
-                                       /* only freeze and capture state once */
+               } /* foreach region */
 
-                                       insert_result = motion_frozen_playlists.insert (pl);
-                                       if (insert_result.second) {
-                                               pl->freeze();
-                                               session->add_command(new MementoCommand<Playlist>(*pl, &pl->get_state(), 0));
-                                       }
-                               }
-                       }
-                       rv->region()->set_opaque(false);
-               }
+       } /* if do_move */
 
-               if (drag_info.brushing) {
-                       mouse_brush_insert_region (rv, pending_region_position);
-               } else {
-                       rv->move (x_delta, y_delta);                    
-               }
-       }
-               
-       if (drag_info.first_move) {
+       if (drag_info.first_move && drag_info.move_threshold_passed) {
                cursor_group->raise_to_top();
+               drag_info.first_move = false;
        }
-               
-       drag_info.first_move = false;
-               
+
        if (x_delta != 0 && !drag_info.brushing) {
                show_verbose_time_cursor (drag_info.last_frame_position, 10);
        }
-               
 } 
 
 void
@@ -3361,106 +3262,94 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
        //printf ("last_frame: %s position is %lu  %g\n", rv->get_time_axis_view().name().c_str(), drag_info.last_frame_position, speed); 
        //printf ("last_rackview: %s \n", drag_info.last_trackview->name().c_str()); 
        
+       char* op_string;
+
+       if (drag_info.copy) {
+               if (drag_info.x_constrained) {
+                       op_string = _("fixed time region copy");
+               } else {
+                       op_string = _("region copy");
+               } 
+       } else {
+               if (drag_info.x_constrained) {
+                       op_string = _("fixed time region drag");
+               } else {
+                       op_string = _("region drag");
+               }
+       }
+
+       begin_reversible_command (op_string);
+
        if (regionview_y_movement) {
 
-               /* motion between tracks */
+               /* moved to a different audio track. */
 
                list<RegionView*> new_selection;
-       
-               /* moved to a different audio track. */
+               new_selection = selection->regions.by_layer();
+               selection->clear_regions ();
 
-               for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ) {
+               for (list<RegionView*>::const_iterator i = new_selection.begin(); i != new_selection.end(); ++i) {
            
-                       RegionView* rv2 = (*i);             
-           
-                       /* the region that used to be in the old playlist is not
-                          moved to the new one - we make a copy of it. as a result,
-                          any existing editor for the region should no longer be
-                          visible.
-                       */ 
-           
-                       if (!drag_info.copy) {
-                               rv2->hide_region_editor();
-                       }           
-                       new_selection.push_back (rv2);      
-                       i++;
-               }
+                       RegionView* rv = (*i);              
 
-               /* first, freeze the target tracks */
-
-               for (list<RegionView*>::const_iterator i = new_selection.begin(); i != new_selection.end();i++ ) {
-
-                       boost::shared_ptr<Playlist> from_playlist;
-                       boost::shared_ptr<Playlist> to_playlist;
-                               
                        double ix1, ix2, iy1, iy2;
-           
-                       (*i)->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
-                       (*i)->get_canvas_group()->i2w (ix1, iy1);
+                       
+                       rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
+                       rv->get_canvas_group()->i2w (ix1, iy1);
                        TimeAxisView* tvp2 = trackview_by_y_position (iy1);
                        AudioTimeAxisView* atv2 = dynamic_cast<AudioTimeAxisView*>(tvp2);
 
-                       (*i)->region()->set_opaque (true);
+                       boost::shared_ptr<Playlist> from_playlist = rv->region()->playlist();
+                       boost::shared_ptr<Playlist> to_playlist = atv2->playlist();
            
-                       from_playlist = (*i)->region()->playlist();
-                       to_playlist = atv2->playlist();
-
-                       /* the from_playlist was frozen in the "first_move" case 
-                          of the motion handler. the insert can fail, 
-                          but that doesn't matter. it just means
-                          we already have the playlist in the list.
-                       */
-                       
-                       motion_frozen_playlists.insert (from_playlist);
-
-                       /* only freeze the to_playlist once */
-
-                       insert_result = motion_frozen_playlists.insert(to_playlist);
-                       if (insert_result.second) {
-                               to_playlist->freeze();
-                                session->add_command(new MementoCommand<Playlist>(*to_playlist, &to_playlist->get_state(), 0));
-                       }
-
-               }
-
-               /* now do it again with the actual operations */
-
-               for (list<RegionView*>::const_iterator i = new_selection.begin(); i != new_selection.end();i++ ) {
+                       where = (nframes_t) (unit_to_frame (ix1) * speed);
+                       boost::shared_ptr<Region> new_region (RegionFactory::create (rv->region()));
 
-                       boost::shared_ptr<Playlist> from_playlist;
-                       boost::shared_ptr<Playlist> to_playlist;
+                       if (!drag_info.copy) {
                                
-                       double ix1, ix2, iy1, iy2;
-           
-                       (*i)->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2);
-                       (*i)->get_canvas_group()->i2w (ix1, iy1);
-                       TimeAxisView* tvp2 = trackview_by_y_position (iy1);
-                       AudioTimeAxisView* atv2 = dynamic_cast<AudioTimeAxisView*>(tvp2);
+                               /* the region that used to be in the old playlist is not
+                                  moved to the new one - we make a copy of it. as a result,
+                                  any existing editor for the region should no longer be
+                                  visible.
+                               */ 
            
-                       from_playlist = (*i)->region()->playlist();
-                       to_playlist = atv2->playlist();
+                               rv->hide_region_editor();
+                               rv->fake_set_opaque (false);
 
-                       latest_regionview = 0;
-           
-                       where = (nframes_t) (unit_to_frame (ix1) * speed);
-                       boost::shared_ptr<Region> new_region (RegionFactory::create ((*i)->region()));
+                               session->add_command (new MementoCommand<Playlist>(*from_playlist, &from_playlist->get_state(), 0));    
+                               from_playlist->remove_region ((rv->region()));
+                               session->add_command (new MementoCommand<Playlist>(*from_playlist, 0, &from_playlist->get_state()));    
+                       }
 
-                       from_playlist->remove_region (((*i)->region()));
+                       latest_regionview = 0;
                        
                        sigc::connection c = atv2->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
+                       session->add_command (new MementoCommand<Playlist>(*to_playlist, &to_playlist->get_state(), 0));        
                        to_playlist->add_region (new_region, where);
+                       session->add_command (new MementoCommand<Playlist>(*to_playlist, 0, &to_playlist->get_state()));        
                        c.disconnect ();
                                                              
                        if (latest_regionview) {
                                selection->add (latest_regionview);
                        }
+
+                       if (drag_info.copy) {
+                               // get rid of the copy
+                               delete rv;
+                       } 
                } 
 
        } else {
 
                /* motion within a single track */
+
+               list<RegionView*> regions = selection->regions.by_layer();
+
+               if (drag_info.copy) {
+                       selection->clear_regions();
+               }
                
-               for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) {
+               for (list<RegionView*>::iterator i = regions.begin(); i != regions.end(); ++i) {
 
                        rv = (*i);
 
@@ -3468,9 +3357,10 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
                                continue;
                        }
                        
+
                        if (regionview_x_movement) {
                                double ownspeed = 1.0;
-                               AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&(rv->get_time_axis_view()));
+                               atv = dynamic_cast<AudioTimeAxisView*> (&(rv->get_time_axis_view()));
 
                                if (atv && atv->get_diskstream()) {
                                        ownspeed = atv->get_diskstream()->speed();
@@ -3489,23 +3379,62 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
                                where = rv->region()->position();
                        }
 
-                       rv->get_time_axis_view().reveal_dependent_views (*rv);
+                       boost::shared_ptr<Playlist> to_playlist = rv->region()->playlist();
 
-                       /* no need to add an undo here, we did that when we added this playlist to motion_frozen playlists */
-                       
-                       rv->region()->set_position (where, (void *) this);
-                       rv->region()->set_opaque (true);
+                       /* add the undo */
+
+                       session->add_command (new MementoCommand<Playlist>(*to_playlist, &to_playlist->get_state(), 0));        
+
+                       if (drag_info.copy) {
+
+                               boost::shared_ptr<Region> newregion;
+                               boost::shared_ptr<Region> ar;
+
+                               if ((ar = boost::dynamic_pointer_cast<AudioRegion>(rv->region())) != 0) {
+                                       newregion = RegionFactory::create (ar);
+                               } else {
+                                       /* XXX MIDI HERE drobilla */
+                                       continue;
+                               }
+
+                               /* add it */
+                               
+                               latest_regionview = 0;
+                               sigc::connection c = atv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
+                               to_playlist->add_region (newregion, (nframes_t) (where * atv->get_diskstream()->speed()));
+                               c.disconnect ();
+                               
+                               if (latest_regionview) {
+                                       atv->reveal_dependent_views (*latest_regionview);
+                                       selection->add (latest_regionview);
+                               }
+                               
+                               /* if the original region was locked, we don't care for the new one */
+                               
+                               newregion->set_locked (false);                  
+
+                       } else {
+
+                               /* just change the model */
+
+                               rv->region()->set_position (where, (void*) this);
+
+                       }
+
+                       /* add the redo */
+
+                       session->add_command (new MementoCommand<Playlist>(*to_playlist, 0, &to_playlist->get_state()));
+
+                       /* get rid of the copy */
+
+                       if (drag_info.copy) {
+                               delete rv;
+                       }
                }
        }
 
   out:
-       for (set<boost::shared_ptr<Playlist> >::iterator p = motion_frozen_playlists.begin(); p != motion_frozen_playlists.end(); ++p) {
-               (*p)->thaw ();
-               session->add_command (new MementoCommand<Playlist>(*((*p).get()), 0, & (*p)->get_state()));
-       }
-
-       motion_frozen_playlists.clear ();
-
+       
        if (!nocommit) {
                commit_reversible_command ();
        }
@@ -3980,8 +3909,6 @@ Editor::start_trim (ArdourCanvas::Item* item, GdkEvent* event)
        nframes_t region_end = (nframes_t) (clicked_regionview->region()->last_frame() / speed);
        nframes_t region_length = (nframes_t) (clicked_regionview->region()->length() / speed);
 
-       motion_frozen_playlists.clear();
-       
        //drag_info.item = clicked_regionview->get_name_highlight();
        drag_info.item = item;
        drag_info.motion_callback = &Editor::trim_motion_callback;
@@ -4070,7 +3997,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                begin_reversible_command (trim_type);
 
                for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) {
-                       (*i)->region()->set_opaque(false);
+                       (*i)->fake_set_opaque(false);
                        (*i)->region()->freeze ();
                
                        AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
@@ -4265,7 +4192,7 @@ Editor::trim_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
                             i != selection->regions.by_layer().end(); ++i)
                        {
                                thaw_region_after_trim (**i);
-                               (*i)->region()->set_opaque(true);
+                               (*i)->fake_set_opaque (true);
                        }
                }
                
@@ -4557,7 +4484,6 @@ Editor::end_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event)
                        switch (mouse_mode) {
                        case MouseObject:
                                /* find the two markers on either side and then make the selection from it */
-                               cerr << "select between " << start << " .. " << end << endl;
                                select_all_within (start, end, 0.0f, FLT_MAX, Selection::Set);
                                break;