Remove beat entry from meter dialog (beats are not allowed in API), clean up some...
[ardour.git] / gtk2_ardour / editor_mouse.cc
index 3fbd0a19bd383f36412d1e3f02fe5741ee632a88..b745b93f2cbf332cde95e633000085706bb6a201 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>
@@ -25,6 +24,7 @@
 #include <set>
 #include <string>
 #include <algorithm>
+#include <sys/time.h>
 
 #include <pbd/error.h>
 #include <gtkmm2ext/utils.h>
@@ -47,6 +47,7 @@
 #include "rgb_macros.h"
 
 #include <ardour/types.h>
+#include <ardour/profile.h>
 #include <ardour/route.h>
 #include <ardour/audio_track.h>
 #include <ardour/audio_diskstream.h>
@@ -68,8 +69,46 @@ using namespace sigc;
 using namespace Gtk;
 using namespace Editing;
 
-nframes_t
-Editor::event_frame (GdkEvent* event, double* pcx, double* pcy)
+bool
+Editor::mouse_frame (nframes64_t& where, bool& in_track_canvas) const
+{
+       int x, y;
+       double wx, wy;
+       Gdk::ModifierType mask;
+       Glib::RefPtr<Gdk::Window> canvas_window = const_cast<Editor*>(this)->track_canvas.get_window();
+       Glib::RefPtr<const Gdk::Window> pointer_window;
+       
+       pointer_window = canvas_window->get_pointer (x, y, mask);
+
+       if (pointer_window == track_canvas.get_bin_window()) {
+
+               track_canvas.window_to_world (x, y, wx, wy);
+               in_track_canvas = true;
+
+       } else {
+               in_track_canvas = false;
+
+               if (pointer_window == time_canvas.get_bin_window()) {
+                       time_canvas.window_to_world (x, y, wx, wy);
+               } else {
+                       return false;
+               }
+       }
+
+       wx += horizontal_adjustment.get_value();
+       wy += vertical_adjustment.get_value();
+
+       GdkEvent event;
+       event.type = GDK_BUTTON_RELEASE;
+       event.button.x = wx;
+       event.button.y = wy;
+       
+       where = event_frame (&event, 0, 0);
+       return true;
+}
+
+nframes64_t
+Editor::event_frame (GdkEvent* event, double* pcx, double* pcy) const
 {
        double cx, cy;
 
@@ -163,6 +202,53 @@ Editor::mouse_mode_toggled (MouseMode m)
        }
 }      
 
+Gdk::Cursor*
+Editor::which_grabber_cursor ()
+{
+       switch (_edit_point) {
+       case EditAtMouse:
+               return grabber_edit_point_cursor;
+               break;
+       default:
+               return grabber_cursor;
+               break;
+       }
+}
+
+void
+Editor::set_canvas_cursor ()
+{
+       switch (mouse_mode) {
+       case MouseRange:
+               current_canvas_cursor = selector_cursor;
+               break;
+
+       case MouseObject:
+               current_canvas_cursor = which_grabber_cursor();
+               break;
+
+       case MouseGain:
+               current_canvas_cursor = cross_hair_cursor;
+               break;
+
+       case MouseZoom:
+               current_canvas_cursor = zoom_cursor;
+               break;
+
+       case MouseTimeFX:
+               current_canvas_cursor = time_fx_cursor; // just use playhead
+               break;
+
+       case MouseAudition:
+               current_canvas_cursor = speaker_cursor;
+               break;
+       }
+
+       if (is_drawable()) {
+               track_canvas.get_window()->set_cursor(*current_canvas_cursor);
+       }
+}
+
 void
 Editor::set_mouse_mode (MouseMode m, bool force)
 {
@@ -204,7 +290,7 @@ Editor::set_mouse_mode (MouseMode m, bool force)
                }
        }
 
-       /* XXX the hack of unsetting all other buttongs should go 
+       /* XXX the hack of unsetting all other buttons should go 
           away once GTK2 allows us to use regular radio buttons drawn like
           normal buttons, rather than my silly GroupedButton hack.
        */
@@ -214,40 +300,32 @@ Editor::set_mouse_mode (MouseMode m, bool force)
        switch (mouse_mode) {
        case MouseRange:
                mouse_select_button.set_active (true);
-               current_canvas_cursor = selector_cursor;
                break;
 
        case MouseObject:
                mouse_move_button.set_active (true);
-               current_canvas_cursor = grabber_cursor;
                break;
 
        case MouseGain:
                mouse_gain_button.set_active (true);
-               current_canvas_cursor = cross_hair_cursor;
                break;
 
        case MouseZoom:
                mouse_zoom_button.set_active (true);
-               current_canvas_cursor = zoom_cursor;
                break;
 
        case MouseTimeFX:
                mouse_timefx_button.set_active (true);
-               current_canvas_cursor = time_fx_cursor; // just use playhead
                break;
 
        case MouseAudition:
                mouse_audition_button.set_active (true);
-               current_canvas_cursor = speaker_cursor;
                break;
        }
 
        ignore_mouse_mode_toggle = false;
-
-       if (is_drawable()) {
-               track_canvas.get_window()->set_cursor(*current_canvas_cursor);
-       }
+       
+       set_canvas_cursor ();
 }
 
 void
@@ -289,10 +367,6 @@ Editor::step_mouse_mode (bool next)
 void
 Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type)
 {
-       bool commit = false;
-       bool c1; 
-       bool c2;
-
        /* in object/audition/timefx mode, any button press sets
           the selection if the object can be selected. this is a
           bit of hack, because we want to avoid this if the
@@ -303,81 +377,92 @@ 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;
        }
+
+       if (event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) {
+
+               if ((event->button.state & Keyboard::RelevantModifierKeyMask) && event->button.button != 1) {
+                       
+                       /* almost no selection action on modified button-2 or button-3 events */
+               
+                       if (item_type != RegionItem && event->button.button != 2) {
+                               return;
+                       }
+               }
+       }
            
        Selection::Operation op = Keyboard::selection_type (event->button.state);
        bool press = (event->type == GDK_BUTTON_PRESS);
 
-       begin_reversible_command (_("select on click"));
-
+       // begin_reversible_command (_("select on click"));
+       
        switch (item_type) {
        case RegionItem:
-               c1 = set_selected_track_from_click (op, true);
-               c2 = set_selected_regionview_from_click (press, op, true);
-               commit = (c1 || c2);
+               if (mouse_mode != MouseRange) {
+                       set_selected_regionview_from_click (press, op, true);
+               } else if (event->type == GDK_BUTTON_PRESS) {
+                       set_selected_track_as_side_effect ();
+               }
                break;
                
        case RegionViewNameHighlight:
        case RegionViewName:
-               c1 = set_selected_track_from_click (op, true);
-               c2 = set_selected_regionview_from_click (press, op, true);
-               commit = (c1 || c2);
+               if (mouse_mode != MouseRange) {
+                       set_selected_regionview_from_click (press, op, true);
+               } else if (event->type == GDK_BUTTON_PRESS) {
+                       set_selected_track_as_side_effect ();
+               }
+               break;
+
+       case FadeInHandleItem:
+       case FadeInItem:
+       case FadeOutHandleItem:
+       case FadeOutItem:
+               if (mouse_mode != MouseRange) {
+                       set_selected_regionview_from_click (press, op, true);
+               } else if (event->type == GDK_BUTTON_PRESS) {
+                       set_selected_track_as_side_effect ();
+               }
                break;
                
        case GainAutomationControlPointItem:
        case PanAutomationControlPointItem:
        case RedirectAutomationControlPointItem:
-               c1 = set_selected_track_from_click (op, true);
-               c2 = set_selected_control_point_from_click (op, false);
-               commit = (c1 || c2);
+               set_selected_track_as_side_effect ();
+               if (mouse_mode != MouseRange) {
+                       set_selected_control_point_from_click (op, false);
+               }
                break;
                
        case StreamItem:
-               commit = set_selected_track_from_click (op, true);
+               /* for context click or range selection, select track */
+               if (event->button.button == 3) {
+                       set_selected_track_as_side_effect ();
+               } else if (event->type == GDK_BUTTON_PRESS && mouse_mode == MouseRange) {
+                       set_selected_track_as_side_effect ();
+               }
                break;
                    
        case AutomationTrackItem:
-               commit = set_selected_track_from_click (op, true);
+               set_selected_track_as_side_effect (true);
                break;
                
        default:
                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 (op, true);
-                       break;
-
-               default:
-                       break;
-               }
-       }
-#endif
-       if (commit) {
-               commit_reversible_command ();
-       }
 }
 
