Make MIDI tools actually do something. Sorta. Sometimes.
[ardour.git] / gtk2_ardour / editor_mouse.cc
index 76357070a747df08f66b63404f6329f0944322ab..4ba1213d6279783a776f6a5426188b75ffb9f295 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>
 #include "time_axis_view.h"
 #include "audio_time_axis.h"
 #include "audio_region_view.h"
+#include "midi_region_view.h"
 #include "marker.h"
 #include "streamview.h"
 #include "region_gain_line.h"
 #include "automation_time_axis.h"
+#include "control_point.h"
 #include "prompter.h"
 #include "utils.h"
 #include "selection.h"
@@ -47,6 +48,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>
@@ -158,6 +160,12 @@ Editor::mouse_mode_toggled (MouseMode m)
                        set_mouse_mode (m);
                }
                break;
+       
+       case MouseNote:
+               if (mouse_note_button.get_active()) {
+                       set_mouse_mode (m);
+               }
+               break;
 
        default:
                break;
@@ -205,7 +213,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.
        */
@@ -242,8 +250,18 @@ Editor::set_mouse_mode (MouseMode m, bool force)
                mouse_audition_button.set_active (true);
                current_canvas_cursor = speaker_cursor;
                break;
+       
+       case MouseNote:
+               mouse_note_button.set_active (true);
+               current_canvas_cursor = note_cursor;
+               break;
        }
 
+       if (mouse_mode == MouseNote)
+               midi_toolbar_frame.show();
+       else
+               midi_toolbar_frame.hide();
+
        ignore_mouse_mode_toggle = false;
 
        if (is_drawable()) {
@@ -284,15 +302,96 @@ Editor::step_mouse_mode (bool next)
                if (next) set_mouse_mode (MouseObject);
                else set_mouse_mode (MouseTimeFX);
                break;
+       
+       case MouseNote:
+               if (next) set_mouse_mode (MouseObject);
+               else set_mouse_mode (MouseAudition);
+               break;
        }
 }
 
+void
+Editor::midi_edit_mode_toggled (MidiEditMode m)
+{
+       if (ignore_midi_edit_mode_toggle) {
+               return;
+       }
+
+       switch (m) {
+       case MidiEditSelect:
+               if (midi_tool_select_button.get_active()) {
+                       set_midi_edit_mode (m);
+               }
+               break;
+       
+       case MidiEditPencil:
+               if (midi_tool_pencil_button.get_active()) {
+                       set_midi_edit_mode (m);
+               }
+               break;
+       
+       case MidiEditErase:
+               if (midi_tool_erase_button.get_active()) {
+                       set_midi_edit_mode (m);
+               }
+               break;
+
+       default:
+               break;
+       }
+}      
+
+
+void
+Editor::set_midi_edit_mode (MidiEditMode m, bool force)
+{
+       if (drag_info.item) {
+               return;
+       }
+
+       if (!force && m == midi_edit_mode) {
+               return;
+       }
+       
+       midi_edit_mode = m;
+
+       instant_save ();
+       
+       ignore_midi_edit_mode_toggle = true;
+
+       switch (midi_edit_mode) {
+       case MidiEditSelect:
+               midi_tool_select_button.set_active (true);
+               //current_canvas_cursor = selector_cursor;
+               break;
+       
+       case MidiEditPencil:
+               midi_tool_pencil_button.set_active (true);
+               //current_canvas_cursor = selector_cursor;
+               break;
+       
+       case MidiEditErase:
+               midi_tool_erase_button.set_active (true);
+               //current_canvas_cursor = selector_cursor;
+               break;
+       }
+
+       if (mouse_mode == MouseNote)
+               midi_toolbar_frame.show();
+       else
+               midi_toolbar_frame.hide();
+
+       ignore_midi_edit_mode_toggle = false;
+
+       /*if (is_drawable()) {
+               track_canvas.get_window()->set_cursor(*current_canvas_cursor);
+       }*/
+}
+
 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
@@ -304,81 +403,82 @@ 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);
-               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);
+       case FadeInHandleItem:
+       case FadeInItem:
+       case FadeOutHandleItem:
+       case FadeOutItem:
+               if (mouse_mode != MouseRange) {
+                       commit = set_selected_regionview_from_click (press, op, true);
+               } else if (event->type == GDK_BUTTON_PRESS) {
+                       commit = set_selected_track_from_click (press, op, false);
+               }
                break;
-               
-       case GainAutomationControlPointItem:
-       case PanAutomationControlPointItem:
-       case RedirectAutomationControlPointItem:
-               c1 = set_selected_track_from_click (op, true);
-               c2 = set_selected_control_point_from_click (op, false);
-               commit = (c1 || c2);
+
+       case CrossfadeViewItem:
+               commit = set_selected_track_from_click (press, op, false);
+               break;
+                       
+       case ControlPointItem:
+               commit = set_selected_track_from_click (press, op, true);
+               if (mouse_mode != MouseRange) {
+                       commit |= 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) {
+                       commit = set_selected_track_from_click (press, op, true);
+               } else if (event->type == GDK_BUTTON_PRESS && mouse_mode == MouseRange) {
+                       commit = set_selected_track_from_click (press, op, false);
+               }
                break;
                    
        case AutomationTrackItem:
-               commit = set_selected_track_from_click (op, true);
+               commit = set_selected_track_from_click (press, op, 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 ();
-       }
+//     if (commit) {
+//             commit_reversible_command ();
+//     }
 }
 
 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()) {
@@ -497,10 +597,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::Control|Keyboard::Alt)) &&
+                           event->type == GDK_BUTTON_PRESS) {
+                               
                                start_rubberband_select (item, event);
 
                        } else if (event->type == GDK_BUTTON_PRESS) {
@@ -535,16 +634,12 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                                                return true;
                                        break;
 
-                               case GainAutomationControlPointItem:
-                               case PanAutomationControlPointItem:
-                               case RedirectAutomationControlPointItem:
+                               case ControlPointItem:
                                        start_control_point_grab (item, event);
                                        return true;
                                        break;
                                        
-                               case GainAutomationLineItem:
-                               case PanAutomationLineItem:
-                               case RedirectAutomationLineItem:
+                               case AutomationLineItem:
                                        start_line_grab_from_line (item, event);
                                        return true;
                                        break;
@@ -554,7 +649,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                                        start_rubberband_select (item, event);
                                        break;
                                        
-                               /* <CMT Additions> */
+#ifdef WITH_CMT
                                case ImageFrameHandleStartItem:
                                        imageframe_start_handle_op(item, event) ;
                                        return(true) ;
@@ -571,16 +666,13 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                                        markerview_item_end_handle_op(item, event) ;
                                        return(true) ;
                                        break ;
-                               /* </CMT Additions> */
-                               
-                               /* <CMT Additions> */
                                case MarkerViewItem:
                                        start_markerview_grab(item, event) ;
                                        break ;
                                case ImageFrameItem:
                                        start_imageframe_grab(item, event) ;
                                        break ;
-                               /* </CMT Additions> */
+#endif
 
                                case MarkerBarItem:
                                        
@@ -599,17 +691,11 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                                // start_line_grab_from_regionview (item, event);
                                break;
 
-                       case GainControlPointItem:
-                               start_control_point_grab (item, event);
-                               return true;
-                               
                        case GainLineItem:
                                start_line_grab_from_line (item, event);
                                return true;
 
-                       case GainAutomationControlPointItem:
-                       case PanAutomationControlPointItem:
-                       case RedirectAutomationControlPointItem:
+                       case ControlPointItem:
                                start_control_point_grab (item, event);
                                return true;
                                break;
@@ -621,15 +707,11 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                        break;
 
                        switch (item_type) {
-                       case GainAutomationControlPointItem:
-                       case PanAutomationControlPointItem:
-                       case RedirectAutomationControlPointItem:
+                       case ControlPointItem:
                                start_control_point_grab (item, event);
                                break;
 
-                       case GainAutomationLineItem:
-                       case PanAutomationLineItem:
-                       case RedirectAutomationLineItem:
+                       case AutomationLineItem:
                                start_line_grab_from_line (item, event);
                                break;
 
@@ -681,9 +763,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                                        }
                                        
                                        break;
-                               case GainAutomationControlPointItem:
-                               case PanAutomationControlPointItem:
-                               case RedirectAutomationControlPointItem:
+                               case ControlPointItem:
                                        start_control_point_grab (item, event);
                                        return true;
                                        break;
@@ -737,79 +817,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_axisview) {
-                                               if (!current_stepping_trackview) {
-                                                 step_timeout = Glib::signal_timeout().connect (mem_fun(*this, &Editor::track_height_step_timeout), 500);
-                                                       current_stepping_trackview = clicked_axisview;
-                                               }
-                                               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_axisview) {
-                                               if (!current_stepping_trackview) {
-                                                 step_timeout = Glib::signal_timeout().connect (mem_fun(*this, &Editor::track_height_step_timeout), 500);
-                                                       current_stepping_trackview = clicked_axisview;
-                                               }
-                                               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;
 
@@ -887,21 +894,13 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                                break;
 
                        case StreamItem:
-                               popup_track_context_menu (1, event->button.time, item_type, false, where);
-                               break;
-                               
                        case RegionItem:
                        case RegionViewNameHighlight:
                        case RegionViewName:
-                               popup_track_context_menu (1, event->button.time, item_type, false, where);
-                               break;
-                               
                        case SelectionItem:
-                               popup_track_context_menu (1, event->button.time, item_type, true, where);
-                               break;
-
                        case AutomationTrackItem:
-                               popup_track_context_menu (1, event->button.time, item_type, false, where);
+                       case CrossfadeViewItem:
+                               popup_track_context_menu (1, event->button.time, where);
                                break;
 
                        case MarkerBarItem: 
@@ -924,11 +923,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                                tm_marker_context_menu (&event->button, item);
                                break;
 
-                       case CrossfadeViewItem:
-                               popup_track_context_menu (1, event->button.time, item_type, false, where);
-                               break;
-
-                       /* <CMT Additions> */
+#ifdef WITH_CMT
                        case ImageFrameItem:
                                popup_imageframe_edit_menu(1, event->button.time, item, true) ;
                                break ;
@@ -941,8 +936,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                        case MarkerTimeAxisItem:
                                popup_marker_time_axis_edit_menu(1, event->button.time, item, false) ;
                                break ;
-                       /* <CMT Additions> */
-
+#endif
                                
                        default:
                                break;
@@ -975,18 +969,14 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                        }
                        break;
                        
