Remove some never-seen tooltips (overridden by other
[ardour.git] / gtk2_ardour / editor_ops.cc
index ede62d8d9b369f6a2907e6e70ce63174bf0599bb..1dd5256d2a98fa63ff9aa331254eb6c8d4d561be 100644 (file)
 #include <gtkmm2ext/choice.h>
 #include <gtkmm2ext/popup.h>
 
-#include "ardour/audioengine.h"
-#include "ardour/session.h"
-#include "ardour/audioplaylist.h"
+#include "ardour/audio_track.h"
 #include "ardour/audioregion.h"
-#include "ardour/audio_diskstream.h"
-#include "ardour/utils.h"
+#include "ardour/dB.h"
 #include "ardour/location.h"
-#include "ardour/audio_track.h"
-#include "ardour/audioplaylist.h"
-#include "ardour/region_factory.h"
+#include "ardour/midi_region.h"
+#include "ardour/operations.h"
 #include "ardour/playlist_factory.h"
-#include "ardour/reverse.h"
-#include "ardour/transient_detector.h"
-#include "ardour/dB.h"
 #include "ardour/quantize.h"
-#include "ardour/strip_silence.h"
+#include "ardour/region_factory.h"
+#include "ardour/reverse.h"
 #include "ardour/route_group.h"
-#include "ardour/operations.h"
+#include "ardour/session.h"
+#include "ardour/session_playlists.h"
+#include "ardour/strip_silence.h"
+#include "ardour/transient_detector.h"
+#include "ardour/utils.h"
 
 #include "ardour_ui.h"
+#include "debug.h"
 #include "editor.h"
 #include "time_axis_view.h"
 #include "route_time_axis.h"
@@ -86,6 +85,7 @@
 #include "editor_cursors.h"
 #include "mouse_cursors.h"
 #include "patch_change_dialog.h"
+#include "transpose_dialog.h"
 
 #include "i18n.h"
 
@@ -104,6 +104,10 @@ using Gtkmm2ext::Keyboard;
 void
 Editor::undo (uint32_t n)
 {
+       if (_drags->active ()) {
+               _drags->abort ();
+       }
+       
        if (_session) {
                _session->undo (n);
        }
@@ -112,6 +116,10 @@ Editor::undo (uint32_t n)
 void
 Editor::redo (uint32_t n)
 {
+       if (_drags->active ()) {
+               _drags->abort ();
+       }
+       
        if (_session) {
                _session->redo (n);
        }
@@ -144,7 +152,7 @@ Editor::split_regions_at (framepos_t where, RegionSelection& regions)
                }
        } else {
                snap_to (where);
-               
+
                frozen = true;
                EditorFreeze(); /* Emit Signal */
        }
@@ -196,98 +204,56 @@ Editor::split_regions_at (framepos_t where, RegionSelection& regions)
        }
 
        commit_reversible_command ();
-       
+
        if (frozen){
                EditorThaw(); /* Emit Signal */
        }
 }
 
-boost::shared_ptr<Region>
-Editor::select_region_for_operation (int /*dir*/, TimeAxisView **tv)
+/** Move one extreme of the current range selection.  If more than one range is selected,
+ *  the start of the earliest range or the end of the latest range is moved.
+ *
+ *  @param move_end true to move the end of the current range selection, false to move
+ *  the start.
+ *  @param next true to move the extreme to the next region boundary, false to move to
+ *  the previous.
+ */
+void
+Editor::move_range_selection_start_or_end_to_region_boundary (bool move_end, bool next)
 {
-       RegionView* rv;
-       boost::shared_ptr<Region> region;
-       framepos_t start = 0;
-
-       if (selection->time.start () == selection->time.end_frame ()) {
-
-               /* no current selection-> is there a selected regionview? */
-
-               if (selection->regions.empty()) {
-                       return region;
-               }
-
+       if (selection->time.start() == selection->time.end_frame()) {
+               return;
        }
 
-       if (!selection->regions.empty()) {
+       framepos_t start = selection->time.start ();
+       framepos_t end = selection->time.end_frame ();
 
-               rv = *(selection->regions.begin());
-               (*tv) = &rv->get_time_axis_view();
-               region = rv->region();
+       /* the position of the thing we may move */
+       framepos_t pos = move_end ? end : start;
+       int dir = next ? 1 : -1;
 
-       } else if (!selection->tracks.empty()) {
-
-               (*tv) = selection->tracks.front();
-
-               RouteTimeAxisView* rtv;
-
-               if ((rtv = dynamic_cast<RouteTimeAxisView*> (*tv)) != 0) {
-                       boost::shared_ptr<Playlist> pl;
-
-                       if ((pl = rtv->playlist()) == 0) {
-                               return region;
-                       }
-
-                       region = pl->top_region_at (start);
-               }
+       /* so we don't find the current region again */
+       if (dir > 0 || pos > 0) {
+               pos += dir;
        }
 
-       return region;
-}
-
-void
-Editor::extend_selection_to_end_of_region (bool next)
-{
-       TimeAxisView *tv;
-       boost::shared_ptr<Region> region;
-       framepos_t start;
-
-       if ((region = select_region_for_operation (next ? 1 : 0, &tv)) == 0) {
+       framepos_t const target = get_region_boundary (pos, dir, true, false);
+       if (target < 0) {
                return;
        }
 
-       if (region && selection->time.start () == selection->time.end_frame ()) {
-               start = region->position();
+       if (move_end) {
+               end = target;
        } else {
-               start = selection->time.start ();
+               start = target;
        }
 
-       begin_reversible_command (_("extend selection"));
-       selection->set (start, region->position() + region->length());
-       commit_reversible_command ();
-}
-
-void
-Editor::extend_selection_to_start_of_region (bool previous)
-{
-       TimeAxisView *tv;
-       boost::shared_ptr<Region> region;
-       framepos_t end;
-
-       if ((region = select_region_for_operation (previous ? -1 : 0, &tv)) == 0) {
+       if (end < start) {
                return;
        }
 
-       if (region && selection->time.start () == selection->time.end_frame ()) {
-               end = region->position() + region->length();
-       } else {
-               end = selection->time.end_frame ();
-       }
-
-       /* Try to leave the selection with the same route if possible */
-
-       begin_reversible_command (_("extend selection"));
-       selection->set (region->position(), end);
+       begin_reversible_command (_("alter selection"));
+       selection->set_preserving_all_ranges (start, end);
        commit_reversible_command ();
 }
 
@@ -340,7 +306,7 @@ Editor::nudge_forward (bool next, bool force_playhead)
                        }
 
                        r->clear_changes ();
-                       r->set_position (r->position() + distance, this);
+                       r->set_position (r->position() + distance);
                        _session->add_command (new StatefulDiffCommand (r));
                }
 
@@ -419,13 +385,13 @@ Editor::nudge_backward (bool next, bool force_playhead)
                        if (next) {
                                distance = next_distance;
                        }
-                        
+
                        r->clear_changes ();
 
                        if (r->position() > distance) {
-                               r->set_position (r->position() - distance, this);
+                               r->set_position (r->position() - distance);
                        } else {
-                               r->set_position (0, this);
+                               r->set_position (0);
                        }
                        _session->add_command (new StatefulDiffCommand (r));
                }
@@ -493,23 +459,23 @@ void
 Editor::nudge_forward_capture_offset ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (!_session || rs.empty()) {
                return;
        }
 
        begin_reversible_command (_("nudge forward"));
-       
+
        framepos_t const distance = _session->worst_output_latency();
-       
+
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
                boost::shared_ptr<Region> r ((*i)->region());
-               
+
                r->clear_changes ();
-               r->set_position (r->position() + distance, this);
+               r->set_position (r->position() + distance);
                _session->add_command(new StatefulDiffCommand (r));
        }
-       
+
        commit_reversible_command ();
 }
 
@@ -523,22 +489,22 @@ Editor::nudge_backward_capture_offset ()
        }
 
        begin_reversible_command (_("nudge forward"));
-       
+
        framepos_t const distance = _session->worst_output_latency();
 
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
                boost::shared_ptr<Region> r ((*i)->region());
-               
+
                r->clear_changes ();
-               
+
                if (r->position() > distance) {
-                       r->set_position (r->position() - distance, this);
+                       r->set_position (r->position() - distance);
                } else {
-                       r->set_position (0, this);
+                       r->set_position (0);
                }
                _session->add_command(new StatefulDiffCommand (r));
        }
-       
+
        commit_reversible_command ();
 }
 
@@ -594,11 +560,11 @@ Editor::build_region_boundary_cache ()
 
        TimeAxisView *ontrack = 0;
        TrackViewList tlist;