+const static double ZERO_GAIN_FRACTION = gain_to_slider_position(dB_to_coefficient(0.0));
+
 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()) {
@@ -411,14 +496,12 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                        */
                        
                        switch (item_type) {
-                       case EditCursorItem:
                        case PlayheadCursorItem:
                                start_cursor_grab (item, event);
                                return true;
 
                        case MarkerItem:
-                               if (Keyboard::modifier_state_equals (event->button.state, 
-                                                                    Keyboard::ModifierMask(Keyboard::Control|Keyboard::Shift))) {
+                               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::ModifierMask(Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
                                        hide_marker (item, event);
                                } else {
                                        start_marker_grab (item, event);
@@ -426,7 +509,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                                return true;
 
                        case TempoMarkerItem:
-                               if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) {
+                               if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) {
                                        start_tempo_marker_copy_grab (item, event);
                                } else {
                                        start_tempo_marker_grab (item, event);
@@ -434,7 +517,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                                return true;
 
                        case MeterMarkerItem:
-                               if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) {
+                               if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) {
                                        start_meter_marker_copy_grab (item, event);
                                } else {
                                        start_meter_marker_grab (item, event);
@@ -452,6 +535,11 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                                return true;
                                break;
 
+                       case CdMarkerBarItem:
+                               start_range_markerbar_op (item, event, CreateCDMarker); 
+                               return true;
+                               break;
+
                        case TransportMarkerBarItem:
                                start_range_markerbar_op (item, event, CreateTransportMarker); 
                                return true;
@@ -475,14 +563,13 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
 
                        case SelectionItem:
                                if (Keyboard::modifier_state_contains 
-                                   (event->button.state, Keyboard::ModifierMask(Keyboard::Alt))) {
+                                   (event->button.state, Keyboard::ModifierMask(Keyboard::SecondaryModifier))) {
                                        // contains and not equals because I can't use alt as a modifier alone.
                                        start_selection_grab (item, event);
-                               } else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
+                               } else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
                                        /* grab selection for moving */
                                        start_selection_op (item, event, SelectionMove);
-                               }
-                               else {
+                               } else {
                                        /* this was debated, but decided the more common action was to
                                           make a new selection */
                                        start_selection_op (item, event, CreateSelection);
@@ -496,10 +583,9 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                        break;
                        
                case MouseObject:
-                       if (Keyboard::modifier_state_contains (event->button.state, 
-                                                              Keyboard::ModifierMask(Keyboard::Control|Keyboard::Alt))
-                               && event->type == GDK_BUTTON_PRESS) {
-
+                       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::ModifierMask(Keyboard::PrimaryModifier|Keyboard::SecondaryModifier)) &&
+                           event->type == GDK_BUTTON_PRESS) {
+                               
                                start_rubberband_select (item, event);
 
                        } else if (event->type == GDK_BUTTON_PRESS) {
@@ -514,7 +600,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                                        return true;
 
                                case RegionItem:
-                                       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) {
+                                       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) {
                                                start_region_copy_grab (item, event);
                                        } else if (Keyboard::the_keyboard().key_is_down (GDK_b)) {
                                                start_region_brush_grab (item, event);
@@ -659,7 +745,13 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                        break;
 
                case MouseAudition:
-                       /* handled in release */
+                       _scrubbing = true;
+                       scrub_reversals = 0;
+                       scrub_reverse_distance = 0;
+                       last_scrub_x = event->button.x;
+                       scrubbing_direction = 0;
+                       track_canvas.get_window()->set_cursor (*transparent_cursor);
+                       /* rest handled in motion & release */
                        break;
 
                default:
@@ -673,13 +765,14 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                        if (event->type == GDK_BUTTON_PRESS) {
                                switch (item_type) {
                                case RegionItem:
-                                       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) {
+                                       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) {
                                                start_region_copy_grab (item, event);
                                        } else {
                                                start_region_grab (item, event);
                                        }
-                                       
+                                       return true;
                                        break;
+
                                case GainAutomationControlPointItem:
                                case PanAutomationControlPointItem:
                                case RedirectAutomationControlPointItem:
@@ -719,7 +812,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                                        
                                
                case MouseZoom:
-                       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
+                       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
                                temporal_zoom_session();
                        } else {
                                temporal_zoom_to_frame (true, event_frame(event));
@@ -736,79 +829,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;
 
@@ -821,6 +841,7 @@ bool
 Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type)
 {
        nframes_t where = event_frame (event, 0, 0);
+       AutomationTimeAxisView* atv = 0;
 
        /* no action if we're recording */
                                                
@@ -905,7 +926,8 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
 
                        case MarkerBarItem: 
                        case RangeMarkerBarItem: 
-                       case TransportMarkerBarItem: 
+                       case TransportMarkerBarItem:
+                       case CdMarkerBarItem:
                        case TempoBarItem:
                        case MeterBarItem:
                                popup_ruler_menu (pixel_to_frame(event->button.x), item_type);
@@ -997,7 +1019,6 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
 
                switch (item_type) {
                /* see comments in button_press_handler */
-               case EditCursorItem:
                case PlayheadCursorItem:
                case MarkerItem:
                case GainLineItem:
@@ -1015,6 +1036,14 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                        mouse_add_new_marker (where);
                        return true;
 
+               case CdMarkerBarItem:
+                       // if we get here then a dragged range wasn't done
+                       if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
+                               snap_to (where, 0, true);
+                       }
+                       mouse_add_new_marker (where, true);
+                       return true;
+
                case TempoBarItem:
                        if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
                                snap_to (where);
@@ -1035,14 +1064,14 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                case MouseObject:
                        switch (item_type) {
                        case AutomationTrackItem:
-                               dynamic_cast<AutomationTimeAxisView*>(clicked_trackview)->add_automation_event 
-                                       (item,
-                                        event,
-                                        where,
-                                        event->button.y);
+                               atv = dynamic_cast<AutomationTimeAxisView*>(clicked_trackview);
+                               if (atv) {
+                                       atv->add_automation_event (item, event, where, event->button.y);
+                               }
                                return true;
+                               
                                break;
-
+                               
                        default:
                                break;
                        }
@@ -1050,8 +1079,10 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
 
                case MouseGain:
                        // Gain only makes sense for audio regions
-                       if ( ! dynamic_cast<AudioRegionView*>(clicked_regionview))
+
+                       if (!dynamic_cast<AudioRegionView*>(clicked_regionview)) {
                                break;
+                       }
 
                        switch (item_type) {
                        case RegionItem:
@@ -1070,12 +1101,20 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                        break;
                        
                case MouseAudition:
-                       switch (item_type) {
-                       case RegionItem:
-                               audition_selected_region ();
-                               break;
-                       default:
-                               break;
+                       _scrubbing = false;
+                       track_canvas.get_window()->set_cursor (*current_canvas_cursor);
+                       if (scrubbing_direction == 0) {
+                               /* no drag, just a click */
+                               switch (item_type) {
+                               case RegionItem:
+                                       play_selected_region ();
+                                       break;
+                               default:
+                                       break;
+                               }
+                       } else {
+                               /* make sure we stop */
+                               session->request_transport_speed (0.0);
                        }
                        break;
 
@@ -1094,9 +1133,9 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                case MouseObject:
                        switch (item_type) {
                        case RegionItem:
-                               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Shift)) {
+                               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
                                        raise_region ();
-                               } else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::ModifierMask (Keyboard::Shift|Keyboard::Alt))) {
+                               } else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::ModifierMask (Keyboard::TertiaryModifier|Keyboard::SecondaryModifier))) {
                                        lower_region ();
                                } else {
                                        // Button2 click is unused
@@ -1138,6 +1177,11 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
        Marker * marker;
        double fraction;
        
+       if (last_item_entered != item) {
+               last_item_entered = item;
+               last_item_entered_n = 0;
+       }
+
        switch (item_type) {
        case GainControlPointItem:
                if (mouse_mode == MouseGain) {
@@ -1153,35 +1197,40 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
 
                        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()) {
+                       if (is_drawable() && !_scrubbing) {
                                track_canvas.get_window()->set_cursor (*fader_cursor);
                        }
+
+                       last_item_entered_n++;
+                       set_verbose_canvas_cursor (cp->line.get_verbose_cursor_string (fraction), at_x, at_y);
+                       if (last_item_entered_n < 10) {
+                               show_verbose_canvas_cursor ();
+                       }
                }
                break;
 
        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;
                
@@ -1189,7 +1238,7 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
                if (mouse_mode == MouseGain) {
                        ArdourCanvas::Line *line = dynamic_cast<ArdourCanvas::Line *> (item);
                        if (line)
-                               line->property_fill_color_rgba() = color_map[cEnteredGainLine];
+                               line->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_EnteredGainLine.get();
                        if (is_drawable()) {
                                track_canvas.get_window()->set_cursor (*fader_cursor);
                        }
@@ -1199,13 +1248,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() = ARDOUR_UI::config()->canvasvar_EnteredAutomationLine.get();
+                       }
+                       if (is_drawable()) {
+                               track_canvas.get_window()->set_cursor (*fader_cursor);
+                       }
                }
                break;
                
@@ -1229,10 +1280,16 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
                }
                break;
 
-       case EditCursorItem:
        case PlayheadCursorItem:
                if (is_drawable()) {
-                       track_canvas.get_window()->set_cursor (*grabber_cursor);
+                       switch (_edit_point) {
+                       case EditAtMouse:
+                               track_canvas.get_window()->set_cursor (*grabber_edit_point_cursor);
+                               break;
+                       default:
+                               track_canvas.get_window()->set_cursor (*grabber_cursor);
+                               break;
+                       }
                }
                break;
 
@@ -1276,6 +1333,7 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
        case MarkerBarItem:
        case RangeMarkerBarItem:
        case TransportMarkerBarItem:
+       case CdMarkerBarItem:
        case MeterBarItem:
        case TempoBarItem:
                if (is_drawable()) {
@@ -1287,7 +1345,8 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
                if ((marker = static_cast<Marker *> (item->get_data ("marker"))) == 0) {
                        break;
                }
-               marker->set_color_rgba (color_map[cEnteredMarker]);
+               entered_marker = marker;
+               marker->set_color_rgba (ARDOUR_UI::config()->canvasvar_EnteredMarker.get());
                // fall through
        case MeterMarkerItem:
        case TempoMarkerItem:
@@ -1370,7 +1429,6 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
        case RegionViewNameHighlight:
        case StartSelectionTrimItem:
        case EndSelectionTrimItem:
-       case EditCursorItem:
        case PlayheadCursorItem:
        /* <CMT Additions> */
        case ImageFrameHandleStartItem:
@@ -1409,6 +1467,7 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
 
        case RangeMarkerBarItem:
        case TransportMarkerBarItem:
+       case CdMarkerBarItem:
        case MeterBarItem:
        case TempoBarItem:
        case MarkerBarItem:
@@ -1421,8 +1480,10 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
                if ((marker = static_cast<Marker *> (item->get_data ("marker"))) == 0) {
                        break;
                }
-               loc = find_location_from_marker (marker, is_start);
-               if (loc) location_flags_changed (loc, this);
+               entered_marker = 0;
+               if ((loc = find_location_from_marker (marker, is_start)) != 0) {
+                       location_flags_changed (loc, this);
+               }
                // fall through
        case MeterMarkerItem:
        case TempoMarkerItem:
@@ -1473,18 +1534,20 @@ Editor::left_automation_track ()
 bool
 Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type, bool from_autoscroll)
 {
-       gint x, y;
-       
-       /* We call this so that MOTION_NOTIFY events continue to be
-          delivered to the canvas. We need to do this because we set
-          Gdk::POINTER_MOTION_HINT_MASK on the canvas. This reduces
-          the density of the events, at the expense of a round-trip
-          to the server. Given that this will mostly occur on cases
-          where DISPLAY = :0.0, and given the cost of what the motion
-          event might do, its a good tradeoff.  
-       */
-
-       track_canvas.get_pointer (x, y);
+       if (event->motion.is_hint) {
+               gint x, y;
+               
+               /* We call this so that MOTION_NOTIFY events continue to be
+                  delivered to the canvas. We need to do this because we set
+                  Gdk::POINTER_MOTION_HINT_MASK on the canvas. This reduces
+                  the density of the events, at the expense of a round-trip
+                  to the server. Given that this will mostly occur on cases
+                  where DISPLAY = :0.0, and given the cost of what the motion
+                  event might do, its a good tradeoff.  
+               */
+               
+               track_canvas.get_pointer (x, y);
+       }
 
        if (current_stepping_trackview) {
                /* don't keep the persistent stepped trackview if the mouse moves */
@@ -1498,41 +1561,129 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
        }
 
        drag_info.item_type = item_type;
+       drag_info.last_pointer_x = drag_info.current_pointer_x;
+       drag_info.last_pointer_y = drag_info.current_pointer_y;
        drag_info.current_pointer_frame = event_frame (event, &drag_info.current_pointer_x,
                                                       &drag_info.current_pointer_y);
 
-       if (!from_autoscroll && drag_info.item) {
-               /* item != 0 is the best test i can think of for dragging.
-               */
-               if (!drag_info.move_threshold_passed) {
+       switch (mouse_mode) {
+       case MouseAudition:
+               if (_scrubbing) {
 
-                       drag_info.move_threshold_passed = (abs ((int) (drag_info.current_pointer_x - drag_info.grab_x)) > 4);
-                       
-                       // and change the initial grab loc/frame if this drag info wants us to
+                       double delta;
 
-                       if (drag_info.want_move_threshold && drag_info.move_threshold_passed) {
-                               drag_info.grab_frame = drag_info.current_pointer_frame;
-                               drag_info.grab_x = drag_info.current_pointer_x;
-                               drag_info.grab_y = drag_info.current_pointer_y;
-                               drag_info.last_pointer_frame = drag_info.grab_frame;
-                               drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position;
-                       }
-               }
-       }
+                       if (scrubbing_direction == 0) {
+                               /* first move */
+                               session->request_locate (drag_info.current_pointer_frame, false);
+                               session->request_transport_speed (0.1);
+                               scrubbing_direction = 1;
 
-       switch (item_type) {
-       case PlayheadCursorItem:
-       case EditCursorItem:
-       case MarkerItem:
-       case GainControlPointItem:
-       case RedirectAutomationControlPointItem:
-       case GainAutomationControlPointItem:
-       case PanAutomationControlPointItem:
-       case TempoMarkerItem:
-       case MeterMarkerItem:
-       case RegionViewNameHighlight:
-       case StartSelectionTrimItem:
-       case EndSelectionTrimItem:
+                       } else {
+                               
+                               if (last_scrub_x > drag_info.current_pointer_x) {
+
+                                       /* pointer moved to the left */
+                                       
+                                       if (scrubbing_direction > 0) {
+
+                                               /* we reversed direction to go backwards */
+
+                                               scrub_reversals++;
+                                               scrub_reverse_distance += (int) (last_scrub_x - drag_info.current_pointer_x);
+
+                                       } else {
+
+                                               /* still moving to the left (backwards) */
+                                               
+                                               scrub_reversals = 0;
+                                               scrub_reverse_distance = 0;
+
+                                               delta = 0.01 * (last_scrub_x - drag_info.current_pointer_x);
+                                               session->request_transport_speed (session->transport_speed() - delta);
+                                       }
+                                       
+                               } else {
+                                       /* pointer moved to the right */
+
+                                       if (scrubbing_direction < 0) {
+                                               /* we reversed direction to go forward */
+
+                                               scrub_reversals++;
+                                               scrub_reverse_distance += (int) (drag_info.current_pointer_x - last_scrub_x);
+
+                                       } else {
+                                               /* still moving to the right */
+
+                                               scrub_reversals = 0;
+                                               scrub_reverse_distance = 0;
+                                               
+                                               delta = 0.01 * (drag_info.current_pointer_x - last_scrub_x);
+                                               session->request_transport_speed (session->transport_speed() + delta);
+                                       }
+                               }
+
+                               /* if there have been more than 2 opposite motion moves detected, or one that moves
+                                  back more than 10 pixels, reverse direction
+                               */
+
+                               if (scrub_reversals >= 2 || scrub_reverse_distance > 10) {
+
+                                       if (scrubbing_direction > 0) {
+                                               /* was forwards, go backwards */
+                                               session->request_transport_speed (-0.1);
+                                               scrubbing_direction = -1;
+                                       } else {
+                                               /* was backwards, go forwards */
+                                               session->request_transport_speed (0.1);
+                                               scrubbing_direction = 1;
+                                       }
+                                       
+                                       scrub_reverse_distance = 0;
+                                       scrub_reversals = 0;
+                               }
+                       }
+
+                       last_scrub_x = drag_info.current_pointer_x;
+               }
+
+       default:
+               break;
+       }
+
+       if (!from_autoscroll && drag_info.item) {
+               /* item != 0 is the best test i can think of for dragging.
+               */
+               if (!drag_info.move_threshold_passed) {
+
+                       bool x_threshold_passed =  (::llabs ((nframes64_t) (drag_info.current_pointer_x - drag_info.grab_x)) > 4LL);
+                       bool y_threshold_passed =  (::llabs ((nframes64_t) (drag_info.current_pointer_y - drag_info.grab_y)) > 4LL);
+                       
+                       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
+
+                       if (drag_info.want_move_threshold && drag_info.move_threshold_passed) {
+                               drag_info.grab_frame = drag_info.current_pointer_frame;
+                               drag_info.grab_x = drag_info.current_pointer_x;
+                               drag_info.grab_y = drag_info.current_pointer_y;
+                               drag_info.last_pointer_frame = drag_info.grab_frame;
+                               drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position;
+                       }
+               }
+       }
+
+       switch (item_type) {
+       case PlayheadCursorItem:
+       case MarkerItem:
+       case GainControlPointItem:
+       case RedirectAutomationControlPointItem:
+       case GainAutomationControlPointItem:
+       case PanAutomationControlPointItem:
+       case TempoMarkerItem:
+       case MeterMarkerItem:
+       case RegionViewNameHighlight:
+       case StartSelectionTrimItem:
+       case EndSelectionTrimItem:
        case SelectionItem:
        case GainLineItem:
        case RedirectAutomationLineItem:
@@ -1599,13 +1750,13 @@ Editor::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
        }
 
        if (cursor == 0) {
-               cursor = grabber_cursor;
+               cursor = which_grabber_cursor ();
        }
 
         // if dragging with button2, the motion is x constrained, with Alt-button2 it is y constrained
 
        if (event->button.button == 2) {
-               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Alt)) {
+               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::SecondaryModifier)) {
                        drag_info.y_constrained = true;
                        drag_info.x_constrained = false;
                } else {
@@ -1617,11 +1768,13 @@ Editor::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
                drag_info.y_constrained = false;
        }
 
-       drag_info.grab_frame = event_frame(event, &drag_info.grab_x, &drag_info.grab_y);
+       drag_info.grab_frame = event_frame (event, &drag_info.grab_x, &drag_info.grab_y);
        drag_info.last_pointer_frame = drag_info.grab_frame;
        drag_info.current_pointer_frame = drag_info.grab_frame;
        drag_info.current_pointer_x = drag_info.grab_x;
        drag_info.current_pointer_y = drag_info.grab_y;
+       drag_info.last_pointer_x = drag_info.current_pointer_x;
+       drag_info.last_pointer_y = drag_info.current_pointer_y;
        drag_info.cumulative_x_drag = 0;
        drag_info.cumulative_y_drag = 0;
        drag_info.first_move = true;
@@ -1660,7 +1813,7 @@ Editor::swap_grab (ArdourCanvas::Item* new_item, Gdk::Cursor* cursor, uint32_t t
        drag_info.item = new_item;
 
        if (cursor == 0) {
-               cursor = grabber_cursor;
+               cursor = which_grabber_cursor ();
        }
 
        drag_info.item->grab (Gdk::POINTER_MOTION_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK, *cursor, time);
@@ -1680,6 +1833,8 @@ Editor::end_grab (ArdourCanvas::Item* item, GdkEvent* event)
        drag_info.item->ungrab (event->button.time);
 
        if (drag_info.finished_callback) {
+               drag_info.last_pointer_x = drag_info.current_pointer_x;
+               drag_info.last_pointer_y = drag_info.current_pointer_y;
                (this->*(drag_info.finished_callback)) (item, event);
        }
 
@@ -1706,35 +1861,6 @@ Editor::end_grab (ArdourCanvas::Item* item, GdkEvent* event)
        return did_drag;
 }
 
-void
-Editor::set_edit_cursor (GdkEvent* event)
-{
-       nframes_t pointer_frame = event_frame (event);
-
-       if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
-               if (snap_type != SnapToEditCursor) {
-                       snap_to (pointer_frame);
-               }
-       }
-
-       edit_cursor->set_position (pointer_frame);
-       edit_cursor_clock.set (pointer_frame);
-}
-
-void
-Editor::set_playhead_cursor (GdkEvent* event)
-{
-       nframes_t pointer_frame = event_frame (event);
-
-       if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
-               snap_to (pointer_frame);
-       }
-
-       if (session) {
-               session->request_locate (pointer_frame, session->transport_rolling());
-       }
-}
-
 void
 Editor::start_fade_in_grab (ArdourCanvas::Item* item, GdkEvent* event)
 {
@@ -1761,7 +1887,7 @@ Editor::fade_in_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
        nframes_t pos;
        nframes_t fade_length;
 
-       if ((long)drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
+       if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
                pos = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
        }
        else {
@@ -1771,16 +1897,26 @@ Editor::fade_in_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
        if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
                snap_to (pos);
        }
-       
+
        if (pos < (arv->region()->position() + 64)) {
                fade_length = 64; // this should be a minimum defined somewhere
        } else if (pos > arv->region()->last_frame()) {
                fade_length = arv->region()->length();
        } else {
                fade_length = pos - arv->region()->position();
-       }
+       }               
+       /* mapover the region selection */
+
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+
+               AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (*i);
+               
+               if (!tmp) {
+                       continue;
+               }
        