-               case GainControlPointItem:
+               case ControlPointItem:
                        if (mouse_mode == MouseGain) {
                                remove_gain_control_point (item, event);
+                       } else {
+                               remove_control_point (item, event);
                        }
                        break;
 
-               case GainAutomationControlPointItem:
-               case PanAutomationControlPointItem:
-               case RedirectAutomationControlPointItem:
-                       remove_control_point (item, event);
-                       break;
-
                default:
                        break;
                }
@@ -1002,9 +992,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                case PlayheadCursorItem:
                case MarkerItem:
                case GainLineItem:
-               case GainAutomationLineItem:
-               case PanAutomationLineItem:
-               case RedirectAutomationLineItem:
+               case AutomationLineItem:
                case StartSelectionTrimItem:
                case EndSelectionTrimItem:
                        return true;
@@ -1051,8 +1039,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:
@@ -1092,25 +1082,6 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
        case 2:
                switch (mouse_mode) {
                        
-               case MouseObject:
-                       switch (item_type) {
-                       case RegionItem:
-                               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Shift)) {
-                                       raise_region ();
-                               } else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::ModifierMask (Keyboard::Shift|Keyboard::Alt))) {
-                                       lower_region ();
-                               } else {
-                                       // Button2 click is unused
-                               }
-                               return true;
-                               
-                               break;
-                               
-                       default:
-                               break;
-                       }
-                       break;
-                       
                case MouseRange:
                        
                        // x_style_paste (where, 1.0);
@@ -1140,73 +1111,50 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
        double fraction;
        
        switch (item_type) {
-       case GainControlPointItem:
-               if (mouse_mode == MouseGain) {
+       case ControlPointItem:
+               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);
+                       cp->item()->i2w (at_x, at_y);
                        at_x += 20.0;
                        at_y += 20.0;
 
-                       fraction = 1.0 - (cp->get_y() / cp->line.height());
+                       fraction = 1.0 - (cp->get_y() / cp->line().height());
 
-                       set_verbose_canvas_cursor (cp->line.get_verbose_cursor_string (fraction), at_x, at_y);
+                       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);
+                               track_canvas.get_window()->set_cursor (*fader_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);
-               }
-               break;
                
        case GainLineItem:
                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);
                        }
                }
                break;
                        
-       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);
+       case AutomationLineItem:
+               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;
                
@@ -1218,12 +1166,13 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
 
        case StartSelectionTrimItem:
        case EndSelectionTrimItem:
-       /* <CMT Additions> */
+
+#ifdef WITH_CMT
        case ImageFrameHandleStartItem:
        case ImageFrameHandleEndItem:
        case MarkerViewHandleStartItem:
        case MarkerViewHandleEndItem:
-       /* </CMT Additions> */
+#endif
 
                if (is_drawable()) {
                        track_canvas.get_window()->set_cursor (*trimmer_cursor);
@@ -1288,7 +1237,7 @@ 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]);
+               marker->set_color_rgba (ARDOUR_UI::config()->canvasvar_EnteredMarker.get());
                // fall through
        case MeterMarkerItem:
        case TempoMarkerItem:
@@ -1316,13 +1265,8 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
 
        switch (item_type) {
        case GainLineItem:
-       case GainAutomationLineItem:
-       case RedirectAutomationLineItem:
-       case PanAutomationLineItem:
-       case GainControlPointItem:
-       case GainAutomationControlPointItem:
-       case PanAutomationControlPointItem:
-       case RedirectAutomationControlPointItem:
+       case AutomationLineItem:
+       case ControlPointItem:
                /* these do not affect the current entered track state */
                clear_entered_track = false;
                break;
@@ -1350,13 +1294,10 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
        bool is_start;
 
        switch (item_type) {
-       case GainControlPointItem:
-       case GainAutomationControlPointItem:
-       case PanAutomationControlPointItem:
-       case RedirectAutomationControlPointItem:
+       case ControlPointItem:
                cp = reinterpret_cast<ControlPoint*>(item->get_data ("control_point"));
-               if (cp->line.npoints() > 1) {
-                       if (!cp->selected) {
+               if (cp->line().the_list()->interpolation() != AutomationList::Discrete) {
+                       if (cp->line().npoints() > 1 && !cp->selected()) {
                                cp->set_visible (false);
                        }
                }
@@ -1373,21 +1314,21 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_
        case EndSelectionTrimItem:
        case EditCursorItem:
        case PlayheadCursorItem:
-       /* <CMT Additions> */
+
+#ifdef WITH_CMT
        case ImageFrameHandleStartItem:
        case ImageFrameHandleEndItem:
        case MarkerViewHandleStartItem:
        case MarkerViewHandleEndItem:
-       /* </CMT Additions> */
+#endif
+
                if (is_drawable()) {
                        track_canvas.get_window()->set_cursor (*current_canvas_cursor);
                }
                break;
 
        case GainLineItem:
-       case GainAutomationLineItem:
-       case RedirectAutomationLineItem:
-       case PanAutomationLineItem:
+       case AutomationLineItem:
                al = reinterpret_cast<AutomationLine*> (item->get_data ("line"));
                {
                        ArdourCanvas::Line *line = dynamic_cast<ArdourCanvas::Line *> (item);
@@ -1507,7 +1448,10 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
                */
                if (!drag_info.move_threshold_passed) {
 
-                       drag_info.move_threshold_passed = (abs ((int) (drag_info.current_pointer_x - drag_info.grab_x)) > 4);
+                       bool x_threshold_passed =  (abs ((nframes64_t) (drag_info.current_pointer_x - drag_info.grab_x)) > 4LL);
+                       bool y_threshold_passed =  (abs ((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
 
@@ -1525,10 +1469,7 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
        case PlayheadCursorItem:
        case EditCursorItem:
        case MarkerItem:
-       case GainControlPointItem:
-       case RedirectAutomationControlPointItem:
-       case GainAutomationControlPointItem:
-       case PanAutomationControlPointItem:
+       case ControlPointItem:
        case TempoMarkerItem:
        case MeterMarkerItem:
        case RegionViewNameHighlight:
@@ -1536,17 +1477,17 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
        case EndSelectionTrimItem:
        case SelectionItem:
        case GainLineItem:
-       case RedirectAutomationLineItem:
-       case GainAutomationLineItem:
-       case PanAutomationLineItem:
+       case AutomationLineItem:
        case FadeInHandleItem:
        case FadeOutHandleItem:
-       /* <CMT Additions> */
+
+#ifdef WITH_CMT
        case ImageFrameHandleStartItem:
        case ImageFrameHandleEndItem:
        case MarkerViewHandleStartItem:
        case MarkerViewHandleEndItem:
-       /* </CMT Additions> */
+#endif
+
          if (drag_info.item && (event->motion.state & Gdk::BUTTON1_MASK ||
                                 (event->motion.state & Gdk::BUTTON2_MASK))) {
                  if (!from_autoscroll) {
@@ -1618,7 +1559,7 @@ 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;
@@ -1752,7 +1693,7 @@ Editor::start_fade_in_grab (ArdourCanvas::Item* item, GdkEvent* event)
 
        AudioRegionView* arv = static_cast<AudioRegionView*>(drag_info.data);
 
-       drag_info.pointer_frame_offset = drag_info.grab_frame - ((nframes_t) arv->audio_region()->fade_in().back()->when + arv->region()->position());  
+       drag_info.pointer_frame_offset = drag_info.grab_frame - ((nframes_t) arv->audio_region()->fade_in()->back()->when + arv->region()->position()); 
 }
 
 void
@@ -1762,7 +1703,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 {
@@ -1772,16 +1713,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);
 
@@ -1791,43 +1742,46 @@ 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;
+               }
+       
+               boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_in();
+               XMLNode &before = alist->get_state();
+
+               tmp->audio_region()->set_fade_in_length (fade_length);
+               
+               XMLNode &after = alist->get_state();
+               session->add_command(new MementoCommand<AutomationList>(*alist.get(), &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
@@ -1846,7 +1800,7 @@ Editor::start_fade_out_grab (ArdourCanvas::Item* item, GdkEvent* event)
 
        AudioRegionView* arv = static_cast<AudioRegionView*>(drag_info.data);
 
-       drag_info.pointer_frame_offset = drag_info.grab_frame - (arv->region()->length() - (nframes_t) arv->audio_region()->fade_out().back()->when + arv->region()->position());       
+       drag_info.pointer_frame_offset = drag_info.grab_frame - (arv->region()->length() - (nframes_t) arv->audio_region()->fade_out()->back()->when + arv->region()->position());      
 }
 
 void
@@ -1856,17 +1810,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
        }
@@ -1876,8 +1829,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);
 
@@ -1893,7 +1857,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 {
@@ -1915,16 +1879,25 @@ 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;
+               }
+       
+               boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_out();
+               XMLNode &before = alist->get_state();
+               
+               tmp->audio_region()->set_fade_out_length (fade_length);
 
-       fade_out_drag_motion_callback (item, event);
+               XMLNode &after = alist->get_state();
+               session->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
+       }
+
+       commit_reversible_command ();
 }
 
 void
@@ -1943,10 +1916,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;  
@@ -1960,7 +1939,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 {
@@ -1979,6 +1958,8 @@ Editor::cursor_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
        
        if (cursor == edit_cursor) {
                edit_cursor_clock.set (cursor->current_frame);
+       } else {
+               UpdateAllTransportClocks (cursor->current_frame);
        }
 
        show_verbose_time_cursor (cursor->current_frame, 10);
@@ -1993,6 +1974,8 @@ 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) {
@@ -2072,10 +2055,9 @@ Editor::marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
 
        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;
        }
 
@@ -2231,7 +2213,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();
@@ -2253,7 +2235,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 {
@@ -2362,7 +2344,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();
@@ -2384,7 +2366,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 {
@@ -2452,16 +2434,16 @@ Editor::remove_gain_control_point (ArdourCanvas::Item*item, GdkEvent* event)
        }
 
        // We shouldn't remove the first or last gain point
-       if (control_point->line.is_last_point(*control_point) ||
-               control_point->line.is_first_point(*control_point)) {   
+       if (control_point->line().is_last_point(*control_point) ||
+               control_point->line().is_first_point(*control_point)) { 
                return;
        }
 
-       control_point->line.remove_point (*control_point);
+       control_point->line().remove_point (*control_point);
 }
 
 void
-Editor::remove_control_point (ArdourCanvas::Item*item, GdkEvent* event)
+Editor::remove_control_point (ArdourCanvas::Item* item, GdkEvent* event)
 {
        ControlPoint* control_point;
 
@@ -2470,14 +2452,14 @@ Editor::remove_control_point (ArdourCanvas::Item*item, GdkEvent* event)
                /*NOTREACHED*/
        }
 
-       control_point->line.remove_point (*control_point);
+       control_point->line().remove_point (*control_point);
 }
 
 void
 Editor::start_control_point_grab (ArdourCanvas::Item* item, GdkEvent* event)
 {
        ControlPoint* control_point;
-       
+
        if ((control_point = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"))) == 0) {
                fatal << _("programming error: control point canvas item has no control point object pointer!") << endmsg;
                /*NOTREACHED*/
@@ -2490,10 +2472,10 @@ Editor::start_control_point_grab (ArdourCanvas::Item* item, GdkEvent* event)
 
        start_grab (event, fader_cursor);
 
-       control_point->line.start_drag (control_point, 0);
+       control_point->line().start_drag (control_point, drag_info.grab_frame, 0);
 
-       float fraction = 1.0 - (control_point->get_y() / control_point->line.height());
-       set_verbose_canvas_cursor (control_point->line.get_verbose_cursor_string (fraction), 
+       double fraction = 1.0 - ((control_point->get_y() - control_point->line().y_position()) / (double)control_point->line().height());
+       set_verbose_canvas_cursor (control_point->line().get_verbose_cursor_string (fraction), 
                                   drag_info.current_pointer_x + 20, drag_info.current_pointer_y + 20);
 
        show_verbose_canvas_cursor ();
@@ -2517,11 +2499,11 @@ Editor::control_point_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent*
                cy = drag_info.grab_y;
        }
 
-       cp->line.parent_group().w2i (cx, cy);
+       cp->line().parent_group().w2i (cx, cy);
 
        cx = max (0.0, cx);
        cy = max (0.0, cy);
-       cy = min ((double) cp->line.height(), cy);
+       cy = min ((double) (cp->line().y_position() + cp->line().height()), cy);
 
        //translate cx to frames
        nframes_t cx_frames = unit_to_frame (cx);
@@ -2530,8 +2512,8 @@ Editor::control_point_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent*
                snap_to (cx_frames);
        }
 
-       float fraction = 1.0 - (cy / cp->line.height());
-       
+       const double fraction = 1.0 - ((cy - cp->line().y_position()) / (double)cp->line().height());
+
        bool push;
 
        if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) {
@@ -2540,9 +2522,9 @@ Editor::control_point_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent*
                push = false;
        }
 
-       cp->line.point_drag (*cp, cx_frames , fraction, push);
+       cp->line().point_drag (*cp, cx_frames , fraction, push);
        
-       set_verbose_canvas_cursor_text (cp->line.get_verbose_cursor_string (fraction));
+       set_verbose_canvas_cursor_text (cp->line().get_verbose_cursor_string (fraction));
 
        drag_info.first_move = false;
 }
@@ -2563,7 +2545,7 @@ Editor::control_point_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent
        } else {
                control_point_drag_motion_callback (item, event);
        }
-       cp->line.end_drag (cp);
+       cp->line().end_drag (cp);
 }
 
 void
@@ -2621,9 +2603,9 @@ Editor::start_line_grab (AutomationLine* line, GdkEvent* event)
 
        start_grab (event, fader_cursor);
 
-       double fraction = 1.0 - (cy / line->height());
+       const double fraction = 1.0 - ((cy - line->y_position()) / (double)line->height());
 
-       line->start_drag (0, fraction);
+       line->start_drag (0, drag_info.grab_frame, fraction);
        
        set_verbose_canvas_cursor (line->get_verbose_cursor_string (fraction),
                                   drag_info.current_pointer_x + 20, drag_info.current_pointer_y + 20);
@@ -2639,8 +2621,7 @@ Editor::line_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
        line->parent_group().w2i (cx, cy);
        
-       double fraction;
-       fraction = 1.0 - (cy / line->height());
+       const double fraction = 1.0 - ((cy - line->y_position()) / (double)line->height());
 
        bool push;
 
@@ -2725,6 +2706,7 @@ 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
@@ -2773,64 +2755,40 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
        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;
+
                        rv = (*i);
-                       
-                       Playlist* to_playlist = rv->region()->playlist();
-                       RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&rv->get_time_axis_view());
-                       
-                       insert_result = affected_playlists.insert (to_playlist);
-                       if (insert_result.second) {
-                               session->add_command (new MementoCommand<Playlist>(*to_playlist, &to_playlist->get_state(), 0));
-                       }
-                       
-                       latest_regionview = 0;
-                       
-                       sigc::connection c = rtv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
-                       
-                       /* create a new region with the same name. */
-                       
-                       boost::shared_ptr<Region> newregion;
 
-                       newregion = RegionFactory::create (rv->region());
-                       assert(newregion != 0);
+                       AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
+                       MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(rv);
 
-                       /* if the original region was locked, we don't care */
-                       
-                       newregion->set_locked (false);
-                       
-                       to_playlist->add_region (newregion, (nframes_t) (rv->region()->position() * rtv->get_diskstream()->speed()));
-                       
-                       c.disconnect ();
-                       
-                       if (latest_regionview) {
-                               new_regionviews.push_back (latest_regionview);
+                       if (arv) {
+                               nrv = new AudioRegionView (*arv);
+                       } else if (mrv) {
+                               nrv = new MidiRegionView (*mrv);
+                       } else {
+                               continue;
                        }
+
+                       nrv->get_canvas_group()->show ();
+
+                       new_regionviews.push_back (nrv);
                }
-               
+
                if (new_regionviews.empty()) {
                        return;
                }
-               
+
                /* reset selection to new regionviews */
                
                selection->set (new_regionviews);
@@ -2838,6 +2796,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                /* reset drag_info data to reflect the fact that we are dragging the copies */
                
                drag_info.data = new_regionviews.front();
+
                swap_grab (new_regionviews.front()->get_canvas_group (), 0, event->motion.time);
        }
 
@@ -2881,7 +2840,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                        TimeAxisView *tracklist_timeview;
                        tracklist_timeview = (*i);
                        RouteTimeAxisView* rtv2 = dynamic_cast<RouteTimeAxisView*>(tracklist_timeview);
-                       list<TimeAxisView*> children_list;
+                       TimeAxisView::Children children_list;
              
                        /* zeroes are audio tracks. ones are other types. */
              
@@ -2901,7 +2860,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                                height_list[rtv2->order] = (*i)->height;
                                children = 1;
                                if ((children_list = rtv2->get_child_list()).size() > 0) {
-                                       for (list<TimeAxisView*>::iterator j = children_list.begin(); j != children_list.end(); ++j) { 
+                                       for (TimeAxisView::Children::iterator j = children_list.begin(); j != children_list.end(); ++j) { 
                                                tracks = tracks |= (0x01 << (rtv2->order + children));
                                                height_list[rtv2->order + children] =  (*j)->height;                
                                                numtracks++;
@@ -3025,14 +2984,14 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
        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);
 
@@ -3064,13 +3023,13 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                        /* now compute the canvas unit distance we need to move the regiondrag_info.last_trackview->order
                           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 {
@@ -3094,6 +3053,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) {
 
@@ -3116,148 +3076,148 @@ 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;
+
+       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) {
 
-       for (list<RegionView*>::const_iterator i = layered_regions.begin(); i != layered_regions.end(); ++i) {
+               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);
-               RouteTimeAxisView* canvas_rtv = dynamic_cast<RouteTimeAxisView*>(tvp2);
-               RouteTimeAxisView* temp_rtv;
-
-               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_rtv->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);
+                       RouteTimeAxisView* canvas_rtv = dynamic_cast<RouteTimeAxisView*>(tvp2);
+                       RouteTimeAxisView* temp_rtv;
+
+                       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_rtv->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_rtv = dynamic_cast<RouteTimeAxisView*>(tvp2);
-                                       rv->set_height (temp_rtv->height);
+                                               tvp2 = trackview_by_y_position (iy1 + y_delta);
+                                               temp_rtv = dynamic_cast<RouteTimeAxisView*>(tvp2);
+                                               rv->set_y_position_and_height (0, temp_rtv->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_rtv->view->get_region_color());
-                                       //rv->set_color (const_cast<GdkColor&>(col));
-                                       break;          
+                                               //const GdkColor& col (temp_rtv->view->get_region_color());
+                                               //rv->set_color (const_cast<GdkColor&>(col));
+                                               break;          
+                                       }
+                                       x++;
                                }
-                               x++;
                        }
-               }
          
-               /* prevent the regionview from being moved to before 
-                  the zero position on the canvas.
-               */
-               /* clamp */
+                       /* prevent the regionview from being moved to before 
+                          the zero position on the canvas.
+                       */
+                       /* clamp */
                
-               if (x_delta < 0) {
-                       if (-x_delta > ix1) {
-                               x_delta = -ix1;
+                       if (x_delta < 0) {
+                               if (-x_delta > ix1) {
+                                       x_delta = -ix1;
+                               }
+                       } else if ((x_delta > 0) && (rv->region()->last_frame() > max_frames - x_delta)) {
+                               x_delta = max_frames - rv->region()->last_frame();
                        }
-               } else if ((x_delta > 0) &&(rv->region()->last_frame() > max_frames - x_delta)) {
-                       x_delta = max_frames - rv->region()->last_frame();
-               }
-                       
-               if (drag_info.first_move) {
 
-                       /* hide any dependent views */
 
-//                     rv->get_time_axis_view().hide_dependent_views (*rv);
-                               
-                       /* this is subtle. raising the regionview itself won't help,
-                          because raise_to_top() just puts the item on the top of
-                          its parent's stack. so, we need to put the trackview canvas_display group
-                          on the top, since its parent is the whole canvas.
-                       */
+                       if (drag_info.first_move) {
 
-                       rv->get_canvas_group()->raise_to_top();
-                       rv->get_time_axis_view().canvas_display->raise_to_top();
-                       cursor_group->raise_to_top();
+                               /* hide any dependent views */
+                       
+                               rv->get_time_axis_view().hide_dependent_views (*rv);
+                       
+                               /* this is subtle. raising the regionview itself won't help,
+                                  because raise_to_top() just puts the item on the top of
+                                  its parent's stack. so, we need to put the trackview canvas_display group
+                                  on the top, since its parent is the whole canvas.
+                               */
+                       
+                               rv->get_canvas_group()->raise_to_top();
+                               rv->get_time_axis_view().canvas_display->raise_to_top();
+                               cursor_group->raise_to_top();
 
-                       /* freeze the playlists from notifying till
-                          the motion is done.
-                       */
+                               rv->fake_set_opaque (true);
+                       }
+                       
+                       if (drag_info.brushing) {
+                               mouse_brush_insert_region (rv, pending_region_position);
+                       } else {
+                               rv->move (x_delta, y_delta);                    
+                       }
 
-                       RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&rv->get_time_axis_view());
-                       if (rtv && rtv->is_track()) {
-                               Playlist* pl = dynamic_cast<Playlist*>(rtv->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
@@ -3265,12 +3225,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;
+       RouteTimeAxisView* rtv;
        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. 
@@ -3291,15 +3252,22 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
 
        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;
        }
 
        /* adjust for track speed */
        speed = 1.0;
 
-       atv = dynamic_cast<RouteTimeAxisView*> (drag_info.last_trackview);
-       if (atv && atv->get_diskstream()) {
-               speed = atv->get_diskstream()->speed();
+       rtv = dynamic_cast<RouteTimeAxisView*> (drag_info.last_trackview);
+       if (rtv && rtv->get_diskstream()) {
+               speed = rtv->get_diskstream()->speed();
        }
        
        regionview_x_movement = (drag_info.last_frame_position != (nframes_t) (rv->region()->position()/speed));
@@ -3308,117 +3276,141 @@ 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);
-                       RouteTimeAxisView* atv2 = dynamic_cast<RouteTimeAxisView*>(tvp2);
-           
-                       from_playlist = (*i)->region()->playlist();
-                       to_playlist = atv2->playlist();
+                       RouteTimeAxisView* rtv2 = dynamic_cast<RouteTimeAxisView*>(tvp2);
 
-                       /* 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);
+                       boost::shared_ptr<Playlist> from_playlist = rv->region()->playlist();
+                       boost::shared_ptr<Playlist> to_playlist = rtv2->playlist();
 
-                       /* only freeze the to_playlist once */
+                       where = (nframes_t) (unit_to_frame (ix1) * speed);
+                       boost::shared_ptr<Region> new_region (RegionFactory::create (rv->region()));
 
-                       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));
-                       }
+                       /* undo the previous hide_dependent_views so that xfades don't
+                          disappear on copying regions 
+                       */
 
-               }
+                       rv->get_time_axis_view().reveal_dependent_views (*rv);
 
-               /* now do it again with the actual operations */
+                       if (!drag_info.copy) {
+                               
+                               /* 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.
+                               */ 
+           
+                               rv->hide_region_editor();
+                               rv->fake_set_opaque (false);
 
-               for (list<RegionView*>::const_iterator i = new_selection.begin(); i != new_selection.end();i++ ) {
+                               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()));    
 
-                       Playlist* from_playlist;
-                       Playlist* to_playlist;
+                       } else {
+
+                               /* the regionview we dragged around is a temporary copy, queue it for deletion */
                                
-                       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);
-                       RouteTimeAxisView* atv2 = dynamic_cast<RouteTimeAxisView*>(tvp2);
-           
-                       from_playlist = (*i)->region()->playlist();
-                       to_playlist = atv2->playlist();
+                               copies.push_back (rv);
+                       }
 
                        latest_regionview = 0;