-
+       
        if (!selection->tracks.empty()) {
-               tlist = selection->tracks;
+               tlist = selection->tracks.filter_to_unique_playlists ();
        } else {
-               tlist = track_views;
+               tlist = track_views.filter_to_unique_playlists ();
        }
 
        while (pos < _session->current_end_frame() && !at_end) {
@@ -745,7 +711,7 @@ Editor::find_next_region_boundary (framepos_t pos, int32_t dir, const TrackViewL
        for (TrackViewList::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
                framepos_t contender;
                framecnt_t d;
-                
+
                RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
 
                if (!rtv) {
@@ -1206,68 +1172,6 @@ Editor::scroll_playhead (bool forward)
        _session->request_locate (pos);
 }
 
-void
-Editor::playhead_backward ()
-{
-       framepos_t pos;
-       framepos_t cnt;
-       float prefix;
-       bool was_floating;
-
-       if (get_prefix (prefix, was_floating)) {
-               cnt = 1;
-       } else {
-               if (was_floating) {
-                       cnt = (framepos_t) floor (prefix * _session->frame_rate ());
-               } else {
-                       cnt = (framepos_t) prefix;
-               }
-       }
-
-       pos = playhead_cursor->current_frame;
-
-       if ((framepos_t) pos < cnt) {
-               pos = 0;
-       } else {
-               pos -= cnt;
-       }
-
-       /* XXX this is completely insane. with the current buffering
-          design, we'll force a complete track buffer flush and
-          reload, just to move 1 sample !!!
-       */
-
-       _session->request_locate (pos);
-}
-
-void
-Editor::playhead_forward ()
-{
-       framepos_t pos;
-       framepos_t cnt;
-       bool was_floating;
-       float prefix;
-
-       if (get_prefix (prefix, was_floating)) {
-               cnt = 1;
-       } else {
-               if (was_floating) {
-                       cnt = (framepos_t) floor (prefix * _session->frame_rate ());
-               } else {
-                       cnt = (framepos_t) floor (prefix);
-               }
-       }
-
-       pos = playhead_cursor->current_frame;
-
-       /* XXX this is completely insane. with the current buffering
-          design, we'll force a complete track buffer flush and
-          reload, just to move 1 sample !!!
-       */
-
-       _session->request_locate (pos+cnt);
-}
-
 void
 Editor::cursor_align (bool playhead_to_edit)
 {
@@ -1301,98 +1205,13 @@ Editor::cursor_align (bool playhead_to_edit)
        }
 }
 
-void
-Editor::edit_cursor_backward ()
-{
-       framepos_t pos;
-       framepos_t cnt;
-       float prefix;
-       bool was_floating;
-
-       if (get_prefix (prefix, was_floating)) {
-               cnt = 1;
-       } else {
-               if (was_floating) {
-                       cnt = (framepos_t) floor (prefix * _session->frame_rate ());
-               } else {
-                       cnt = (framepos_t) prefix;
-               }
-       }
-
-       if ((pos = get_preferred_edit_position()) < 0) {
-               return;
-       }
-
-       if (pos < cnt) {
-               pos = 0;
-       } else {
-               pos -= cnt;
-       }
-
-       // EDIT CURSOR edit_cursor->set_position (pos);
-}
-
-void
-Editor::edit_cursor_forward ()
-{
-       //framepos_t pos;
-       framepos_t cnt;
-       bool was_floating;
-       float prefix;
-
-       if (get_prefix (prefix, was_floating)) {
-               cnt = 1;
-       } else {
-               if (was_floating) {
-                       cnt = (framepos_t) floor (prefix * _session->frame_rate ());
-               } else {
-                       cnt = (framepos_t) floor (prefix);
-               }
-       }
-
-       // pos = edit_cursor->current_frame;
-       // EDIT CURSOR edit_cursor->set_position (pos+cnt);
-}
-
-void
-Editor::goto_frame ()
-{
-       float prefix;
-       bool was_floating;
-       framepos_t frame;
-
-       if (get_prefix (prefix, was_floating)) {
-               return;
-       }
-
-       if (was_floating) {
-               frame = (framepos_t) floor (prefix * _session->frame_rate());
-       } else {
-               frame = (framepos_t) floor (prefix);
-       }
-
-       _session->request_locate (frame);
-}
-
 void
 Editor::scroll_backward (float pages)
 {
-       framepos_t frame;
-       framepos_t one_page = (framepos_t) rint (_canvas_width * frames_per_unit);
-       bool was_floating;
-       float prefix;
-       framepos_t cnt;
-
-       if (get_prefix (prefix, was_floating)) {
-               cnt = (framepos_t) floor (pages * one_page);
-       } else {
-               if (was_floating) {
-                       cnt = (framepos_t) floor (prefix * _session->frame_rate());
-               } else {
-                       cnt = (framepos_t) floor (prefix * one_page);
-               }
-       }
+       framepos_t const one_page = (framepos_t) rint (_canvas_width * frames_per_unit);
+       framepos_t const cnt = (framepos_t) floor (pages * one_page);
 
+       framepos_t frame;
        if (leftmost_frame < cnt) {
                frame = 0;
        } else {
@@ -1405,22 +1224,10 @@ Editor::scroll_backward (float pages)
 void
 Editor::scroll_forward (float pages)
 {
-       framepos_t frame;
-       framepos_t one_page = (framepos_t) rint (_canvas_width * frames_per_unit);
-       bool was_floating;
-       float prefix;
-       framepos_t cnt;
-
-       if (get_prefix (prefix, was_floating)) {
-               cnt = (framepos_t) floor (pages * one_page);
-       } else {
-               if (was_floating) {
-                       cnt = (framepos_t) floor (prefix * _session->frame_rate());
-               } else {
-                       cnt = (framepos_t) floor (prefix * one_page);
-               }
-       }
+       framepos_t const one_page = (framepos_t) rint (_canvas_width * frames_per_unit);
+       framepos_t const cnt = (framepos_t) floor (pages * one_page);
 
+       framepos_t frame;
        if (max_framepos - cnt < leftmost_frame) {
                frame = max_framepos - cnt;
        } else {
@@ -1433,38 +1240,18 @@ Editor::scroll_forward (float pages)
 void
 Editor::scroll_tracks_down ()
 {
-       float prefix;
-       bool was_floating;
-       int cnt;
-
-       if (get_prefix (prefix, was_floating)) {
-               cnt = 1;
-       } else {
-               cnt = (int) floor (prefix);
-       }
-
-       double vert_value = vertical_adjustment.get_value() + (cnt *
-               vertical_adjustment.get_page_size());
+       double vert_value = vertical_adjustment.get_value() + vertical_adjustment.get_page_size();
        if (vert_value > vertical_adjustment.get_upper() - _canvas_height) {
                vert_value = vertical_adjustment.get_upper() - _canvas_height;
        }
+
        vertical_adjustment.set_value (vert_value);
 }
 
 void
 Editor::scroll_tracks_up ()
 {
-       float prefix;
-       bool was_floating;
-       int cnt;
-
-       if (get_prefix (prefix, was_floating)) {
-               cnt = 1;
-       } else {
-               cnt = (int) floor (prefix);
-       }
-
-       vertical_adjustment.set_value (vertical_adjustment.get_value() - (cnt * vertical_adjustment.get_page_size()));
+       vertical_adjustment.set_value (vertical_adjustment.get_value() - vertical_adjustment.get_page_size());
 }
 
 void
@@ -1475,7 +1262,7 @@ Editor::scroll_tracks_down_line ()
        if (vert_value > vertical_adjustment.get_upper() - _canvas_height) {
                vert_value = vertical_adjustment.get_upper() - _canvas_height;
        }
-       
+
        vertical_adjustment.set_value (vert_value);
 }
 
@@ -1723,7 +1510,7 @@ Editor::temporal_zoom_region (bool both_axes)
 
                for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
                        if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
-                               hide_track_in_display (*i, true);
+                               hide_track_in_display (*i);
                        }
                }
 
@@ -1794,6 +1581,10 @@ Editor::temporal_zoom_by_frame (framepos_t start, framepos_t end, const string &
                new_leftmost = 0;
        }
 
+       if (new_leftmost < 0) {
+               new_leftmost = 0;
+       }
+
        reposition_and_zoom (new_leftmost, new_fpu);
 }
 
@@ -1825,10 +1616,10 @@ Editor::temporal_zoom_to_frame (bool coarser, framepos_t frame)
        if (new_leftmost > frame) {
                new_leftmost = 0;
        }
-//     begin_reversible_command (_("zoom to frame"));
-//     _session->add_undo (sigc::bind (sigc::mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
-//     _session->add_redo (sigc::bind (sigc::mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
-//     commit_reversible_command ();
+
+       if (new_leftmost < 0) {
+               new_leftmost = 0;
+       }
 
        reposition_and_zoom (new_leftmost, new_fpu);
 }
@@ -1928,7 +1719,7 @@ void
 Editor::add_locations_from_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -1955,7 +1746,7 @@ void
 Editor::add_location_from_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -1986,59 +1777,6 @@ Editor::add_location_from_region ()
        _session->commit_reversible_command ();
 }
 
-void
-Editor::amplitude_zoom_step (bool in)
-{
-       gdouble zoom = 1.0;
-
-       if (in) {
-               zoom *= 2.0;
-       } else {
-               if (zoom > 2.0) {
-                       zoom /= 2.0;
-               } else {
-                       zoom = 1.0;
-               }
-       }
-
-#ifdef FIX_FOR_CANVAS
-       /* XXX DO SOMETHING */
-#endif
-}
-
-
-/* DELETION */
-
-
-void
-Editor::delete_sample_forward ()
-{
-}
-
-void
-Editor::delete_sample_backward ()
-{
-}
-
-void
-Editor::delete_screen ()
-{
-}
-
-/* SEARCH */
-
-void
-Editor::search_backwards ()
-{
-       /* what ? */
-}
-
-void
-Editor::search_forwards ()
-{
-       /* what ? */
-}
-
 /* MARKS */
 
 void