-       arv->reset_fade_in_shape_width (fade_length);
+               tmp->reset_fade_in_shape_width (fade_length);
+       }
 
        show_verbose_duration_cursor (arv->region()->position(),  arv->region()->position() + fade_length, 10);
 
@@ -1790,43 +1926,47 @@ Editor::fade_in_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 void
 Editor::fade_in_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
 {
-       if (drag_info.first_move) return;
-
        AudioRegionView* arv = static_cast<AudioRegionView*>(drag_info.data);
        nframes_t pos;
        nframes_t fade_length;
 
-       if ((long)drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
+       if (drag_info.first_move) return;
+
+       if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
                pos = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
-       }
-       else {
+       } else {
                pos = 0;
        }
 
-       if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
-               snap_to (pos);
-       }
-
        if (pos < (arv->region()->position() + 64)) {
                fade_length = 64; // this should be a minimum defined somewhere
-       }
-       else if (pos > arv->region()->last_frame()) {
+       } else if (pos > arv->region()->last_frame()) {
                fade_length = arv->region()->length();
-       }
-       else {
+       } else {
                fade_length = pos - arv->region()->position();
        }
-
+               
        begin_reversible_command (_("change fade in length"));
-       AutomationList& alist = arv->audio_region()->fade_in();
-        XMLNode &before = alist.get_state();
 