-           
-                       where = (nframes_t) (unit_to_frame (ix1) * speed);
-                       boost::shared_ptr<Region> new_region (RegionFactory::create ((*i)->region()));
-
-                       from_playlist->remove_region (((*i)->region()));
                        
-                       sigc::connection c = atv2->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
+                       sigc::connection c = rtv2->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);
+                               new_selection.push_back (latest_regionview);
+                       }
+
+                       /* 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);
 
-                       if (rv->region()->locked()) {
+                       if (!rv->region()->can_move()) {
                                continue;
                        }
-                       
+
                        if (regionview_x_movement) {
                                double ownspeed = 1.0;
-                               RouteTimeAxisView* atv = dynamic_cast<RouteTimeAxisView*> (&(rv->get_time_axis_view()));
+                               rtv = dynamic_cast<RouteTimeAxisView*> (&(rv->get_time_axis_view()));
 
-                               if (atv && atv->get_diskstream()) {
-                                       ownspeed = atv->get_diskstream()->speed();
+                               if (rtv && rtv->get_diskstream()) {
+                                       ownspeed = rtv->get_diskstream()->speed();
                                }
                                
                                /* base the new region position on the current position of the regionview.*/
@@ -3434,25 +3426,65 @@ 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;
+                               boost::shared_ptr<Region> mr;
+
+                               if ((ar = boost::dynamic_pointer_cast<AudioRegion>(rv->region())) != 0) {
+                                       newregion = RegionFactory::create (ar);
+                               } else if ((mr = boost::dynamic_pointer_cast<MidiRegion>(rv->region())) != 0) {
+                                       newregion = RegionFactory::create (mr);
+                               }
+
+                               /* add it */
+
+                               latest_regionview = 0;
+                               sigc::connection c = rtv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
+                               to_playlist->add_region (newregion, (nframes_t) (where * rtv->get_diskstream()->speed()));
+                               c.disconnect ();
+                               
+                               if (latest_regionview) {
+                                       rtv->reveal_dependent_views (*latest_regionview);
+                                       selection->add (latest_regionview);
+                               }
+                               
+                       } 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
@@ -3464,10 +3496,10 @@ Editor::region_view_item_click (AudioRegionView& rv, GdkEventButton* event)
        
        if (Keyboard::modifier_state_contains (event->state, Keyboard::Control)) {
                TimeAxisView* tv = &rv.get_time_axis_view();
-               RouteTimeAxisView* atv = dynamic_cast<RouteTimeAxisView*>(tv);
+               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(tv);
                double speed = 1.0;
-               if (atv && atv->is_track()) {
-                       speed = atv->get_diskstream()->speed();
+               if (rtv && rtv->is_track()) {
+                       speed = rtv->get_diskstream()->speed();
                }
 
                if (Keyboard::modifier_state_equals (event->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Alt))) {
@@ -3491,13 +3523,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);
@@ -3509,10 +3543,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:
@@ -3536,6 +3574,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));
 