@@ -2076,25 +1814,15 @@ Editor::jump_backward_to_mark ()
 void
 Editor::set_mark ()
 {
-       framepos_t pos;
-       float prefix;
-       bool was_floating;
-       string markername;
+       framepos_t const pos = _session->audible_frame ();
 
-       if (get_prefix (prefix, was_floating)) {
-               pos = _session->audible_frame ();
-       } else {
-               if (was_floating) {
-                       pos = (framepos_t) floor (prefix * _session->frame_rate ());
-               } else {
-                       pos = (framepos_t) floor (prefix);
-               }
-       }
+       string markername;
+       _session->locations()->next_available_name (markername, "mark");
 
-       _session->locations()->next_available_name(markername,"mark");
-       if (!choose_new_marker_name(markername)) {
+       if (!choose_new_marker_name (markername)) {
                return;
        }
+
        _session->locations()->add (new Location (*_session, pos, 0, markername, Location::IsMark), true);
 }
 
@@ -2120,11 +1848,13 @@ Editor::clear_ranges ()
 
                Location * looploc = _session->locations()->auto_loop_location();
                Location * punchloc = _session->locations()->auto_punch_location();
+               Location * sessionloc = _session->locations()->session_range_location();
 
                _session->locations()->clear_ranges ();
                // re-add these
                if (looploc) _session->locations()->add (looploc);
                if (punchloc) _session->locations()->add (punchloc);
+               if (sessionloc) _session->locations()->add (sessionloc);
 
                XMLNode &after = _session->locations()->get_state();
                _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
@@ -2218,7 +1948,6 @@ Editor::insert_route_list_drag (boost::shared_ptr<Route> route, int x, int y)
 {
        double wx, wy;
        double cx, cy;
-       framepos_t where;
        RouteTimeAxisView *dest_rtv = 0;
        RouteTimeAxisView *source_rtv = 0;
 
@@ -2231,7 +1960,7 @@ Editor::insert_route_list_drag (boost::shared_ptr<Route> route, int x, int y)
        event.button.x = wx;
        event.button.y = wy;
 
-       where = event_frame (&event, &cx, &cy);
+       event_frame (&event, &cx, &cy);
 
        std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (cy);
        if (tv.first == 0) {
@@ -2408,28 +2137,101 @@ Editor::loop_location (Location& location)
        }
 }
 
+void
+Editor::do_layer_operation (LayerOperation op)
+{
+       if (selection->regions.empty ()) {
+               return;
+       }
+
+       bool const multiple = selection->regions.size() > 1;
+       switch (op) {
+       case Raise:
+               if (multiple) {
+                       begin_reversible_command (_("raise regions"));
+               } else {
+                       begin_reversible_command (_("raise region"));
+               }
+               break;
+
+       case RaiseToTop:
+               if (multiple) {
+                       begin_reversible_command (_("raise regions to top"));
+               } else {
+                       begin_reversible_command (_("raise region to top"));
+               }
+               break;
+               
+       case Lower:
+               if (multiple) {
+                       begin_reversible_command (_("lower regions"));
+               } else {
+                       begin_reversible_command (_("lower region"));
+               }
+               break;
+               
+       case LowerToBottom:
+               if (multiple) {
+                       begin_reversible_command (_("lower regions to bottom"));
+               } else {
+                       begin_reversible_command (_("lower region"));
+               }
+               break;
+       }
+
+       set<boost::shared_ptr<Playlist> > playlists = selection->regions.playlists ();
+       for (set<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
+               (*i)->clear_owned_changes ();
+       }
+       
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+               boost::shared_ptr<Region> r = (*i)->region ();
+               switch (op) {
+               case Raise:
+                       r->raise ();
+                       break;
+               case RaiseToTop:
+                       r->raise_to_top ();
+                       break;
+               case Lower:
+                       r->lower ();
+                       break;
+               case LowerToBottom:
+                       r->lower_to_bottom ();
+               }
+       }
+
+       for (set<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
+               vector<Command*> cmds;
+               (*i)->rdiff (cmds);
+               _session->add_commands (cmds);
+       }
+       
+       commit_reversible_command ();
+}
+
 void
 Editor::raise_region ()
 {
-       selection->foreach_region (&Region::raise);
+       do_layer_operation (Raise);
 }
 
 void
 Editor::raise_region_to_top ()
 {
-       selection->foreach_region (&Region::raise_to_top);
+       do_layer_operation (RaiseToTop);
 }
 
 void
 Editor::lower_region ()
 {
-       selection->foreach_region (&Region::lower);
+       do_layer_operation (Lower);
 }
 
 void
 Editor::lower_region_to_bottom ()
 {
-       selection->foreach_region (&Region::lower_to_bottom);
+       do_layer_operation (LowerToBottom);
 }
 
 /** Show the region editor for the selected regions */
@@ -2450,7 +2252,7 @@ void
 Editor::rename_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -2473,7 +2275,7 @@ Editor::rename_region ()
        d.set_size_request (300, -1);
        d.set_position (Gtk::WIN_POS_MOUSE);
 
-       entry.set_text (selection->regions.front()->region()->name());
+       entry.set_text (rs.front()->region()->name());
        entry.select_region (0, -1);
 
        entry.signal_activate().connect (sigc::bind (sigc::mem_fun (d, &Dialog::response), RESPONSE_OK));
@@ -2489,7 +2291,7 @@ Editor::rename_region ()
        if (ret != RESPONSE_OK) {
                return;
        }
-       
+
        std::string str = entry.get_text();
        strip_whitespace_edges (str);
        if (!str.empty()) {
@@ -2535,7 +2337,7 @@ Editor::play_selected_region ()
        framepos_t end = 0;
 
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -2593,8 +2395,8 @@ Editor::region_from_selection ()
                internal_start = start - current->position();
                RegionFactory::region_name (new_name, current->name(), true);
 
-               PropertyList plist; 
-               
+               PropertyList plist;
+
                plist.add (ARDOUR::Properties::start, current->start() + internal_start);
                plist.add (ARDOUR::Properties::length, selection_cnt);
                plist.add (ARDOUR::Properties::name, new_name);
@@ -2614,9 +2416,10 @@ Editor::create_region_from_selection (vector<boost::shared_ptr<Region> >& new_re
        framepos_t start = selection->time[clicked_selection].start;
        framepos_t end = selection->time[clicked_selection].end;
 
-       sort_track_selection ();
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+       sort_track_selection (ts);
 
-       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+       for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) {
                boost::shared_ptr<Region> current;
                boost::shared_ptr<Playlist> playlist;
                framepos_t internal_start;
@@ -2633,8 +2436,8 @@ Editor::create_region_from_selection (vector<boost::shared_ptr<Region> >& new_re
                internal_start = start - current->position();
                RegionFactory::region_name (new_name, current->name(), true);
 
-               PropertyList plist; 
-               
+               PropertyList plist;
+
                plist.add (ARDOUR::Properties::start, current->start() + internal_start);
                plist.add (ARDOUR::Properties::length, end - start + 1);
                plist.add (ARDOUR::Properties::name, new_name);
@@ -2647,7 +2450,7 @@ void
 Editor::split_multichannel_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -2712,7 +2515,7 @@ Editor::get_tracks_for_range_action () const
                t = selection->tracks;
        }
 
-       return t;
+       return t.filter_to_unique_playlists();
 }
 
 void
@@ -2723,7 +2526,7 @@ Editor::separate_regions_between (const TimeSelection& ts)
        RegionSelection new_selection;
 
        TrackViewList tmptracks = get_tracks_for_range_action ();
-       sort_track_selection (&tmptracks);
+       sort_track_selection (tmptracks);
 
        for (TrackSelection::iterator i = tmptracks.begin(); i != tmptracks.end(); ++i) {
 
@@ -2765,12 +2568,12 @@ Editor::separate_regions_between (const TimeSelection& ts)
                                                        rtv->view()->foreach_regionview (sigc::bind (
                                                                                sigc::ptr_fun (add_if_covered),
                                                                                &(*t), &new_selection));
-                                                       
+
                                                        if (!in_command) {
                                                                begin_reversible_command (_("separate"));
                                                                in_command = true;
                                                        }
-                                                        
+
                                                        /* pick up changes to existing regions */
 
                                                        vector<Command*> cmds;
@@ -2873,7 +2676,7 @@ Editor::separate_under_selected_regions ()
        vector<PlaylistState> playlists;
 
        RegionSelection rs;
-       
+
        rs = get_regions_from_selection_and_entered();
 
        if (!_session || rs.empty()) {
@@ -2927,7 +2730,7 @@ Editor::separate_under_selected_regions ()
 
                //Partition on the region bounds
                playlist->partition ((*rl)->first_frame() - 1, (*rl)->last_frame() + 1, true);
-               
+
                //Re-add region that was just removed due to the partition operation
                playlist->add_region( (*rl), (*rl)->first_frame() );
        }
@@ -2966,16 +2769,17 @@ Editor::crop_region_to (framepos_t start, framepos_t end)
 {
        vector<boost::shared_ptr<Playlist> > playlists;
        boost::shared_ptr<Playlist> playlist;
-       TrackViewList* ts;
+       TrackViewList ts;
 
        if (selection->tracks.empty()) {
-               ts = &track_views;
+               ts = track_views.filter_to_unique_playlists();
        } else {
-               sort_track_selection ();
-               ts = &selection->tracks;
+               ts = selection->tracks.filter_to_unique_playlists ();
        }
 
-       for (TrackSelection::iterator i = ts->begin(); i != ts->end(); ++i) {
+       sort_track_selection (ts);
+
+       for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) {
 
                RouteTimeAxisView* rtv;
 
@@ -3026,7 +2830,7 @@ Editor::crop_region_to (framepos_t start, framepos_t end)
                cnt = the_end - the_start + 1;
 
                region->clear_changes ();
-               region->trim_to (the_start, cnt, this);
+               region->trim_to (the_start, cnt);
                _session->add_command (new StatefulDiffCommand (region));
        }
 
@@ -3100,7 +2904,9 @@ Editor::region_fill_selection ()
 
        begin_reversible_command (Operations::fill_selection);
 
-       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+
+       for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
 
                if ((playlist = (*i)->playlist()) == 0) {
                        continue;
@@ -3153,20 +2959,20 @@ void
 Editor::remove_region_sync ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
 
        begin_reversible_command (_("remove region sync"));
-       
+
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
 
                (*i)->region()->clear_changes ();
                (*i)->region()->clear_sync_position ();
                _session->add_command(new StatefulDiffCommand ((*i)->region()));
        }
-       
+
        commit_reversible_command ();
 }
 
@@ -3184,13 +2990,13 @@ Editor::naturalize_region ()
        } else {
                begin_reversible_command (_("move region to original position"));
        }
-               
+
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
                (*i)->region()->clear_changes ();
-               (*i)->region()->move_to_natural_position (this);
+               (*i)->region()->move_to_natural_position ();
                _session->add_command (new StatefulDiffCommand ((*i)->region()));
        }