-       arv->audio_region()->set_fade_in_length (fade_length);
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+
+               AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (*i);
+               
+               if (!tmp) {
+                       continue;
+               }
+       
+               AutomationList& alist = tmp->audio_region()->fade_in();
+               XMLNode &before = alist.get_state();
+
+               tmp->audio_region()->set_fade_in_length (fade_length);
+               tmp->audio_region()->set_fade_in_active (true);
+               
+               XMLNode &after = alist.get_state();
+               session->add_command(new MementoCommand<AutomationList>(alist, &before, &after));
+       }
 
-        XMLNode &after = alist.get_state();
-        session->add_command(new MementoCommand<AutomationList>(alist, &before, &after));
        commit_reversible_command ();
-       fade_in_drag_motion_callback (item, event);
 }
 
 void
@@ -1855,17 +1995,16 @@ Editor::fade_out_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event
        nframes_t pos;
        nframes_t fade_length;
 
-       if ((long)drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
+       if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
                pos = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
-       }
-       else {
+       } else {
                pos = 0;
        }
 
        if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
                snap_to (pos);
        }
-
+       
        if (pos > (arv->region()->last_frame() - 64)) {
                fade_length = 64; // this should really be a minimum fade defined somewhere
        }
@@ -1875,8 +2014,19 @@ Editor::fade_out_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event
        else {
                fade_length = arv->region()->last_frame() - pos;
        }
+               
+       /* mapover the region selection */
+
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+
+               AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (*i);
+               
+               if (!tmp) {
+                       continue;
+               }
        
-       arv->reset_fade_out_shape_width (fade_length);
+               tmp->reset_fade_out_shape_width (fade_length);
+       }
 
        show_verbose_duration_cursor (arv->region()->last_frame() - fade_length, arv->region()->last_frame(), 10);
 
@@ -1892,7 +2042,7 @@ Editor::fade_out_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* eve
        nframes_t pos;
        nframes_t fade_length;
 
-       if ((long)drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
+       if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
                pos = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
        }
        else {
@@ -1914,16 +2064,26 @@ Editor::fade_out_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* eve
        }
 
        begin_reversible_command (_("change fade out length"));
-       AutomationList& alist = arv->audio_region()->fade_out();
-        XMLNode &before = alist.get_state();
 
-       arv->audio_region()->set_fade_out_length (fade_length);
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
 
-        XMLNode &after = alist.get_state();
-        session->add_command(new MementoCommand<AutomationList>(alist, &before, &after));
-       commit_reversible_command ();
+               AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (*i);
+               
+               if (!tmp) {
+                       continue;
+               }
+       
+               AutomationList& alist = tmp->audio_region()->fade_out();
+               XMLNode &before = alist.get_state();
+               
+               tmp->audio_region()->set_fade_out_length (fade_length);
+               tmp->audio_region()->set_fade_out_active (true);
 
-       fade_out_drag_motion_callback (item, event);
+               XMLNode &after = alist.get_state();
+               session->add_command(new MementoCommand<AutomationList>(alist, &before, &after));
+       }
+
+       commit_reversible_command ();
 }
 
 void
@@ -1942,10 +2102,16 @@ Editor::start_cursor_grab (ArdourCanvas::Item* item, GdkEvent* event)
 
        Cursor* cursor = (Cursor *) drag_info.data;
 
-       if (session && cursor == playhead_cursor) {
-               if (drag_info.was_rolling) {
+       if (cursor == playhead_cursor) {
+               _dragging_playhead = true;
+               
+               if (session && drag_info.was_rolling) {
                        session->request_stop ();
-               } 
+               }
+
+               if (session && session->is_auditioning()) {
+                       session->cancel_audition ();
+               }
        }
 
        drag_info.pointer_frame_offset = drag_info.grab_frame - cursor->current_frame;  
@@ -1959,7 +2125,7 @@ Editor::cursor_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
        Cursor* cursor = (Cursor *) drag_info.data;
        nframes_t adjusted_frame;
        
-       if ((long)drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
+       if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
                adjusted_frame = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
        }
        else {
@@ -1967,7 +2133,7 @@ Editor::cursor_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
        }
        
        if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
-               if (cursor != edit_cursor || snap_type != SnapToEditCursor) {
+               if (cursor == playhead_cursor) {
                        snap_to (adjusted_frame);
                }
        }
@@ -1976,9 +2142,7 @@ Editor::cursor_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
        cursor->set_position (adjusted_frame);
        
-       if (cursor == edit_cursor) {
-               edit_cursor_clock.set (cursor->current_frame);
-       }
+       UpdateAllTransportClocks (cursor->current_frame);
 
        show_verbose_time_cursor (cursor->current_frame, 10);
 
@@ -1992,14 +2156,13 @@ Editor::cursor_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
        if (drag_info.first_move) return;
        
        cursor_drag_motion_callback (item, event);
+
+       _dragging_playhead = false;
        
        if (item == &playhead_cursor->canvas_item) {
                if (session) {
                        session->request_locate (playhead_cursor->current_frame, drag_info.was_rolling);
                }
-       } else if (item == &edit_cursor->canvas_item) {
-               edit_cursor->set_position (edit_cursor->current_frame);
-               edit_cursor_clock.set (edit_cursor->current_frame);
        } 
 }
 
@@ -2041,22 +2204,43 @@ Editor::start_marker_grab (ArdourCanvas::Item* item, GdkEvent* event)
 
        start_grab (event);
 
+       _dragging_edit_point = true;
+
        drag_info.copied_location = new Location (*location);
        drag_info.pointer_frame_offset = drag_info.grab_frame - (is_start ? location->start() : location->end());       
 
        update_marker_drag_item (location);
 
        if (location->is_mark()) {
-               marker_drag_line->show();
-               marker_drag_line->raise_to_top();
-       }
-       else {
+               // marker_drag_line->show();
+               // marker_drag_line->raise_to_top();
+       } else {
                range_marker_drag_rect->show();
                range_marker_drag_rect->raise_to_top();
        }
-       
-       if (is_start) show_verbose_time_cursor (location->start(), 10);
-       else show_verbose_time_cursor (location->end(), 10);
+
+       if (is_start) {
+               show_verbose_time_cursor (location->start(), 10);
+       } else {
+               show_verbose_time_cursor (location->end(), 10);
+       }
+
+       Selection::Operation op = Keyboard::selection_type (event->button.state);
+
+       switch (op) {
+       case Selection::Toggle:
+               selection->toggle (marker);
+               break;
+       case Selection::Set:
+               selection->set (marker);
+               break;
+       case Selection::Extend:
+               selection->add (marker);
+               break;
+       case Selection::Add:
+               selection->add (marker);
+               break;
+       }
 }
 
 void
@@ -2069,12 +2253,10 @@ Editor::marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
        bool is_start;
        bool move_both = false;
 
-
        nframes_t newframe;
-       if (drag_info.pointer_frame_offset <= (long) drag_info.current_pointer_frame) {
+       if (drag_info.pointer_frame_offset <= drag_info.current_pointer_frame) {
                newframe = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
-       }
-       else {
+       } else {
                newframe = 0;
        }
 
@@ -2090,7 +2272,13 @@ Editor::marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
        /* call this to find out if its the start or end */
        
-       real_location = find_location_from_marker (marker, is_start);
+       if ((real_location = find_location_from_marker (marker, is_start)) == 0) {
+               return;
+       }
+
+       if (real_location->locked()) {
+               return;
+       }
 
        /* use the copy that we're "dragging" around */
        
@@ -2098,7 +2286,7 @@ Editor::marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
        f_delta = copy_location->end() - copy_location->start();
        
-       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
+       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
                move_both = true;
        }
 
@@ -2145,7 +2333,8 @@ Editor::marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
        LocationMarkers* lm = find_location_markers (real_location);
        lm->set_position (copy_location->start(), copy_location->end());
-       
+       edit_point_clock.set (copy_location->start());
+
        show_verbose_time_cursor (newframe, 10);
 }
 
@@ -2156,17 +2345,23 @@ Editor::marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
                marker_drag_motion_callback (item, event);
 
        }
+
+       _dragging_edit_point = false;
        
        Marker* marker = (Marker *) drag_info.data;
        bool is_start;
 
-
        begin_reversible_command ( _("move marker") );
        XMLNode &before = session->locations()->get_state();
        
        Location * location = find_location_from_marker (marker, is_start);