@@ -3576,10 +3616,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:
@@ -3638,7 +3683,7 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event)
 
        begin_reversible_command (_("selection grab"));
 
-       Playlist* playlist = clicked_axisview->playlist();
+       boost::shared_ptr<Playlist> playlist = clicked_axisview->playlist();
 
        XMLNode *before = &(playlist->get_state());
        clicked_routeview->playlist()->add_region (region, selection->time[clicked_selection].start);
@@ -3750,10 +3795,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;
        }
        
@@ -3911,8 +3955,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;
@@ -3962,7 +4004,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
        double speed = 1.0;
        TimeAxisView* tvp = clicked_axisview;
        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_track()) {
                speed = tv->get_diskstream()->speed();
@@ -4001,13 +4043,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));
@@ -4195,12 +4238,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 ();
@@ -4234,22 +4278,22 @@ Editor::point_trim (GdkEvent* event)
                             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));
                        }
                }
 
@@ -4265,22 +4309,22 @@ Editor::point_trim (GdkEvent* event)
                        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));
                        }
                }
 
@@ -4436,6 +4480,7 @@ void
 Editor::end_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event)
 {
        Location * newloc = 0;
+       string rangename;
        
        if (!drag_info.first_move) {
                drag_range_markerbar_op (item, event);
@@ -4445,7 +4490,8 @@ Editor::end_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event)
                    {
                        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");
+                       newloc = new Location(temp_location->start(), temp_location->end(), rangename, Location::IsRangeMarker);
                        session->locations()->add (newloc, true);
                         XMLNode &after = session->locations()->get_state();
                        session->add_command(new MementoCommand<Locations>(*(session->locations()), &before, &after));
@@ -4484,8 +4530,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:
@@ -4584,7 +4629,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;
@@ -4618,16 +4663,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())) {
+               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;
@@ -4639,8 +4683,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;
        }
@@ -4687,12 +4730,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) {
@@ -4700,6 +4743,7 @@ Editor::end_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event)
                }
                
        } else {
+               selection->clear_tracks();
                selection->clear_regions();
                selection->clear_points ();
                selection->clear_lines ();
@@ -4726,7 +4770,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;
        }
@@ -4819,19 +4863,19 @@ Editor::mouse_brush_insert_region (RegionView* rv, nframes_t pos)
                return;
        }
 
-       RouteTimeAxisView* atv = dynamic_cast<RouteTimeAxisView*>(&arv->get_time_axis_view());
+       RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&arv->get_time_axis_view());
 
-       if (atv == 0 || !atv->is_track()) {
+       if (rtv == 0 || !rtv->is_track()) {
                return;
        }
 
-       Playlist* playlist = atv->playlist();
-       double speed = atv->get_diskstream()->speed();
+       boost::shared_ptr<Playlist> playlist = rtv->playlist();
+       double speed = rtv->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