-       
+
        commit_reversible_command ();
 }
 
@@ -3198,7 +3004,7 @@ void
 Editor::align_regions (RegionPoint what)
 {
        RegionSelection const rs = get_regions_from_selection_and_edit_point ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -3224,7 +3030,7 @@ void
 Editor::align_regions_relative (RegionPoint point)
 {
        RegionSelection const rs = get_regions_from_selection_and_edit_point ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -3282,7 +3088,7 @@ Editor::align_regions_relative (RegionPoint point)
        /* move first one specially */
 
        r->clear_changes ();
-       r->set_position (pos, this);
+       r->set_position (pos);
        _session->add_command(new StatefulDiffCommand (r));
 
        /* move rest by the same amount */
@@ -3296,11 +3102,11 @@ Editor::align_regions_relative (RegionPoint point)
                region->clear_changes ();
 
                if (dir > 0) {
-                       region->set_position (region->position() + distance, this);
+                       region->set_position (region->position() + distance);
                } else {
-                       region->set_position (region->position() - distance, this);
+                       region->set_position (region->position() - distance);
                }
-                
+
                _session->add_command(new StatefulDiffCommand (region));
 
        }
@@ -3323,17 +3129,17 @@ Editor::align_region_internal (boost::shared_ptr<Region> region, RegionPoint poi
 
        switch (point) {
        case SyncPoint:
-               region->set_position (region->adjust_to_sync (position), this);
+               region->set_position (region->adjust_to_sync (position));
                break;
 
        case End:
                if (position > region->length()) {
-                       region->set_position (position - region->length(), this);
+                       region->set_position (position - region->length());
                }
                break;
 
        case Start:
-               region->set_position (position, this);
+               region->set_position (position);
                break;
        }
 
@@ -3371,15 +3177,15 @@ Editor::trim_region (bool front)
 
        for (list<RegionView*>::const_iterator i = rs.by_layer().begin(); i != rs.by_layer().end(); ++i) {
                if (!(*i)->region()->locked()) {
-                        
+
                        (*i)->region()->clear_changes ();
-                       
+
                        if (front) {
-                               (*i)->region()->trim_front (where, this);
+                               (*i)->region()->trim_front (where);
                        } else {
-                               (*i)->region()->trim_end (where, this);
+                               (*i)->region()->trim_end (where);
                        }
-                       
+
                        _session->add_command (new StatefulDiffCommand ((*i)->region()));
                }
        }
@@ -3441,9 +3247,9 @@ Editor::trim_region_to_location (const Location& loc, const char* str)
 
                start = session_frame_to_track_frame (loc.start(), speed);
                end = session_frame_to_track_frame (loc.end(), speed);
-                
+
                rv->region()->clear_changes ();
-               rv->region()->trim_to (start, (end - start), this);
+               rv->region()->trim_to (start, (end - start));
                _session->add_command(new StatefulDiffCommand (rv->region()));
        }
 
@@ -3505,7 +3311,7 @@ Editor::trim_to_region(bool forward)
                        continue;
                    }
 
-                   region->trim_end((framepos_t) ( (next_region->first_frame() - 1) * speed), this);
+                   region->trim_end((framepos_t) ( (next_region->first_frame() - 1) * speed));
                    arv->region_changed (PropertyChange (ARDOUR::Properties::length));
                }
                else {
@@ -3516,7 +3322,7 @@ Editor::trim_to_region(bool forward)
                        continue;
                    }
 
-                   region->trim_front((framepos_t) ((next_region->last_frame() + 1) * speed), this);
+                   region->trim_front((framepos_t) ((next_region->last_frame() + 1) * speed));
 
                    arv->region_changed (ARDOUR::bounds_change);
                }