-       
+
        if (location) {
+
+               if (location->locked()) {
+                       return;
+               }
+
                if (location->is_mark()) {
                        location->set_start (drag_info.copied_location->start());
                } else {
@@ -2202,6 +2397,7 @@ Editor::start_meter_marker_grab (ArdourCanvas::Item* item, GdkEvent* event)
        }
 
        drag_info.item = item;
+       drag_info.copy = false;
        drag_info.data = marker;
        drag_info.motion_callback = &Editor::meter_marker_drag_motion_callback;
        drag_info.finished_callback = &Editor::meter_marker_drag_finished_callback;
@@ -2230,7 +2426,7 @@ Editor::start_meter_marker_copy_grab (ArdourCanvas::Item* item, GdkEvent* event)
        // The actual copying is not done before we reach the finish callback.
        char name[64];
        snprintf (name, sizeof(name), "%g/%g", meter_marker->meter().beats_per_bar(), meter_marker->meter().note_divisor ());
-       MeterMarker* new_marker = new MeterMarker(*this, *meter_group, color_map[cMeterMarker], name, 
+       MeterMarker* new_marker = new MeterMarker(*this, *meter_group, ARDOUR_UI::config()->canvasvar_MeterMarker.get(), name, 
                                                  *new MeterSection(meter_marker->meter()));
 
        drag_info.item = &new_marker->the_item();
@@ -2252,7 +2448,7 @@ Editor::meter_marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* e
        MeterMarker* marker = (MeterMarker *) drag_info.data;
        nframes_t adjusted_frame;
 
-       if ((long)drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
+       if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
                adjusted_frame = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
        }
        else {
@@ -2331,6 +2527,7 @@ Editor::start_tempo_marker_grab (ArdourCanvas::Item* item, GdkEvent* event)
        }
 
        drag_info.item = item;
+       drag_info.copy = false;
        drag_info.data = marker;
        drag_info.motion_callback = &Editor::tempo_marker_drag_motion_callback;
        drag_info.finished_callback = &Editor::tempo_marker_drag_finished_callback;
@@ -2361,7 +2558,7 @@ Editor::start_tempo_marker_copy_grab (ArdourCanvas::Item* item, GdkEvent* event)
        // The actual copying is not done before we reach the finish callback.
        char name[64];
        snprintf (name, sizeof (name), "%.2f", tempo_marker->tempo().beats_per_minute());
-       TempoMarker* new_marker = new TempoMarker(*this, *tempo_group, color_map[cTempoMarker], name, 
+       TempoMarker* new_marker = new TempoMarker(*this, *tempo_group, ARDOUR_UI::config()->canvasvar_TempoMarker.get(), name, 
                                                  *new TempoSection(tempo_marker->tempo()));
 
        drag_info.item = &new_marker->the_item();
@@ -2383,7 +2580,7 @@ Editor::tempo_marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* e
        TempoMarker* marker = (TempoMarker *) drag_info.data;
        nframes_t adjusted_frame;
        
-       if ((long)drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
+       if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
                adjusted_frame = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
        }
        else {
@@ -2489,6 +2686,16 @@ Editor::start_control_point_grab (ArdourCanvas::Item* item, GdkEvent* event)
 
        start_grab (event, fader_cursor);
 
+       // start the grab at the center of the control point so
+       // the point doesn't 'jump' to the mouse after the first drag
+       drag_info.grab_x = control_point->get_x();
+       drag_info.grab_y = control_point->get_y();
+       control_point->line.parent_group().i2w(drag_info.grab_x, drag_info.grab_y);
+       track_canvas.w2c(drag_info.grab_x, drag_info.grab_y,
+                                                                        drag_info.grab_x, drag_info.grab_y);
+
+       drag_info.grab_frame = pixel_to_frame(drag_info.grab_x);
+
        control_point->line.start_drag (control_point, drag_info.grab_frame, 0);
 
        float fraction = 1.0 - (control_point->get_y() / control_point->line.height());
@@ -2503,11 +2710,28 @@ Editor::control_point_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent*
 {
        ControlPoint* cp = reinterpret_cast<ControlPoint *> (drag_info.data);
 
-       double cx = drag_info.current_pointer_x;
-       double cy = drag_info.current_pointer_y;
+       double dx = drag_info.current_pointer_x - drag_info.last_pointer_x;
+       double dy = drag_info.current_pointer_y - drag_info.last_pointer_y;
 
-       drag_info.cumulative_x_drag = cx - drag_info.grab_x ;
-       drag_info.cumulative_y_drag = cy - drag_info.grab_y ;
+       if (event->button.state & Keyboard::SecondaryModifier) {
+               dx *= 0.1;
+               dy *= 0.1;
+       }
+
+       double cx = drag_info.grab_x + drag_info.cumulative_x_drag + dx;
+       double cy = drag_info.grab_y + drag_info.cumulative_y_drag + dy;
+
+       // calculate zero crossing point. back off by .01 to stay on the
+       // positive side of zero
+       double _unused = 0;
+       double zero_gain_y = (1.0 - ZERO_GAIN_FRACTION) * cp->line.height() - .01;
+       cp->line.parent_group().i2w(_unused, zero_gain_y);
+
+       // make sure we hit zero when passing through
+       if ((cy < zero_gain_y and (cy - dy) > zero_gain_y)
+                       or (cy > zero_gain_y and (cy - dy) < zero_gain_y)) {
+               cy = zero_gain_y;
+       }
 
        if (drag_info.x_constrained) {
                cx = drag_info.grab_x;
@@ -2516,6 +2740,9 @@ Editor::control_point_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent*
                cy = drag_info.grab_y;
        }
 
+       drag_info.cumulative_x_drag = cx - drag_info.grab_x;
+       drag_info.cumulative_y_drag = cy - drag_info.grab_y;
+
        cp->line.parent_group().w2i (cx, cy);
 
        cx = max (0.0, cx);
@@ -2530,10 +2757,10 @@ Editor::control_point_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent*
        }
 
        float fraction = 1.0 - (cy / cp->line.height());
-       
+
        bool push;
 
-       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) {
+       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier)) {
                push = true;
        } else {
                push = false;
@@ -2555,7 +2782,7 @@ Editor::control_point_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent
 
                /* just a click */
                
-               if ((event->type == GDK_BUTTON_RELEASE) && (event->button.button == 1) && Keyboard::modifier_state_equals (event->button.state, Keyboard::Shift)) {
+               if ((event->type == GDK_BUTTON_RELEASE) && (event->button.button == 1) && Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
                        reset_point_selection ();
                }
 
@@ -2633,17 +2860,41 @@ void
 Editor::line_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 {
        AutomationLine* line = reinterpret_cast<AutomationLine *> (drag_info.data);
+
+       double dy = drag_info.current_pointer_y - drag_info.last_pointer_y;
+
+       if (event->button.state & Keyboard::SecondaryModifier) {
+               dy *= 0.1;
+       }
+
        double cx = drag_info.current_pointer_x;
-       double cy = drag_info.current_pointer_y;
+       double cy = drag_info.grab_y + drag_info.cumulative_y_drag + dy;
+
+       // calculate zero crossing point. back off by .01 to stay on the
+       // positive side of zero
+       double _unused = 0;
+       double zero_gain_y = (1.0 - ZERO_GAIN_FRACTION) * line->height() - .01;
+       line->parent_group().i2w(_unused, zero_gain_y);
+
+       // make sure we hit zero when passing through
+       if ((cy < zero_gain_y and (cy - dy) > zero_gain_y)
+                       or (cy > zero_gain_y and (cy - dy) < zero_gain_y)) {
+               cy = zero_gain_y;
+       }
+
+       drag_info.cumulative_y_drag = cy - drag_info.grab_y;
 
        line->parent_group().w2i (cx, cy);
-       
+
+       cy = max (0.0, cy);
+       cy = min ((double) line->height(), cy);
+
        double fraction;
        fraction = 1.0 - (cy / line->height());
 
        bool push;
 
-       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) {
+       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier)) {
                push = false;
        } else {
                push = true;
@@ -2672,8 +2923,14 @@ Editor::start_region_grab (ArdourCanvas::Item* item, GdkEvent* event)
        drag_info.copy = false;
        drag_info.item = item;
        drag_info.data = clicked_regionview;
-       drag_info.motion_callback = &Editor::region_drag_motion_callback;
-       drag_info.finished_callback = &Editor::region_drag_finished_callback;
+
+       if (Config->get_edit_mode() == Splice) {
+               drag_info.motion_callback = &Editor::region_drag_splice_motion_callback;
+               drag_info.finished_callback = &Editor::region_drag_splice_finished_callback;
+       } else {
+               drag_info.motion_callback = &Editor::region_drag_motion_callback;
+               drag_info.finished_callback = &Editor::region_drag_finished_callback;
+       }
 
        start_grab (event);
 
@@ -2724,12 +2981,13 @@ Editor::start_region_copy_grab (ArdourCanvas::Item* item, GdkEvent* event)
        drag_info.want_move_threshold = true;
        drag_info.motion_callback = &Editor::region_drag_motion_callback;
        drag_info.finished_callback = &Editor::region_drag_finished_callback;
+       show_verbose_time_cursor (drag_info.last_frame_position, 10);
 }
 
 void
 Editor::start_region_brush_grab (ArdourCanvas::Item* item, GdkEvent* event)
 {
-       if (selection->regions.empty() || clicked_regionview == 0) {
+       if (selection->regions.empty() || clicked_regionview == 0 || Config->get_edit_mode() == Splice) {
                return;
        }
 
@@ -2760,108 +3018,166 @@ Editor::start_region_brush_grab (ArdourCanvas::Item* item, GdkEvent* event)
 }
 
 void
-Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
+Editor::possibly_copy_regions_during_grab (GdkEvent* event)
 {
-       double x_delta;
-       double y_delta = 0;
-       RegionView* rv = reinterpret_cast<RegionView*> (drag_info.data); 
-       nframes_t pending_region_position = 0;
-       int32_t pointer_y_span = 0, canvas_pointer_y_span = 0, original_pointer_order;
-       int32_t visible_y_high = 0, visible_y_low = 512;  //high meaning higher numbered.. not the height on the screen
-       bool clamp_y_axis = false;
-       vector<int32_t>  height_list(512) ;
-       vector<int32_t>::iterator j;
-
-       show_verbose_time_cursor (drag_info.last_frame_position, 10);
-
        if (drag_info.copy && drag_info.move_threshold_passed && drag_info.want_move_threshold) {
 
                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<Playlist*> affected_playlists;
-               pair<set<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);
+
                        
-                       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));
+                       if ((arv = dynamic_cast<AudioRegionView*>(rv)) == 0) {
+                               /* XXX handle MIDI here */
+                               continue;
                        }
-                       
-                       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);
-                       }
-                       assert(newregion != 0);
+                       nrv = new AudioRegionView (*arv);
+                       nrv->get_canvas_group()->show ();
 
-                       /* 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);
-                       }
+                       new_regionviews.push_back (nrv);
                }
-               
+
                if (new_regionviews.empty()) {
                        return;
                }
-               
+
                /* reset selection to new regionviews */
                
                selection->set (new_regionviews);
-               
+
                /* 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);
        }
+}
+
+bool
+Editor::check_region_drag_possible (AudioTimeAxisView** tv)
+{
+       /* Which trackview is this ? */
+
+       TimeAxisView* tvp = trackview_by_y_position (drag_info.current_pointer_y);
+       (*tv) = dynamic_cast<AudioTimeAxisView*>(tvp);
+
+       /* The region motion is only processed if the pointer is over
+          an audio track.
+       */
+       
+       if (!(*tv) || !(*tv)->is_audio_track()) {
+               /* To make sure we hide the verbose canvas cursor when the mouse is 
+                  not held over and audiotrack. 
+               */
+               hide_verbose_canvas_cursor ();
+               return false;
+       }
+       
+       return true;
+}
+
+struct RegionSelectionByPosition {
+    bool operator() (RegionView*a, RegionView* b) {
+           return a->region()->position () < b->region()->position();
+    }
+};
+
+void
+Editor::region_drag_splice_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
+{
+       AudioTimeAxisView* tv;
+       
+       if (!check_region_drag_possible (&tv)) {
+               return;
+       }
+
+       if (!drag_info.move_threshold_passed) {
+               return;
+       }
+
+       int dir;
+
+       if (drag_info.current_pointer_x - drag_info.grab_x > 0) {
+               dir = 1;
+       } else {
+               dir = -1;
+       }
+
+       RegionSelection copy (selection->regions);
+
+       RegionSelectionByPosition cmp;
+       copy.sort (cmp);
+
+       for (RegionSelection::iterator i = copy.begin(); i != copy.end(); ++i) {
+
+               AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&(*i)->get_time_axis_view());
+
+               if (!atv) {
+                       continue;
+               }
+
+               boost::shared_ptr<Playlist> playlist;
+
+               if ((playlist = atv->playlist()) == 0) {
+                       continue;
+               }
+
+               if (!playlist->region_is_shuffle_constrained ((*i)->region())) {
+                       continue;
+               } 
+
+               if (dir > 0) {
+                       if (drag_info.current_pointer_frame < (*i)->region()->last_frame() + 1) {
+                               continue;
+                       }
+               } else {
+                       if (drag_info.current_pointer_frame > (*i)->region()->first_frame()) {
+                               continue;
+                       }
+               }
+
+               
+               playlist->shuffle ((*i)->region(), dir);
+
+               drag_info.grab_x = drag_info.current_pointer_x;
+       }
+}
 