@@ -3556,6 +3362,14 @@ Editor::freeze_thread ()
 void
 Editor::freeze_route ()
 {
+       if (!_session) {
+               return;
+       }
+
+       /* stop transport before we start. this is important */
+
+       _session->request_transport_speed (0.0);
+
        if (clicked_routeview == 0 || !clicked_routeview->is_audio_track()) {
                return;
        }
@@ -3601,10 +3415,11 @@ Editor::bounce_range_selection (bool replace, bool enable_processing)
 
        for (TrackViewList::iterator i = views.begin(); i != views.end(); ++i) {
                RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
-               if (rtv && !rtv->track()->bounceable()) {
+               if (rtv && rtv->track() && replace && enable_processing && !rtv->track()->bounceable()) {
                        MessageDialog d (
-                               _("One or more selected tracks cannot be bounced because it has more outputs than inputs.  "
-                                 "You can fix this by increasing the number of inputs on that track.")
+                               _("You can't perform this operation because the processing of the signal "
+                                 "will cause one or more of the tracks will end up with a region with more channels than this track has inputs.\n\n"
+                                 "You can do this without processing, which is a different operation.")
                                );
                        d.set_title (_("Cannot bounce"));
                        d.run ();
@@ -3636,9 +3451,13 @@ Editor::bounce_range_selection (bool replace, bool enable_processing)
 
                playlist->clear_changes ();
                playlist->clear_owned_changes ();
-               
+
                boost::shared_ptr<Region> r = rtv->track()->bounce_range (start, start+cnt, itt, enable_processing);
 
+               if (!r) {
+                       continue;
+               }
+
                if (replace) {
                        list<AudioRange> ranges;
                        ranges.push_back (AudioRange (start, start+cnt, 0));
@@ -3656,6 +3475,13 @@ Editor::bounce_range_selection (bool replace, bool enable_processing)
        commit_reversible_command ();
 }
 
+/** Delete selected regions, automation points or a time range */
+void
+Editor::delete_ ()
+{
+       cut_copy (Delete);
+}
+
 /** Cut selected regions, automation points or a time range */
 void
 Editor::cut ()
@@ -3708,6 +3534,9 @@ Editor::cut_copy (CutCopyOp op)
        string opname;
 
        switch (op) {
+       case Delete:
+               opname = _("delete");
+               break;
        case Cut:
                opname = _("cut");
                break;
@@ -3725,7 +3554,7 @@ Editor::cut_copy (CutCopyOp op)
           this function.
        */
 
-       if (op == Cut || op == Clear) {
+       if (op == Delete || op == Cut || op == Clear) {
                if (_drags->active ()) {
                        _drags->abort ();
                }
@@ -3765,12 +3594,9 @@ Editor::cut_copy (CutCopyOp op)
 
                /* we only want to cut regions if some are selected */
 
-               if (!selection->regions.empty()) {
-                       rs = selection->regions;
-               }
-
                switch (current_mouse_mode()) {
                case MouseObject:
+                       rs = get_regions_from_selection ();
                        if (!rs.empty() || !selection->points.empty()) {
 
                                begin_reversible_command (opname + _(" objects"));
@@ -3778,7 +3604,7 @@ Editor::cut_copy (CutCopyOp op)
                                if (!rs.empty()) {
                                        cut_copy_regions (op, rs);
 
-                                       if (op == Cut) {
+                                       if (op == Cut || op == Delete) {
                                                selection->clear_regions ();
                                        }
                                }
@@ -3786,11 +3612,10 @@ Editor::cut_copy (CutCopyOp op)
                                if (!selection->points.empty()) {
                                        cut_copy_points (op);
 
-                                       if (op == Cut) {
+                                       if (op == Cut || op == Delete) {
                                                selection->clear_points ();
                                        }
                                }
-
                                commit_reversible_command ();
                                break; // terminate case statement here
                        }
@@ -3813,7 +3638,7 @@ Editor::cut_copy (CutCopyOp op)
                        cut_copy_ranges (op);
                        commit_reversible_command ();
 
-                       if (op == Cut) {
+                       if (op == Cut || op == Delete) {
                                selection->clear_time ();
                        }
 
@@ -3824,7 +3649,7 @@ Editor::cut_copy (CutCopyOp op)
                }
        }
 
-       if (op == Cut || op == Clear) {
+       if (op == Delete || op == Cut || op == Clear) {
                _drags->abort ();
        }
 }
@@ -3838,6 +3663,7 @@ Editor::cut_copy_points (CutCopyOp op)
        for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) {
 
                AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*>((*i).track);
+               _last_cut_copy_source_track = atv;
 
                if (atv) {
                        atv->cut_copy_clear_objects (selection->points, op);
@@ -3884,7 +3710,16 @@ Editor::remove_clicked_region ()
 
        begin_reversible_command (_("remove region"));
        playlist->clear_changes ();
+       playlist->clear_owned_changes ();
        playlist->remove_region (clicked_regionview->region());
+
+       /* We might have removed regions, which alters other regions' layering_index,
+          so we need to do a recursive diff here.
+       */
+       vector<Command*> cmds;
+       playlist->rdiff (cmds);
+       _session->add_commands (cmds);
+       
        _session->add_command(new StatefulDiffCommand (playlist));
        commit_reversible_command ();
 }
@@ -3928,23 +3763,16 @@ Editor::remove_selected_regions ()
                        continue;
                }
 
-               vector<boost::shared_ptr<Playlist> >::iterator i;
-
-               //only prep history if this is a new playlist.
-               for (i = playlists.begin(); i != playlists.end(); ++i) {
-                       if ((*i) == playlist) {
-                               break;
-                       }
-               }
-
-               if (i == playlists.end()) {
-
-                       playlist->clear_changes ();
-                       playlist->freeze ();
+               /* get_regions_from_selection_and_entered() guarantees that
+                  the playlists involved are unique, so there is no need
+                  to check here.
+               */
 
-                       playlists.push_back (playlist);
-               }
+               playlists.push_back (playlist);
 
+               playlist->clear_changes ();
+               playlist->clear_owned_changes ();
+               playlist->freeze ();
                playlist->remove_region (*rl);
        }
 
@@ -3952,6 +3780,14 @@ Editor::remove_selected_regions ()
 
        for (pl = playlists.begin(); pl != playlists.end(); ++pl) {
                (*pl)->thaw ();
+
+               /* We might have removed regions, which alters other regions' layering_index,
+                  so we need to do a recursive diff here.
+               */
+               vector<Command*> cmds;
+               (*pl)->rdiff (cmds);
+               _session->add_commands (cmds);
+               
                _session->add_command(new StatefulDiffCommand (*pl));
        }
 
@@ -3983,13 +3819,13 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs)
 
                first_position = min ((framepos_t) (*x)->region()->position(), first_position);
 
-               if (op == Cut || op == Clear) {
+               if (op == Cut || op == Clear || op == Delete) {
                        boost::shared_ptr<Playlist> pl = (*x)->region()->playlist();
 
                        if (pl) {
                                FreezeList::iterator fl;
 
-                               //only take state if this is a new playlist.
+                               // only take state if this is a new playlist.
                                for (fl = freezelist.begin(); fl != freezelist.end(); ++fl) {
                                        if ((*fl) == pl) {
                                                break;
@@ -3998,6 +3834,7 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs)
 
                                if (fl == freezelist.end()) {
                                        pl->clear_changes();
+                                       pl->clear_owned_changes ();
                                        pl->freeze ();
                                        freezelist.insert (pl);
                                }
@@ -4037,22 +3874,25 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs)
                tmp = x;
                ++tmp;
 
-               vector<PlaylistMapping>::iterator z;
+               if (op != Delete) {
 
-               for (z = pmap.begin(); z != pmap.end(); ++z) {
-                       if ((*z).tv == &tv) {
-                               break;
+                       vector<PlaylistMapping>::iterator z;
+                       
+                       for (z = pmap.begin(); z != pmap.end(); ++z) {
+                               if ((*z).tv == &tv) {
+                                       break;
+                               }
+                       }
+                       
+                       assert (z != pmap.end());
+                       
+                       if (!(*z).pl) {
+                               npl = PlaylistFactory::create (pl->data_type(), *_session, "cutlist", true);
+                               npl->freeze();
+                               (*z).pl = npl;
+                       } else {
+                               npl = (*z).pl;
                        }
-               }
-
-               assert (z != pmap.end());
-
-               if (!(*z).pl) {
-                       npl = PlaylistFactory::create (pl->data_type(), *_session, "cutlist", true);
-                       npl->freeze();
-                       (*z).pl = npl;
-               } else {
-                       npl = (*z).pl;
                }
 
                boost::shared_ptr<Region> r = (*x)->region();
@@ -4061,6 +3901,10 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs)
                assert (r != 0);
 
                switch (op) {
+               case Delete:
+                       pl->remove_region (r);
+                       break;
+                       
                case Cut:
                        _xx = RegionFactory::create (r);
                        npl->add_region (_xx, r->position() - first_position);
@@ -4073,36 +3917,47 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs)
                        break;
 
                case Clear:
-                       pl->remove_region (r);
+                       pl->remove_region (r);  
                        break;
                }
 
                x = tmp;
        }
 
-       list<boost::shared_ptr<Playlist> > foo;
-
-       /* the pmap is in the same order as the tracks in which selected regions occured */
+       if (op != Delete) {
 
-       for (vector<PlaylistMapping>::iterator i = pmap.begin(); i != pmap.end(); ++i) {
-               if ((*i).pl) {
-                       (*i).pl->thaw();
-                       foo.push_back ((*i).pl);
+               list<boost::shared_ptr<Playlist> > foo;
+               
+               /* the pmap is in the same order as the tracks in which selected regions occured */
+               
+               for (vector<PlaylistMapping>::iterator i = pmap.begin(); i != pmap.end(); ++i) {
+                       if ((*i).pl) {
+                               (*i).pl->thaw();
+                               foo.push_back ((*i).pl);
+                       }
+               }
+               
+               if (!foo.empty()) {
+                       cut_buffer->set (foo);
+               }
+               
+               if (pmap.empty()) {
+                       _last_cut_copy_source_track = 0;
+               } else {
+                       _last_cut_copy_source_track = pmap.front().tv;
                }
        }
 
-       if (!foo.empty()) {
-               cut_buffer->set (foo);
-       }
-
-       if (pmap.empty()) {
-               _last_cut_copy_source_track = 0;
-       } else {
-               _last_cut_copy_source_track = pmap.front().tv;
-       }
-        
        for (FreezeList::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) {
                (*pl)->thaw ();
+
+               /* We might have removed regions, which alters other regions' layering_index,
+                  so we need to do a recursive diff here.
+               */
+               vector<Command*> cmds;
+               (*pl)->rdiff (cmds);
+               _session->add_commands (cmds);
+               
                _session->add_command (new StatefulDiffCommand (*pl));
        }
 }
@@ -4110,28 +3965,34 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs)
 void
 Editor::cut_copy_ranges (CutCopyOp op)
 {
-       TrackViewList* ts;
-       TrackViewList entered;
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
 
-       if (selection->tracks.empty()) {
+       /* Sort the track selection now, so that it if is used, the playlists
+          selected by the calls below to cut_copy_clear are in the order that
+          their tracks appear in the editor.  This makes things like paste
+          of ranges work properly.
+       */
+
+       sort_track_selection (ts);
+
+       if (ts.empty()) {
                if (!entered_track) {
                        return;
                }
-               entered.push_back (entered_track);
-               ts = &entered;
-       } else {
-               ts = &selection->tracks;
-       }
+               ts.push_back (entered_track);
+       } 
 
-       for (TrackSelection::iterator i = ts->begin(); i != ts->end(); ++i) {
+       for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
                (*i)->cut_copy_clear (*selection, op);
        }
 }
 
 void
-Editor::paste (float times)
+Editor::paste (float times, bool from_context)
 {
-       paste_internal (get_preferred_edit_position(), times);
+        DEBUG_TRACE (DEBUG::CutNPaste, "paste to preferred edit pos\n");
+
+       paste_internal (get_preferred_edit_position (false, from_context), times);
 }
 
 void
@@ -4151,7 +4012,7 @@ Editor::mouse_paste ()
 void
 Editor::paste_internal (framepos_t position, float times)
 {
-       bool commit = false;
+        DEBUG_TRACE (DEBUG::CutNPaste, string_compose ("apparent paste position is %1\n", position));
 
        if (internal_editing()) {
                if (cut_buffer->midi_notes.empty()) {
@@ -4165,10 +4026,9 @@ Editor::paste_internal (framepos_t position, float times)
 
        if (position == max_framepos) {
                position = get_preferred_edit_position();
+                DEBUG_TRACE (DEBUG::CutNPaste, string_compose ("preferred edit position is %1\n", position));
        }
 
-       begin_reversible_command (Operations::paste);
-
        TrackViewList ts;
        TrackViewList::iterator i;
        size_t nth;
@@ -4177,20 +4037,20 @@ Editor::paste_internal (framepos_t position, float times)
 
        if (!selection->tracks.empty()) {
                /* there are some selected tracks, so paste to them */
-               sort_track_selection ();
-               ts = selection->tracks;
+               ts = selection->tracks.filter_to_unique_playlists ();
+               sort_track_selection (ts);
        } else if (_last_cut_copy_source_track) {
                /* otherwise paste to the track that the cut/copy came from;
-                  see discussion in mants #3333.
+                  see discussion in mantis #3333.
                */
                ts.push_back (_last_cut_copy_source_track);
        }
 
-       for (nth = 0, i = ts.begin(); i != ts.end(); ++i, ++nth) {
+       if (internal_editing ()) {
 
                /* undo/redo is handled by individual tracks/regions */
 
-               if (internal_editing()) {
+               for (nth = 0, i = ts.begin(); i != ts.end(); ++i, ++nth) {
 
                        RegionSelection rs;
                        RegionSelection::iterator r;
@@ -4206,16 +4066,18 @@ Editor::paste_internal (framepos_t position, float times)
                                        ++cb;
                                }
                        }
+               }
 
-               } else {
+       } else {
 
-                       if ((*i)->paste (position, times, *cut_buffer, nth)) {
-                               commit = true;
-                       }
+               /* we do redo (do you do voodoo?) */
+
+               begin_reversible_command (Operations::paste);
+
+               for (nth = 0, i = ts.begin(); i != ts.end(); ++i, ++nth) {
+                       (*i)->paste (position, times, *cut_buffer, nth);
                }
-       }
 
-       if (commit) {
                commit_reversible_command ();
        }
 }
@@ -4281,7 +4143,9 @@ Editor::duplicate_selection (float times)
 
        ri = new_regions.begin();
 
-       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+
+       for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
                if ((playlist = (*i)->playlist()) == 0) {
                        continue;
                }
@@ -4360,7 +4224,9 @@ Editor::nudge_track (bool use_edit, bool forwards)
 
        begin_reversible_command (_("nudge track"));
 
-       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+
+       for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
 
                if ((playlist = (*i)->playlist()) == 0) {
                        continue;
@@ -4370,12 +4236,12 @@ Editor::nudge_track (bool use_edit, bool forwards)
                playlist->clear_owned_changes ();
 
                playlist->nudge_after (start, distance, forwards);
-               
+
                vector<Command*> cmds;
-               
+
                playlist->rdiff (cmds);
                _session->add_commands (cmds);
-               
+
                _session->add_command (new StatefulDiffCommand (playlist));
        }
 
@@ -4420,7 +4286,7 @@ Editor::normalize_region ()
        }
 
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -4453,7 +4319,7 @@ Editor::normalize_region ()
                                set_canvas_cursor (current_canvas_cursor);
                                return;
                        }
-                       
+
                        max_amps.push_back (a);
                        max_amp = max (max_amp, a);
                        dialog.ascend ();
@@ -4463,7 +4329,7 @@ Editor::normalize_region ()
        begin_reversible_command (_("normalize"));
 
        list<double>::const_iterator a = max_amps.begin ();
-       
+
        for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
                AudioRegionView* const arv = dynamic_cast<AudioRegionView*> (*r);
                if (!arv) {
@@ -4473,7 +4339,7 @@ Editor::normalize_region ()
                arv->region()->clear_changes ();
 
                double const amp = dialog.normalize_individually() ? *a : max_amp;
-               
+
                arv->audio_region()->normalize (amp, dialog.target ());
                _session->add_command (new StatefulDiffCommand (arv->region()));
 
@@ -4584,13 +4450,13 @@ Editor::strip_region_silence ()
        int const r = d.run ();
 
         d.drop_rects ();
-       
+
         if (r == Gtk::RESPONSE_OK) {
                 ARDOUR::AudioIntervalMap silences;
                 d.silences (silences);
                StripSilence s (*_session, silences, d.fade_length());
                apply_filter (s, _("strip silence"), &d);
-       } 
+       }
 }
 
 Command*
@@ -4602,7 +4468,10 @@ Editor::apply_midi_note_edit_op_to_region (MidiOperator& op, MidiRegionView& mrv
        vector<Evoral::Sequence<Evoral::MusicalTime>::Notes> v;
        v.push_back (selected);
 
-       return op (mrv.midi_region()->model(), v);
+       framepos_t pos_frames = mrv.midi_region()->position();
+       double     pos_beats  = _session->tempo_map().framewalk_to_beats(0, pos_frames);
+
+       return op (mrv.midi_region()->model(), pos_beats, v);
 }
 
 void
@@ -4661,7 +4530,7 @@ Editor::fork_region ()
                if (mrv) {
                        boost::shared_ptr<Playlist> playlist = mrv->region()->playlist();
                        boost::shared_ptr<MidiRegion> newregion = mrv->midi_region()->clone ();
-                        
+
                        playlist->clear_changes ();
                        playlist->replace_region (mrv->region(), newregion, mrv->region()->position());
                        _session->add_command(new StatefulDiffCommand (playlist));
@@ -4718,18 +4587,19 @@ Editor::quantize_region ()
 }
 
 void
-Editor::insert_patch_change ()
+Editor::insert_patch_change (bool from_context)
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
+
        if (rs.empty ()) {
                return;
        }
 
-       framepos_t const p = get_preferred_edit_position (false);
+       const framepos_t p = get_preferred_edit_position (false, from_context);
 
        Evoral::PatchChange<Evoral::MusicalTime> empty (0, 0, 0, 0);
        PatchChangeDialog d (0, _session, empty, Gtk::Stock::ADD);
-       
+
        if (d.run() == RESPONSE_CANCEL) {
                return;
        }
@@ -4760,7 +4630,7 @@ Editor::apply_filter (Filter& filter, string command, ProgressReporter* progress
 
        int n = 0;
        int const N = rs.size ();
-       
+
        for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ) {
                RegionSelection::iterator tmp = r;
                ++tmp;
@@ -4776,6 +4646,7 @@ Editor::apply_filter (Filter& filter, string command, ProgressReporter* progress
                        if (arv->audio_region()->apply (filter, progress) == 0) {
 
                                playlist->clear_changes ();
+                               playlist->clear_owned_changes ();
 
                                if (filter.results.empty ()) {
 
@@ -4798,6 +4669,13 @@ Editor::apply_filter (Filter& filter, string command, ProgressReporter* progress
 
                                }
 
+                               /* We might have removed regions, which alters other regions' layering_index,
+                                  so we need to do a recursive diff here.
+                               */
+                               vector<Command*> cmds;
+                               playlist->rdiff (cmds);
+                               _session->add_commands (cmds);
+                               
                                _session->add_command(new StatefulDiffCommand (playlist));
                        } else {
                                goto out;
@@ -4824,22 +4702,6 @@ Editor::external_edit_region ()
        /* more to come */
 }
 
-void
-Editor::brush (framepos_t pos)
-{
-       snap_to (pos);
-
-       RegionSelection rs = get_regions_from_selection_and_entered ();
-
-       if (rs.empty()) {
-               return;
-       }
-
-       for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
-               mouse_brush_insert_region ((*i), pos);
-       }
-}
-
 void
 Editor::reset_region_gain_envelopes ()
 {
@@ -4871,7 +4733,7 @@ Editor::toggle_gain_envelope_visibility ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -4898,7 +4760,7 @@ Editor::toggle_gain_envelope_active ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -4949,7 +4811,7 @@ Editor::toggle_region_lock_style ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -4974,7 +4836,7 @@ Editor::toggle_opaque_region ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -5013,6 +4875,60 @@ Editor::toggle_record_enable ()
        }
 }
 
+void
+Editor::toggle_solo ()
+{
+       bool new_state = false;
+       bool first = true;
+       boost::shared_ptr<RouteList> rl (new RouteList);
+
+       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+               RouteTimeAxisView *rtav = dynamic_cast<RouteTimeAxisView *>(*i);
+
+               if (!rtav) {
+                       continue;
+               }
+
+               if (first) {
+                       new_state = !rtav->route()->soloed ();
+                       first = false;
+               }
+
+               rl->push_back (rtav->route());
+       }
+
+       _session->set_solo (rl, new_state, Session::rt_cleanup, true);
+}
+
+void
+Editor::toggle_mute ()
+{
+       bool new_state = false;
+       bool first = true;
+       boost::shared_ptr<RouteList> rl (new RouteList);
+
+       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+               RouteTimeAxisView *rtav = dynamic_cast<RouteTimeAxisView *>(*i);
+
+               if (!rtav) {
+                       continue;
+               }
+
+               if (first) {
+                       new_state = !rtav->route()->muted();
+                       first = false;
+               }
+
+               rl->push_back (rtav->route());
+       }
+
+       _session->set_mute (rl, new_state, Session::rt_cleanup, true);
+}
+
+void
+Editor::toggle_solo_isolate ()
+{
+}
 
 void
 Editor::set_fade_length (bool in)
@@ -5166,7 +5082,7 @@ Editor::set_fade_in_active (bool yn)
 
 
                boost::shared_ptr<AudioRegion> ar (tmp->audio_region());
-               
+
                ar->clear_changes ();
                ar->set_fade_in_active (yn);
                _session->add_command (new StatefulDiffCommand (ar));
@@ -5207,7 +5123,7 @@ void
 Editor::toggle_region_fades (int dir)
 {
        boost::shared_ptr<AudioRegion> ar;
-       bool yn;
+       bool yn = false;
 
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
@@ -5215,7 +5131,7 @@ Editor::toggle_region_fades (int dir)
                return;
        }
 
-       RegionSelection::iterator i;    
+       RegionSelection::iterator i;
        for (i = rs.begin(); i != rs.end(); ++i) {
                if ((ar = boost::dynamic_pointer_cast<AudioRegion>((*i)->region())) != 0) {
                        if (dir == -1) {
@@ -5335,12 +5251,12 @@ Editor::set_playhead_cursor ()
 void
 Editor::split_region ()
 {
-       if (((mouse_mode == MouseRange) || 
-            (mouse_mode != MouseObject && _join_object_range_state == JOIN_OBJECT_RANGE_RANGE)) && 
+       if (((mouse_mode == MouseRange) ||
+            (mouse_mode != MouseObject && _join_object_range_state == JOIN_OBJECT_RANGE_RANGE)) &&
            !selection->time.empty()) {
                separate_regions_between (selection->time);
                return;
-       } 
+       }
 
        RegionSelection rs = get_regions_from_selection_and_edit_point ();
 
@@ -5599,11 +5515,42 @@ Editor::pitch_shift_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
-       if (rs.empty()) {
+       RegionSelection audio_rs;
+       for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
+               if (dynamic_cast<AudioRegionView*> (*i)) {
+                       audio_rs.push_back (*i);
+               }
+       }
+
+       if (audio_rs.empty()) {
+               return;
+       }
+
+       pitch_shift (audio_rs, 1.2);
+}
+
+void
+Editor::transpose_region ()
+{
+       RegionSelection rs = get_regions_from_selection_and_entered ();
+
+       list<MidiRegionView*> midi_region_views;
+       for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
+               MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*i);
+               if (mrv) {
+                       midi_region_views.push_back (mrv);
+               }
+       }
+
+       TransposeDialog d;
+       int const r = d.run ();
+       if (r != RESPONSE_ACCEPT) {
                return;
        }
 
-       pitch_shift (rs, 1.2);
+       for (list<MidiRegionView*>::iterator i = midi_region_views.begin(); i != midi_region_views.end(); ++i) {
+               (*i)->midi_region()->transpose (d.semitones ());
+       }
 }
 
 void
@@ -5642,7 +5589,9 @@ Editor::define_one_bar (framepos_t start, framepos_t end)
           we have frames per bar, and beats per bar, so ...
        */
 
-       double frames_per_beat = length / m.beats_per_bar();
+       /* XXXX METER MATH */
+
+       double frames_per_beat = length / m.divisions_per_bar();
 
        /* beats per minute = */
 
@@ -5675,7 +5624,7 @@ Editor::define_one_bar (framepos_t start, framepos_t end)
                        _("Do you want to set the global tempo or add a new tempo marker?"),
                        options
                        );
-               
+
                c.set_default_response (2);
 
                switch (c.run()) {
@@ -5753,9 +5702,9 @@ void
 Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList& positions, bool can_ferret, bool select_new)
 {
        bool use_rhythmic_rodent = false;
-       
+
        boost::shared_ptr<Playlist> pl = r->playlist();
-       
+
        list<boost::shared_ptr<Region> > new_regions;
 
        if (!pl) {
@@ -5786,7 +5735,7 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
 
                int response = msg.run();
                msg.hide ();
-               
+
                switch (response) {
                case RESPONSE_OK:
                        break;
@@ -5806,6 +5755,7 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
        AnalysisFeatureList::const_iterator x;
 
        pl->clear_changes ();
+       pl->clear_owned_changes ();
 
        x = positions.begin();
 
@@ -5819,7 +5769,7 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
        framepos_t pos = 0;
 
        while (x != positions.end()) {
-         
+
                /* deal with positons that are out of scope of present region bounds */
                if (*x <= 0 || *x > r->length()) {
                        ++x;
@@ -5835,7 +5785,7 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
                 */
 
                framepos_t len = (*x) - pos;
-               
+
                /* XXX we do we really want to allow even single-sample regions?
                   shouldn't we have some kind of lower limit on region size?
                */
@@ -5852,8 +5802,8 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
 
                /* do NOT announce new regions 1 by one, just wait till they are all done */
 
-               PropertyList plist; 
-               
+               PropertyList plist;
+
                plist.add (ARDOUR::Properties::start, file_start);
                plist.add (ARDOUR::Properties::length, len);
                plist.add (ARDOUR::Properties::name, new_name);
@@ -5874,10 +5824,10 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
        string new_name;
 
        RegionFactory::region_name (new_name, r->name());
-       
+
        /* Add the final region */
-       PropertyList plist; 
-               
+       PropertyList plist;
+
        plist.add (ARDOUR::Properties::start, r->start() + pos);
        plist.add (ARDOUR::Properties::length, r->last_frame() - (r->position() + pos) + 1);
        plist.add (ARDOUR::Properties::name, new_name);
@@ -5885,15 +5835,22 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
 
        boost::shared_ptr<Region> nr = RegionFactory::create (r->sources(), plist, false);
        pl->add_region (nr, r->position() + pos);
-       
+
        if (select_new) {
                new_regions.push_front(nr);
        }
 
        pl->thaw ();
 
-       _session->add_command (new StatefulDiffCommand (pl));
+       /* We might have removed regions, which alters other regions' layering_index,
+          so we need to do a recursive diff here.
+       */
+       vector<Command*> cmds;
+       pl->rdiff (cmds);
+       _session->add_commands (cmds);
        
+       _session->add_command (new StatefulDiffCommand (pl));
+
        if (select_new) {
 
                for (list<boost::shared_ptr<Region> >::iterator i = new_regions.begin(); i != new_regions.end(); ++i){
@@ -5914,16 +5871,16 @@ Editor::place_transient()
        if (rs.empty()) {
                return;
        }
-       
+
        framepos_t where = get_preferred_edit_position();
 
        _session->begin_reversible_command (_("place transient"));
-       
+
        for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
                framepos_t position = (*r)->region()->position();
                (*r)->region()->add_transient(where - position);
        }
-       
+
        _session->commit_reversible_command ();
 }
 
@@ -5945,19 +5902,19 @@ void
 Editor::snap_regions_to_grid ()
 {
        list <boost::shared_ptr<Playlist > > used_playlists;
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
                return;
        }
-       
+
        _session->begin_reversible_command (_("snap regions to grid"));
-       
+
        for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
-         
+
                boost::shared_ptr<Playlist> pl = (*r)->region()->playlist();
-         
+
                if (!pl->frozen()) {
                        /* we haven't seen this playlist before */
 
@@ -5968,9 +5925,9 @@ Editor::snap_regions_to_grid ()
 
                framepos_t start_frame = (*r)->region()->first_frame ();
                snap_to (start_frame);
-               (*r)->region()->set_position (start_frame, this);
+               (*r)->region()->set_position (start_frame);
        }
-       
+
        while (used_playlists.size() > 0) {
                list <boost::shared_ptr<Playlist > >::iterator i = used_playlists.begin();
                (*i)->thaw();
@@ -5984,7 +5941,7 @@ void
 Editor::close_region_gaps ()
 {
        list <boost::shared_ptr<Playlist > > used_playlists;
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -5999,7 +5956,7 @@ Editor::close_region_gaps ()
        Label* l = manage (new Label (_("Crossfade length")));
        l->set_alignment (0, 0.5);
        table.attach (*l, 0, 1, 0, 1);
-       
+
        SpinButton spin_crossfade (1, 0);
        spin_crossfade.set_range (0, 15);
        spin_crossfade.set_increments (1, 1);
@@ -6011,7 +5968,7 @@ Editor::close_region_gaps ()
        l = manage (new Label (_("Pull-back length")));
        l->set_alignment (0, 0.5);
        table.attach (*l, 0, 1, 1, 2);
-       
+
        SpinButton spin_pullback (1, 0);
        spin_pullback.set_range (0, 100);
        spin_pullback.set_increments (1, 1);
@@ -6019,7 +5976,7 @@ Editor::close_region_gaps ()
        table.attach (spin_pullback, 1, 2, 1, 2);
 
        table.attach (*manage (new Label (_("ms"))), 2, 3, 1, 2);
-       
+
        dialog.get_vbox()->pack_start (table);
        dialog.add_button (Stock::CANCEL, RESPONSE_CANCEL);
        dialog.add_button (_("Ok"), RESPONSE_ACCEPT);
@@ -6029,25 +5986,25 @@ Editor::close_region_gaps ()
                return;
        }
 
-       framepos_t crossfade_len = spin_crossfade.get_value(); 
+       framepos_t crossfade_len = spin_crossfade.get_value();
        framepos_t pull_back_frames = spin_pullback.get_value();
 
        crossfade_len = lrintf (crossfade_len * _session->frame_rate()/1000);
        pull_back_frames = lrintf (pull_back_frames * _session->frame_rate()/1000);
 
        /* Iterate over the region list and make adjacent regions overlap by crossfade_len_ms */
-       
+
        _session->begin_reversible_command (_("close region gaps"));
 
        int idx = 0;
        boost::shared_ptr<Region> last_region;
-       
+
        rs.sort_by_position_and_track();
-       
+
        for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
-         
+
                boost::shared_ptr<Playlist> pl = (*r)->region()->playlist();
-               
+
                if (!pl->frozen()) {
                        /* we haven't seen this playlist before */
 
@@ -6057,21 +6014,21 @@ Editor::close_region_gaps ()
                }
 
                framepos_t position = (*r)->region()->position();
-         
+
                if (idx == 0 || position < last_region->position()){
                        last_region = (*r)->region();
                        idx++;
                        continue;
                }
-               
-               (*r)->region()->trim_front( (position - pull_back_frames), this );
-               last_region->trim_end( (position - pull_back_frames + crossfade_len), this );
-               
+
+               (*r)->region()->trim_front( (position - pull_back_frames));
+               last_region->trim_end( (position - pull_back_frames + crossfade_len));
+
                last_region = (*r)->region();
-               
+
                idx++;
        }
-       
+
        while (used_playlists.size() > 0) {
                list <boost::shared_ptr<Playlist > >::iterator i = used_playlists.begin();
                (*i)->thaw();
@@ -6096,7 +6053,12 @@ Editor::tab_to_transient (bool forward)
 
        if (!selection->tracks.empty()) {
 
-               for (TrackSelection::iterator t = selection->tracks.begin(); t != selection->tracks.end(); ++t) {
+               /* don't waste time searching for transients in duplicate playlists.
+                */
+
+               TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+
+               for (TrackViewList::iterator t = ts.begin(); t != ts.end(); ++t) {
 
                        RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*t);
 
@@ -6187,7 +6149,7 @@ Editor::set_track_height (Height h)
        TrackSelection& ts (selection->tracks);
 
        for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) {
-               (*x)->set_height (h);
+               (*x)->set_height_enum (h);
        }
 }
 
@@ -6350,6 +6312,7 @@ Editor::do_insert_time ()
                get_preferred_edit_position(),
                d.distance(),
                opt,
+               d.all_playlists(),
                d.move_glued(),
                d.move_markers(),
                d.move_glued_markers(),
@@ -6359,8 +6322,10 @@ Editor::do_insert_time ()
 }
 
 void
-Editor::insert_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
-                    bool ignore_music_glue, bool markers_too, bool glued_markers_too, bool locked_markers_too, bool tempo_too)
+Editor::insert_time (
+       framepos_t pos, framecnt_t frames, InsertTimeOption opt,
+       bool all_playlists, bool ignore_music_glue, bool markers_too, bool glued_markers_too, bool locked_markers_too, bool tempo_too
+       )
 {
        bool commit = false;
 
@@ -6370,26 +6335,49 @@ Editor::insert_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
 
        begin_reversible_command (_("insert time"));
 
-       for (TrackSelection::iterator x = selection->tracks.begin(); x != selection->tracks.end(); ++x) {
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+
+       for (TrackViewList::iterator x = ts.begin(); x != ts.end(); ++x) {
+
                /* regions */
-               boost::shared_ptr<Playlist> pl = (*x)->playlist();
 
-               if (pl) {
+               /* don't operate on any playlist more than once, which could
+                * happen if "all playlists" is enabled, but there is more
+                * than 1 track using playlists "from" a given track.
+                */
 
-                       pl->clear_changes ();
-                       pl->clear_owned_changes ();
+               set<boost::shared_ptr<Playlist> > pl;
+
+               if (all_playlists) {
+                       RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*x);
+                       if (rtav) {
+                               vector<boost::shared_ptr<Playlist> > all = _session->playlists->playlists_for_track (rtav->track ());
+                               for (vector<boost::shared_ptr<Playlist> >::iterator p = all.begin(); p != all.end(); ++p) {
+                                       pl.insert (*p);
+                               }
+                       }
+               } else {
+                       if ((*x)->playlist ()) {
+                               pl.insert ((*x)->playlist ());
+                       }
+               }
+               
+               for (set<boost::shared_ptr<Playlist> >::iterator i = pl.begin(); i != pl.end(); ++i) {
+
+                       (*i)->clear_changes ();
+                       (*i)->clear_owned_changes ();
 
                        if (opt == SplitIntersected) {
-                               pl->split (pos);
+                               (*i)->split (pos);
                        }
 
-                       pl->shift (pos, frames, (opt == MoveIntersected), ignore_music_glue);
+                       (*i)->shift (pos, frames, (opt == MoveIntersected), ignore_music_glue);
 
                        vector<Command*> cmds;
-                       pl->rdiff (cmds);
+                       (*i)->rdiff (cmds);
                        _session->add_commands (cmds);
-                       
-                       _session->add_command (new StatefulDiffCommand (pl));
+
+                       _session->add_command (new StatefulDiffCommand (*i));
                        commit = true;
                }
 
@@ -6425,7 +6413,7 @@ Editor::insert_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
                                        }
                                        moved = true;
                                }
-                               
+
                        }
 
                        if (was_locked) {
@@ -6451,7 +6439,31 @@ Editor::insert_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
 void
 Editor::fit_selected_tracks ()
 {
-       fit_tracks (selection->tracks);
+        if (!selection->tracks.empty()) {
+                fit_tracks (selection->tracks);
+        } else {
+                TrackViewList tvl;
+
+                /* no selected tracks - use tracks with selected regions */
+
+                if (!selection->regions.empty()) {
+                        for (RegionSelection::iterator r = selection->regions.begin(); r != selection->regions.end(); ++r) {
+                                tvl.push_back (&(*r)->get_time_axis_view ());
+                        }
+
+                        if (!tvl.empty()) {
+                                fit_tracks (tvl);
+                        }
+                } else if (internal_editing()) {
+                        /* no selected tracks, or regions, but in internal edit mode, so follow the mouse and use
+                           the entered track
+                        */
+                        if (entered_track) {
+                                tvl.push_back (entered_track);
+                                fit_tracks (tvl);
+                        }
+                }
+        }
 }
 
 void
@@ -6611,7 +6623,7 @@ Editor::toggle_region_mute ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (rs.empty ()) {
@@ -6623,15 +6635,85 @@ Editor::toggle_region_mute ()
        } else {
                begin_reversible_command (_("mute region"));
        }
-       
+
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
-               
+
                (*i)->region()->playlist()->clear_changes ();
                (*i)->region()->set_muted (!(*i)->region()->muted ());
                _session->add_command (new StatefulDiffCommand ((*i)->region()->playlist()));
-               
+
        }
-       
+
+       commit_reversible_command ();
+}
+
+void
+Editor::combine_regions ()
+{
+       /* foreach track with selected regions, take all selected regions
+          and join them into a new region containing the subregions (as a
+          playlist)
+       */
+
+       typedef set<RouteTimeAxisView*> RTVS;
+       RTVS tracks;
+
+       if (selection->regions.empty()) {
+               return;
+       }
+
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&(*i)->get_time_axis_view());
+
+               if (rtv) {
+                       tracks.insert (rtv);
+               }
+       }
+
+       begin_reversible_command (_("combine regions"));
+
+       vector<RegionView*> new_selection;
+
+       for (RTVS::iterator i = tracks.begin(); i != tracks.end(); ++i) {
+               RegionView* rv;
+
+               if ((rv = (*i)->combine_regions ()) != 0) {
+                       new_selection.push_back (rv);
+               }
+       }
+
+       selection->clear_regions ();
+       for (vector<RegionView*>::iterator i = new_selection.begin(); i != new_selection.end(); ++i) {
+               selection->add (*i);
+       }
+
+       commit_reversible_command ();
+}
+
+void
+Editor::uncombine_regions ()
+{
+       typedef set<RouteTimeAxisView*> RTVS;
+       RTVS tracks;
+
+       if (selection->regions.empty()) {
+               return;
+       }
+
+       for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&(*i)->get_time_axis_view());
+
+               if (rtv) {
+                       tracks.insert (rtv);
+               }
+       }
+
+       begin_reversible_command (_("uncombine regions"));
+
+       for (RTVS::iterator i = tracks.begin(); i != tracks.end(); ++i) {
+               (*i)->uncombine_regions ();
+       }
+
        commit_reversible_command ();
 }