-       /* Which trackview is this ? */
+void
+Editor::region_drag_splice_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
+{
+}
 
-       TimeAxisView* tvp = trackview_by_y_position (drag_info.current_pointer_y);
-       AudioTimeAxisView* tv = dynamic_cast<AudioTimeAxisView*>(tvp);
+void
+Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
+{
+       double x_delta;
+       double y_delta = 0;
+       RegionView* rv = reinterpret_cast<RegionView*> (drag_info.data); 
+       nframes_t pending_region_position = 0;
+       int32_t pointer_y_span = 0, canvas_pointer_y_span = 0, original_pointer_order;
+       int32_t visible_y_high = 0, visible_y_low = 512;  //high meaning higher numbered.. not the height on the screen
+       bool clamp_y_axis = false;
+       vector<int32_t>  height_list(512) ;
+       vector<int32_t>::iterator j;
+       AudioTimeAxisView* tv;
 
-       /* The region motion is only processed if the pointer is over
-          an audio track.
-       */
-       
-       if (!tv || !tv->is_audio_track()) {
-               /* To make sure we hide the verbose canvas cursor when the mouse is 
-                  not held over and audiotrack. 
-               */
-               hide_verbose_canvas_cursor ();
+       possibly_copy_regions_during_grab (event);
+
+       if (!check_region_drag_possible (&tv)) {
                return;
        }
-       
+
        original_pointer_order = drag_info.last_trackview->order;
                
        /************************************************************
@@ -2873,7 +3189,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                pointer_y_span = 0;
                goto y_axis_done;
        }
-       
+
        if ((pointer_y_span = (drag_info.last_trackview->order - tv->order)) != 0) {
 
                int32_t children = 0, numtracks = 0;
@@ -3027,30 +3343,34 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
           the region would be if we moved it by that much.
        */
 
-       if (drag_info.move_threshold_passed) {
+       if ( drag_info.move_threshold_passed ) {
 
-               if ((int32_t)drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
+               if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
 
                        nframes_t sync_frame;
                        nframes_t sync_offset;
                        int32_t sync_dir;
-           
+
                        pending_region_position = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
-           
+
                        sync_offset = rv->region()->sync_offset (sync_dir);
-                       sync_frame = rv->region()->adjust_to_sync (pending_region_position);
 
-                       /* we snap if the snap modifier is not enabled.
+                       /* we don't handle a sync point that lies before zero.
                         */
+                       if (sync_dir >= 0 || (sync_dir < 0 && pending_region_position >= sync_offset)) {
+                               sync_frame = pending_region_position + (sync_dir*sync_offset);
+
+                               /* we snap if the snap modifier is not enabled.
+                                */
            
-                       if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
-                               snap_to (sync_frame);   
-                       }
+                               if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
+                                       snap_to (sync_frame);   
+                               }
            
-                       if (sync_frame - sync_offset <= sync_frame) {
-                               pending_region_position = sync_frame - (sync_dir*sync_offset);
+                               pending_region_position = rv->region()->adjust_to_sync (sync_frame);
+
                        } else {
-                               pending_region_position = 0;
+                               pending_region_position = drag_info.last_frame_position;
                        }
            
                } else {
@@ -3063,18 +3383,19 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
          
                // printf ("3: pending_region_position= %lu    %lu\n", pending_region_position, drag_info.last_frame_position );
          
-               if (pending_region_position != drag_info.last_frame_position && !drag_info.x_constrained) {
+               bool x_move_allowed = ( !drag_info.x_constrained && (Config->get_edit_mode() != Lock)) || ( drag_info.x_constrained && (Config->get_edit_mode() == Lock)) ;
+               if ( pending_region_position != drag_info.last_frame_position && x_move_allowed ) {
 
-                       /* now compute the canvas unit distance we need to move the regiondrag_info.last_trackview->order
+                       /* now compute the canvas unit distance we need to move the regionview
                           to make it appear at the new location.
                        */
-           
+
                        if (pending_region_position > drag_info.last_frame_position) {
                                x_delta = ((double) (pending_region_position - drag_info.last_frame_position) / frames_per_unit);
                        } else {
                                x_delta = -((double) (drag_info.last_frame_position - pending_region_position) / frames_per_unit);
                        }
-           
+
                        drag_info.last_frame_position = pending_region_position;
            
                } else {
@@ -3086,7 +3407,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
                x_delta = 0;
        }
-
+       
        /*************************************************************
                         PREPARE TO MOVE
        ************************************************************/
@@ -3098,6 +3419,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                return;
        } 
 
+
        if (x_delta < 0) {
                for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) {
 
@@ -3120,148 +3442,147 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                         MOTION                                                               
        ************************************************************/
 
-       pair<set<Playlist*>::iterator,bool> insert_result;
-       const list<RegionView*>& layered_regions = selection->regions.by_layer();
+       bool do_move;
 
-       for (list<RegionView*>::const_iterator i = layered_regions.begin(); i != layered_regions.end(); ++i) {
+       if (drag_info.first_move) {
+               if (drag_info.move_threshold_passed) {
+                       do_move = true;
+               } else {
+                       do_move = false;
+               }
+       } else {
+               do_move = true;
+       }
+
+       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();
+                               rv->fake_set_opaque (true);
+                       }
 
-                       /* freeze the playlists from notifying till
-                          the motion is done.
-                       */
+                       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()) {
-                               AudioPlaylist* pl = dynamic_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));
-                                       }
-                               }
-                       }
-               }
+       } /* 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
@@ -3269,12 +3590,13 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
 {
        nframes_t where;
        RegionView* rv = reinterpret_cast<RegionView *> (drag_info.data);
-       pair<set<Playlist*>::iterator,bool> insert_result;
+       pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
        bool nocommit = true;
        double speed;
        RouteTimeAxisView* atv;
        bool regionview_y_movement;
        bool regionview_x_movement;
+       vector<RegionView*> copies;
 
        /* first_move is set to false if the regionview has been moved in the 
           motion handler. 
@@ -3293,8 +3615,20 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
 
        region_drag_motion_callback (item, event);
 
+       if (Config->get_edit_mode() == Splice && !pre_drag_region_selection.empty()) {
+               selection->set (pre_drag_region_selection);
+               pre_drag_region_selection.clear ();
+       }
+
        if (drag_info.brushing) {
                /* all changes were made during motion event handlers */
+               
+               if (drag_info.copy) {
+                       for (list<RegionView*>::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+                               copies.push_back (*i);
+                       }
+               }
+
                goto out;
        }
 
@@ -3312,104 +3646,128 @@ 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()); 
        
-       if (regionview_y_movement) {
+       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");
+               }
+       }
 
-               /* motion between tracks */
+       begin_reversible_command (op_string);
+
+       if (regionview_y_movement) {
 
-               list<RegionView*> new_selection;
-       
                /* moved to a different audio track. */
+               
+               vector<RegionView*> new_selection;
 
                for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ) {
-           
-                       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++;
-               }
-
-               /* first, freeze the target tracks */
-
-               for (list<RegionView*>::const_iterator i = new_selection.begin(); i != new_selection.end();i++ ) {
+                       
+                       RegionView* rv = (*i);              
 
-                       Playlist* from_playlist;
-                       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);
-           
-                       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));
-                       }
+                       boost::shared_ptr<Playlist> from_playlist = rv->region()->playlist();
+                       boost::shared_ptr<Playlist> to_playlist = atv2->playlist();
 
-               }
+                       where = (nframes_t) (unit_to_frame (ix1) * speed);
+                       boost::shared_ptr<Region> new_region (RegionFactory::create (rv->region()));
 
-               /* now do it again with the actual operations */
+                       /* undo the previous hide_dependent_views so that xfades don't
+                          disappear on copying regions 
+                       */
 
-               for (list<RegionView*>::const_iterator i = new_selection.begin(); i != new_selection.end();i++ ) {
+                       rv->get_time_axis_view().reveal_dependent_views (*rv);
 
-                       Playlist* from_playlist;
-                       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()));    
+
+                       } else {
+
+                               /* the regionview we dragged around is a temporary copy, queue it for deletion */
+                               
+                               copies.push_back (rv);
+                       }
 
-                       from_playlist->remove_region (((*i)->region()));
+                       latest_regionviews.clear ();
                        
                        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 (!latest_regionviews.empty()) {
+                               new_selection.insert (new_selection.end(), latest_regionviews.begin(), latest_regionviews.end());
+                       }
+
+                       /* OK, this is where it gets tricky. If the playlist was being used by >1 tracks, and the region
+                          was selected in all of them, then removing it from the playlist will have removed all
+                          trace of it from the selection (i.e. there were N regions selected, we removed 1,
+                          but since its the same playlist for N tracks, all N tracks updated themselves, removed the
+                          corresponding regionview, and the selection is now empty).
+
+                          this could have invalidated any and all iterators into the region selection.
+
+                          the heuristic we use here is: if the region selection is empty, break out of the loop
+                          here. if the region selection is not empty, then restart the loop because we know that
+                          we must have removed at least the region(view) we've just been working on as well as any
+                          that we processed on previous iterations.
+
+                          EXCEPT .... if we are doing a copy drag, then the selection hasn't been modified and
+                          we can just iterate.
+                       */
+
+                       if (drag_info.copy) {
+                               ++i;
+                       } else {
+                               if (selection->regions.empty()) {
+                                       break;
+                               } else { 
+                                       i = selection->regions.by_layer().begin();
+                               }
                        }
                } 
 
+               selection->set (new_selection);
+
        } 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);
 
@@ -3417,9 +3775,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();
@@ -3438,25 +3797,70 @@ 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);
+                       assert (to_playlist);
+
+                       /* 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_regionviews.clear ();
+                               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_regionviews.empty()) {
+                                       // XXX why just the first one ? we only expect one
+                                       atv->reveal_dependent_views (*latest_regionviews.front());
+                                       selection->add (latest_regionviews);
+                               }
+                               
+                               /* 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()));
+
+                       if (drag_info.copy) {
+                               copies.push_back (rv);
+                       }
                }
        }
 
   out:
-       for (set<Playlist*>::iterator p = motion_frozen_playlists.begin(); p != motion_frozen_playlists.end(); ++p) {
-               (*p)->thaw ();
-               session->add_command (new MementoCommand<Playlist>(*(*p), 0, & (*p)->get_state()));
-       }
-
-       motion_frozen_playlists.clear ();
-
+       
        if (!nocommit) {
                commit_reversible_command ();
        }
+
+       for (vector<RegionView*>::iterator x = copies.begin(); x != copies.end(); ++x) {
+               delete *x;
+       }
 }
 
 void
@@ -3466,7 +3870,7 @@ Editor::region_view_item_click (AudioRegionView& rv, GdkEventButton* event)
           this is an alignment click (control used)
        */
        
-       if (Keyboard::modifier_state_contains (event->state, Keyboard::Control)) {
+       if (Keyboard::modifier_state_contains (event->state, Keyboard::PrimaryModifier)) {
                TimeAxisView* tv = &rv.get_time_axis_view();
                AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(tv);
                double speed = 1.0;
@@ -3474,17 +3878,22 @@ Editor::region_view_item_click (AudioRegionView& rv, GdkEventButton* event)
                        speed = atv->get_diskstream()->speed();
                }
 
-               if (Keyboard::modifier_state_equals (event->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Alt))) {
-
-                       align_region (rv.region(), SyncPoint, (nframes_t) (edit_cursor->current_frame * speed));
+               nframes64_t where = get_preferred_edit_position();
 
-               } else if (Keyboard::modifier_state_equals (event->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) {
+               if (where >= 0) {
 
-                       align_region (rv.region(), End, (nframes_t) (edit_cursor->current_frame * speed));
-
-               } else {
-
-                       align_region (rv.region(), Start, (nframes_t) (edit_cursor->current_frame * speed));
+                       if (Keyboard::modifier_state_equals (event->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
+                               
+                               align_region (rv.region(), SyncPoint, (nframes_t) (where * speed));
+                               
+                       } else if (Keyboard::modifier_state_equals (event->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
+                               
+                               align_region (rv.region(), End, (nframes_t) (where * speed));
+                               
+                       } else {
+                               
+                               align_region (rv.region(), Start, (nframes_t) (where * speed));
+                       }
                }
        }
 }
@@ -3495,13 +3904,15 @@ Editor::show_verbose_time_cursor (nframes_t frame, double offset, double xpos, d
        char buf[128];
        SMPTE::Time smpte;
        BBT_Time bbt;
+       int hours, mins;
+       nframes_t frame_rate;
        float secs;
 
        if (session == 0) {
                return;
        }
 
-       switch (ARDOUR_UI::instance()->secondary_clock.mode ()) {
+       switch (Profile->get_small_screen() ? ARDOUR_UI::instance()->primary_clock.mode () : ARDOUR_UI::instance()->secondary_clock.mode ()) {
        case AudioClock::BBT:
                session->bbt_time (frame, bbt);
                snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bbt.bars, bbt.beats, bbt.ticks);
@@ -3513,10 +3924,14 @@ Editor::show_verbose_time_cursor (nframes_t frame, double offset, double xpos, d
                break;
 
        case AudioClock::MinSec:
-               /* XXX fix this to compute min/sec properly */
-               session->smpte_time (frame, smpte);
-               secs = smpte.seconds + ((float) smpte.frames / Config->get_smpte_frames_per_second());
-               snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%.4f", smpte.hours, smpte.minutes, secs);
+               /* XXX this is copied from show_verbose_duration_cursor() */
+               frame_rate = session->frame_rate();
+               hours = frame / (frame_rate * 3600);
+               frame = frame % (frame_rate * 3600);
+               mins = frame / (frame_rate * 60);
+               frame = frame % (frame_rate * 60);
+               secs = (float) frame / (float) frame_rate;
+               snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%.4f", hours, mins, secs);
                break;
 
        default:
@@ -3540,6 +3955,8 @@ Editor::show_verbose_duration_cursor (nframes_t start, nframes_t end, double off
        SMPTE::Time smpte;
        BBT_Time sbbt;
        BBT_Time ebbt;
+       int hours, mins;
+       nframes_t distance, frame_rate;
        float secs;
        Meter meter_at_start(session->tempo_map().meter_at(start));
 
@@ -3580,10 +3997,15 @@ Editor::show_verbose_duration_cursor (nframes_t start, nframes_t end, double off
                break;
 
        case AudioClock::MinSec:
-               /* XXX fix this to compute min/sec properly */
-               session->smpte_duration (end - start, smpte);
-               secs = smpte.seconds + ((float) smpte.frames / Config->get_smpte_frames_per_second());
-               snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%.4f", smpte.hours, smpte.minutes, secs);
+               /* XXX this stuff should be elsewhere.. */
+               distance = end - start;
+               frame_rate = session->frame_rate();
+               hours = distance / (frame_rate * 3600);
+               distance = distance % (frame_rate * 3600);
+               mins = distance / (frame_rate * 60);
+               distance = distance % (frame_rate * 60);
+               secs = (float) distance / (float) frame_rate;
+               snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%.4f", hours, mins, secs);
                break;
 
        default:
@@ -3603,7 +4025,7 @@ Editor::show_verbose_duration_cursor (nframes_t start, nframes_t end, double off
 void
 Editor::collect_new_region_view (RegionView* rv)
 {
-       latest_regionview = rv;
+       latest_regionviews.push_back (rv);
 }
 
 void
@@ -3633,7 +4055,7 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event)
           set the regionview we want to then drag.
        */
        
-       latest_regionview = 0;
+       latest_regionviews.clear();
        sigc::connection c = clicked_audio_trackview->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
        
        /* A selection grab currently creates two undo/redo operations, one for 
@@ -3642,7 +4064,7 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event)
 
        begin_reversible_command (_("selection grab"));
 
-       Playlist* playlist = clicked_trackview->playlist();
+       boost::shared_ptr<Playlist> playlist = clicked_trackview->playlist();
 
         XMLNode *before = &(playlist->get_state());
        clicked_trackview->playlist()->add_region (region, selection->time[clicked_selection].start);
@@ -3653,24 +4075,25 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event)
        
        c.disconnect ();
        
-       if (latest_regionview == 0) {
+       if (latest_regionviews.empty()) {
                /* something went wrong */
                return;
        }
 
        /* we need to deselect all other regionviews, and select this one
-          i'm ignoring undo stuff, because the region creation will take care of it */
-       selection->set (latest_regionview);
+          i'm ignoring undo stuff, because the region creation will take care of it 
+       */
+       selection->set (latest_regionviews);
        
-       drag_info.item = latest_regionview->get_canvas_group();
-       drag_info.data = latest_regionview;
+       drag_info.item = latest_regionviews.front()->get_canvas_group();
+       drag_info.data = latest_regionviews.front();
        drag_info.motion_callback = &Editor::region_drag_motion_callback;
        drag_info.finished_callback = &Editor::region_drag_finished_callback;
 
        start_grab (event);
        
        drag_info.last_trackview = clicked_trackview;
-       drag_info.last_frame_position = latest_regionview->region()->position();
+       drag_info.last_frame_position = latest_regionviews.front()->region()->position();
        drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position;
        
        show_verbose_time_cursor (drag_info.last_frame_position, 10);
@@ -3682,10 +4105,8 @@ Editor::cancel_selection ()
         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
                (*i)->hide_selection ();
        }
-       begin_reversible_command (_("cancel selection"));
        selection->clear ();
        clicked_selection = 0;
-       commit_reversible_command ();
 }      
 
 void
@@ -3706,7 +4127,7 @@ Editor::start_selection_op (ArdourCanvas::Item* item, GdkEvent* event, Selection
 
        switch (op) {
        case CreateSelection:
-               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Shift)) {
+               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
                        drag_info.copy = true;
                } else {
                        drag_info.copy = false;
@@ -3754,10 +4175,9 @@ Editor::drag_selection (ArdourCanvas::Item* item, GdkEvent* event)
        nframes_t length;
        nframes_t pending_position;
 
-       if ((int32_t) drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
+       if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) {
                pending_position = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
-       }
-       else {
+       } else {
                pending_position = 0;
        }
        
@@ -3915,8 +4335,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;
@@ -3924,7 +4342,7 @@ Editor::start_trim (ArdourCanvas::Item* item, GdkEvent* event)
 
        start_grab (event, trimmer_cursor);
        
-       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
+       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
                trim_op = ContentsTrim;
        } else {
                /* These will get overridden for a point trim.*/
@@ -3966,7 +4384,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
        double speed = 1.0;
        TimeAxisView* tvp = clicked_trackview;
        RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
-       pair<set<Playlist*>::iterator,bool> insert_result;
+       pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
 
        if (tv && tv->is_audio_track()) {
                speed = tv->get_diskstream()->speed();
@@ -4005,13 +4423,14 @@ 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)->fake_set_opaque(false);                   
                        (*i)->region()->freeze ();
                
                        AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
                        if (arv)
                                arv->temporarily_hide_envelope ();
 
-                       Playlist * pl = (*i)->region()->playlist();
+                       boost::shared_ptr<Playlist> pl = (*i)->region()->playlist();
                        insert_result = motion_frozen_playlists.insert (pl);
                        if (insert_result.second) {
                                 session->add_command(new MementoCommand<Playlist>(*pl, &pl->get_state(), 0));
@@ -4050,7 +4469,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                {
                        bool swap_direction = false;
 
-                       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) {
+                       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
                                swap_direction = true;
                        }
                        
@@ -4191,7 +4610,7 @@ Editor::trim_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
        if (!drag_info.first_move) {
                trim_motion_callback (item, event);
                
-               if (!clicked_regionview->get_selected()) {
+               if (!selection->selected (clicked_regionview)) {
                        thaw_region_after_trim (*clicked_regionview);           
                } else {
                        
@@ -4199,12 +4618,13 @@ Editor::trim_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
                             i != selection->regions.by_layer().end(); ++i)
                        {
                                thaw_region_after_trim (**i);
+                               (*i)->fake_set_opaque (true);
                        }
                }
                
-               for (set<Playlist*>::iterator p = motion_frozen_playlists.begin(); p != motion_frozen_playlists.end(); ++p) {
+               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), 0, &(*p)->get_state()));
+                        session->add_command (new MementoCommand<Playlist>(*(*p).get(), 0, &(*p)->get_state()));
                 }
                
                motion_frozen_playlists.clear ();
@@ -4232,28 +4652,28 @@ Editor::point_trim (GdkEvent* event)
                trim_op = StartTrim;
                begin_reversible_command (_("Start point trim"));
 
-               if (rv->get_selected()) {
+               if (selection->selected (rv)) {
 
                        for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin();
                             i != selection->regions.by_layer().end(); ++i)
                        {
                                if (!(*i)->region()->locked()) {
-                                        Playlist *pl = (*i)->region()->playlist();
+                                       boost::shared_ptr<Playlist> pl = (*i)->region()->playlist();
                                         XMLNode &before = pl->get_state();
                                        (*i)->region()->trim_front (new_bound, this);   
                                         XMLNode &after = pl->get_state();
-                                        session->add_command(new MementoCommand<Playlist>(*pl, &before, &after));
+                                        session->add_command(new MementoCommand<Playlist>(*pl.get(), &before, &after));
                                }
                        }
 
                } else {
 
                        if (!rv->region()->locked()) {
-                                Playlist *pl = rv->region()->playlist();
+                               boost::shared_ptr<Playlist> pl = rv->region()->playlist();
                                XMLNode &before = pl->get_state();
                                rv->region()->trim_front (new_bound, this);     
                                 XMLNode &after = pl->get_state();
-                               session->add_command(new MementoCommand<Playlist>(*pl, &before, &after));
+                               session->add_command(new MementoCommand<Playlist>(*pl.get(), &before, &after));
                        }
                }
 
@@ -4264,27 +4684,27 @@ Editor::point_trim (GdkEvent* event)
                trim_op = EndTrim;
                begin_reversible_command (_("End point trim"));
 
-               if (rv->get_selected()) {
+               if (selection->selected (rv)) {
                        
                        for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i)
                        {
                                if (!(*i)->region()->locked()) {
-                                        Playlist *pl = (*i)->region()->playlist();
+                                       boost::shared_ptr<Playlist> pl = (*i)->region()->playlist();
                                        XMLNode &before = pl->get_state();
                                        (*i)->region()->trim_end (new_bound, this);
                                        XMLNode &after = pl->get_state();
-                                       session->add_command(new MementoCommand<Playlist>(*pl, &before, &after));
+                                       session->add_command(new MementoCommand<Playlist>(*pl.get(), &before, &after));
                                }
                        }
 
                } else {
 
                        if (!rv->region()->locked()) {
-                                Playlist *pl = rv->region()->playlist();
+                               boost::shared_ptr<Playlist> pl = rv->region()->playlist();
                                XMLNode &before = pl->get_state();
                                rv->region()->trim_end (new_bound, this);
                                 XMLNode &after = pl->get_state();
-                               session->add_command (new MementoCommand<Playlist>(*pl, &before, &after));
+                               session->add_command (new MementoCommand<Playlist>(*pl.get(), &before, &after));
                        }
                }
 
@@ -4350,8 +4770,9 @@ Editor::start_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event, Ran
        switch (op) {
        case CreateRangeMarker:
        case CreateTransportMarker:
-               
-               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Shift)) {
+       case CreateCDMarker:
+       
+               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
                        drag_info.copy = true;
                } else {
                        drag_info.copy = false;
@@ -4369,7 +4790,23 @@ Editor::drag_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event)
 {
        nframes_t start = 0;
        nframes_t end = 0;
-       ArdourCanvas::SimpleRect *crect = (range_marker_op == CreateRangeMarker) ? range_bar_drag_rect: transport_bar_drag_rect;
+       ArdourCanvas::SimpleRect *crect;
+
+       switch (range_marker_op) {
+       case CreateRangeMarker:
+               crect = range_bar_drag_rect;
+               break;
+       case CreateTransportMarker:
+               crect = transport_bar_drag_rect;
+               break;
+       case CreateCDMarker:
+               crect = cd_marker_bar_drag_rect;
+               break;
+       default:
+               cerr << "Error: unknown range marker op passed to Editor::drag_range_markerbar_op ()" << endl;
+               return;
+               break;
+       }
        
        if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
                snap_to (drag_info.current_pointer_frame);
@@ -4384,6 +4821,7 @@ Editor::drag_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event)
        switch (range_marker_op) {
        case CreateRangeMarker:
        case CreateTransportMarker:
+       case CreateCDMarker:
                if (drag_info.first_move) {
                        snap_to (drag_info.grab_frame);
                }
@@ -4440,22 +4878,33 @@ void
 Editor::end_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event)
 {
        Location * newloc = 0;
+       string rangename;
+       int flags;
        
        if (!drag_info.first_move) {
                drag_range_markerbar_op (item, event);
 
                switch (range_marker_op) {
                case CreateRangeMarker:
+               case CreateCDMarker:
                    {
                        begin_reversible_command (_("new range marker"));
                         XMLNode &before = session->locations()->get_state();
-                       newloc = new Location(temp_location->start(), temp_location->end(), "unnamed", Location::IsRangeMarker);
+                       session->locations()->next_available_name(rangename,"unnamed");
+                       if (range_marker_op == CreateCDMarker) {
+                               flags =  Location::IsRangeMarker|Location::IsCDMarker;
+                               cd_marker_bar_drag_rect->hide();
+                       }
+                       else {
+                               flags =  Location::IsRangeMarker;
+                               range_bar_drag_rect->hide();
+                       }
+                       newloc = new Location(temp_location->start(), temp_location->end(), rangename, (Location::Flags) flags);
                        session->locations()->add (newloc, true);
                         XMLNode &after = session->locations()->get_state();
                        session->add_command(new MementoCommand<Locations>(*(session->locations()), &before, &after));
                        commit_reversible_command ();
                        
-                       range_bar_drag_rect->hide();
                        range_marker_drag_rect->hide();
                        break;
                    }
@@ -4469,7 +4918,7 @@ Editor::end_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event)
        } else {
                /* just a click, no pointer movement. remember that context menu stuff was handled elsewhere */
 
-               if (Keyboard::no_modifier_keys_pressed (&event->button)) {
+               if (Keyboard::no_modifier_keys_pressed (&event->button) && range_marker_op != CreateCDMarker) {
 
                        nframes_t start;
                        nframes_t end;
@@ -4488,8 +4937,7 @@ 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);
+                               select_all_within (start, end, 0.0f, FLT_MAX, track_views, Selection::Set);
                                break;
 
                        case MouseRange:
@@ -4588,7 +5036,7 @@ Editor::reposition_zoom_rect (nframes_t start, nframes_t end)
 {
        double x1 = frame_to_pixel (start);
        double x2 = frame_to_pixel (end);
-       double y2 = canvas_height - 2;
+       double y2 = full_canvas_height - 1.0;
 
        zoom_rect->property_x1() = x1;
        zoom_rect->property_y1() = 1.0;
@@ -4622,16 +5070,15 @@ Editor::drag_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event)
                return;
        }
 
-//     if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
-//             snap_to (drag_info.current_pointer_frame);
-               
-//             if (drag_info.first_move) {
-//                     snap_to (drag_info.grab_frame);
-//             }
-//     }
-               
+       if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier()) && Config->get_rubberbanding_snaps_to_grid()) {
+               if (drag_info.first_move) {
+                       snap_to (drag_info.grab_frame);
+               } 
+               snap_to (drag_info.current_pointer_frame);
+       }
 
        /* base start and end on initial click position */
+
        if (drag_info.current_pointer_frame < drag_info.grab_frame) {
                start = drag_info.current_pointer_frame;
                end = drag_info.grab_frame;
@@ -4643,8 +5090,7 @@ Editor::drag_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event)
        if (drag_info.current_pointer_y < drag_info.grab_y) {
                y1 = drag_info.current_pointer_y;
                y2 = drag_info.grab_y;
-       }
-       else {
+       } else {
                y2 = drag_info.current_pointer_y;
                y1 = drag_info.grab_y;
        }
@@ -4691,12 +5137,12 @@ Editor::end_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event)
                Selection::Operation op = Keyboard::selection_type (event->button.state);
                bool commit;
 
-               begin_reversible_command (_("select regions"));
+               begin_reversible_command (_("rubberband selection"));
 
                if (drag_info.grab_frame < drag_info.last_pointer_frame) {
-                       commit = select_all_within (drag_info.grab_frame, drag_info.last_pointer_frame, y1, y2, op);
+                       commit = select_all_within (drag_info.grab_frame, drag_info.last_pointer_frame, y1, y2, track_views, op);
                } else {
-                       commit = select_all_within (drag_info.last_pointer_frame, drag_info.grab_frame, y1, y2, op);
+                       commit = select_all_within (drag_info.last_pointer_frame, drag_info.grab_frame, y1, y2, track_views, op);
                }               
 
                if (commit) {
@@ -4704,6 +5150,7 @@ Editor::end_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event)
                }
                
        } else {
+               selection->clear_tracks();
                selection->clear_regions();
                selection->clear_points ();
                selection->clear_lines ();
@@ -4730,7 +5177,7 @@ Editor::mouse_rename_region (ArdourCanvas::Item* item, GdkEvent* event)
         string str;
                prompter.get_result(str);
                if (str.length()) {
-               clicked_regionview->region()->set_name (str);
+                       clicked_regionview->region()->set_name (str);
                }
                break;
        }
@@ -4780,13 +5227,27 @@ Editor::end_time_fx (ArdourCanvas::Item* item, GdkEvent* event)
        if (drag_info.first_move) {
                return;
        }
+
+       if (drag_info.last_pointer_frame < clicked_regionview->region()->position()) {
+               /* backwards drag of the left edge - not usable */
+               return;
+       }
        
        nframes_t newlen = drag_info.last_pointer_frame - clicked_regionview->region()->position();
+#ifdef USE_RUBBERBAND
+       float percentage = (float) ((double) newlen / (double) clicked_regionview->region()->length());
+#else
        float percentage = (float) ((double) newlen - (double) clicked_regionview->region()->length()) / ((double) newlen) * 100.0f;
-       
+#endif 
+
        begin_reversible_command (_("timestretch"));
 
-       if (run_timestretch (selection->regions, percentage) == 0) {
+       // XXX how do timeFX on multiple regions ?
+
+       RegionSelection rs;
+       rs.add (clicked_regionview);
+
+       if (time_stretch (rs, percentage) == 0) {
                session->commit_reversible_command ();
        }
 }
@@ -4808,9 +5269,7 @@ Editor::mouse_brush_insert_region (RegionView* rv, nframes_t pos)
        }
 
        switch (snap_type) {
-       case SnapToFrame:
        case SnapToMark:
-       case SnapToEditCursor:
                return;
 
        default:
@@ -4829,13 +5288,13 @@ Editor::mouse_brush_insert_region (RegionView* rv, nframes_t pos)
                return;
        }
 
-       Playlist* playlist = atv->playlist();
+       boost::shared_ptr<Playlist> playlist = atv->playlist();
        double speed = atv->get_diskstream()->speed();
        
         XMLNode &before = playlist->get_state();
        playlist->add_region (boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (arv->audio_region())), (nframes_t) (pos * speed));
         XMLNode &after = playlist->get_state();
-       session->add_command(new MementoCommand<Playlist>(*playlist, &before, &after));
+       session->add_command(new MementoCommand<Playlist>(*playlist.get(), &before, &after));
        
        // playlist is frozen, so we have to update manually
        
@@ -4857,3 +5316,4 @@ Editor::track_height_step_timeout ()
        }
        return true;
 }
+