implement a delete operation that works like "cut" but doesn't put the deleted items...
[ardour.git] / gtk2_ardour / editor_ops.cc
index 5bddc13891507d8c863d8eb232c862d576d45590..9c541191b4f8a908f3b4c5222a50c7cc69c11896 100644 (file)
 #include "ardour/quantize.h"
 #include "ardour/strip_silence.h"
 #include "ardour/route_group.h"
+#include "ardour/operations.h"
 
 #include "ardour_ui.h"
+#include "debug.h"
 #include "editor.h"
 #include "time_axis_view.h"
 #include "route_time_axis.h"
@@ -84,6 +86,8 @@
 #include "normalize_dialog.h"
 #include "editor_cursors.h"
 #include "mouse_cursors.h"
+#include "patch_change_dialog.h"
+#include "transpose_dialog.h"
 
 #include "i18n.h"
 
@@ -118,6 +122,8 @@ Editor::redo (uint32_t n)
 void
 Editor::split_regions_at (framepos_t where, RegionSelection& regions)
 {
+       bool frozen = false;
+
        list <boost::shared_ptr<Playlist > > used_playlists;
 
        if (regions.empty()) {
@@ -140,6 +146,9 @@ Editor::split_regions_at (framepos_t where, RegionSelection& regions)
                }
        } else {
                snap_to (where);
+
+               frozen = true;
+               EditorFreeze(); /* Emit Signal */
        }
 
        for (RegionSelection::iterator a = regions.begin(); a != regions.end(); ) {
@@ -189,94 +198,56 @@ Editor::split_regions_at (framepos_t where, RegionSelection& regions)
        }
 
        commit_reversible_command ();
-}
-
-boost::shared_ptr<Region>
-Editor::select_region_for_operation (int /*dir*/, TimeAxisView **tv)
-{
-       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->regions.empty()) {
-
-               rv = *(selection->regions.begin());
-               (*tv) = &rv->get_time_axis_view();
-               region = rv->region();
-
-       } 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);
-               }
+       if (frozen){
+               EditorThaw(); /* Emit Signal */
        }
-
-       return region;
 }
 
+/** 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::extend_selection_to_end_of_region (bool next)
+Editor::move_range_selection_start_or_end_to_region_boundary (bool move_end, bool next)
 {
-       TimeAxisView *tv;
-       boost::shared_ptr<Region> region;
-       framepos_t start;
-
-       if ((region = select_region_for_operation (next ? 1 : 0, &tv)) == 0) {
+       if (selection->time.start() == selection->time.end_frame()) {
                return;
        }
 
-       if (region && selection->time.start () == selection->time.end_frame ()) {
-               start = region->position();
-       } else {
-               start = selection->time.start ();
-       }
+       framepos_t start = selection->time.start ();
+       framepos_t end = selection->time.end_frame ();
 
-       begin_reversible_command (_("extend selection"));
-       selection->set (start, region->position() + region->length());
-       commit_reversible_command ();
-}
+       /* the position of the thing we may move */
+       framepos_t pos = move_end ? end : start;
+       int dir = next ? 1 : -1;
 
-void
-Editor::extend_selection_to_start_of_region (bool previous)
-{
-       TimeAxisView *tv;
-       boost::shared_ptr<Region> region;
-       framepos_t end;
+       /* so we don't find the current region again */
+       if (dir > 0 || pos > 0) {
+               pos += dir;
+       }
 
-       if ((region = select_region_for_operation (previous ? -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 ()) {
-               end = region->position() + region->length();
+       if (move_end) {
+               end = target;
        } else {
-               end = selection->time.end_frame ();
+               start = target;
        }
 
-       /* Try to leave the selection with the same route if possible */
+       if (end < start) {
+               return;
+       }
 
-       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 ();
 }
 
@@ -329,7 +300,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));
                }
 
@@ -408,13 +379,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));
                }
@@ -482,23 +453,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 ();
 }
 
@@ -512,22 +483,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 ();
 }
 
@@ -734,7 +705,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) {
@@ -861,7 +832,7 @@ Editor::cursor_to_region_point (EditorCursor* cursor, RegionPoint point, int32_t
                return;
        }
 
-       switch (point){
+       switch (point) {
        case Start:
                pos = r->first_frame ();
                break;
@@ -1052,7 +1023,7 @@ Editor::selected_marker_to_region_point (RegionPoint point, int32_t dir)
                return;
        }
 
-       switch (point){
+       switch (point) {
        case Start:
                pos = r->first_frame ();
                break;
@@ -1195,68 +1166,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)
 {
@@ -1290,98 +1199,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 {
@@ -1394,22 +1218,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 {
@@ -1422,38 +1234,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
@@ -1464,7 +1256,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);
 }
 
@@ -1712,7 +1504,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);
                        }
                }
 
@@ -1752,13 +1544,13 @@ Editor::temporal_zoom_session ()
        ENSURE_GUI_THREAD (*this, &Editor::temporal_zoom_session)
 
        if (_session) {
-               nframes_t const l = _session->current_end_frame() - _session->current_start_frame();
+               framecnt_t const l = _session->current_end_frame() - _session->current_start_frame();
                double s = _session->current_start_frame() - l * 0.01;
                if (s < 0) {
                        s = 0;
                }
-               nframes_t const e = _session->current_end_frame() + l * 0.01;
-               temporal_zoom_by_frame (nframes_t (s), e, "zoom to _session");
+               framecnt_t const e = _session->current_end_frame() + l * 0.01;
+               temporal_zoom_by_frame (framecnt_t (s), e, "zoom to _session");
        }
 }
 
@@ -1814,10 +1606,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);
 }
@@ -1917,7 +1709,7 @@ void
 Editor::add_locations_from_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -1944,7 +1736,7 @@ void
 Editor::add_location_from_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -1975,59 +1767,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
@@ -2065,25 +1804,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);
 }
 
@@ -2207,7 +1936,7 @@ Editor::insert_route_list_drag (boost::shared_ptr<Route> route, int x, int y)
 {
        double wx, wy;
        double cx, cy;
-       nframes_t where;
+       framepos_t where;
        RouteTimeAxisView *dest_rtv = 0;
        RouteTimeAxisView *source_rtv = 0;
 
@@ -2439,7 +2168,7 @@ void
 Editor::rename_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -2478,7 +2207,7 @@ Editor::rename_region ()
        if (ret != RESPONSE_OK) {
                return;
        }
-       
+
        std::string str = entry.get_text();
        strip_whitespace_edges (str);
        if (!str.empty()) {
@@ -2524,7 +2253,7 @@ Editor::play_selected_region ()
        framepos_t end = 0;
 
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -2582,8 +2311,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);
@@ -2622,8 +2351,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);
@@ -2636,7 +2365,7 @@ void
 Editor::split_multichannel_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -2754,12 +2483,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;
@@ -2861,7 +2590,9 @@ Editor::separate_under_selected_regions ()
 {
        vector<PlaylistState> playlists;
 
-       RegionSelection rs = get_regions_from_selection_and_entered ();
+       RegionSelection rs;
+
+       rs = get_regions_from_selection_and_entered();
 
        if (!_session || rs.empty()) {
                return;
@@ -2914,7 +2645,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() );
        }
@@ -3013,7 +2744,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));
        }
 
@@ -3031,7 +2762,7 @@ Editor::region_fill_track ()
 
        framepos_t const end = _session->current_end_frame ();
 
-       begin_reversible_command (_("region fill"));
+       begin_reversible_command (Operations::region_fill);
 
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
 
@@ -3085,7 +2816,7 @@ Editor::region_fill_selection ()
        framepos_t selection_length = end - start;
        float times = (float)selection_length / region->length();
 
-       begin_reversible_command (_("fill selection"));
+       begin_reversible_command (Operations::fill_selection);
 
        for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
 
@@ -3140,20 +2871,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 ();
 }
 
@@ -3171,13 +2902,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 ();
 }
 
@@ -3185,7 +2916,7 @@ void
 Editor::align_regions (RegionPoint what)
 {
        RegionSelection const rs = get_regions_from_selection_and_edit_point ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -3211,7 +2942,7 @@ void
 Editor::align_regions_relative (RegionPoint point)
 {
        RegionSelection const rs = get_regions_from_selection_and_edit_point ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -3269,7 +3000,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 */
@@ -3283,11 +3014,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));
 
        }
@@ -3310,17 +3041,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;
        }
 
@@ -3358,15 +3089,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()));
                }
        }
@@ -3428,9 +3159,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()));
        }
 
@@ -3484,15 +3215,15 @@ Editor::trim_to_region(bool forward)
 
                region->clear_changes ();
 
-               if(forward){
+               if (forward) {
 
                    next_region = playlist->find_next_region (region->first_frame(), Start, 1);
 
-                   if(!next_region){
+                   if (!next_region) {
                        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 {
@@ -3503,7 +3234,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);
                }
@@ -3547,6 +3278,19 @@ Editor::freeze_route ()
                return;
        }
 
+       if (!clicked_routeview->track()->bounceable()) {
+               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_routeview);
+               if (rtv && !rtv->track()->bounceable()) {
+                       MessageDialog d (
+                               _("This route cannot be frozen because it has more outputs than inputs.  "
+                                 "You can fix this by increasing the number of inputs.")
+                               );
+                       d.set_title (_("Cannot freeze"));
+                       d.run ();
+                       return;
+               }
+       }
+
        InterThreadInfo itt;
        current_interthread_info = &itt;
 
@@ -3573,6 +3317,20 @@ Editor::bounce_range_selection (bool replace, bool enable_processing)
 
        TrackSelection views = selection->tracks;
 
+       for (TrackViewList::iterator i = views.begin(); i != views.end(); ++i) {
+               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
+               if (rtv && rtv->track() && replace && enable_processing && !rtv->track()->bounceable()) {
+                       MessageDialog d (
+                               _("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 ();
+                       return;
+               }
+       }
+
        framepos_t start = selection->time[clicked_selection].start;
        framepos_t end = selection->time[clicked_selection].end;
        framepos_t cnt = end - start + 1;
@@ -3597,7 +3355,7 @@ 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 (replace) {
@@ -3617,6 +3375,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 ()
@@ -3669,6 +3434,9 @@ Editor::cut_copy (CutCopyOp op)
        string opname;
 
        switch (op) {
+       case Delete:
+               opname = _("delete");
+               break;
        case Cut:
                opname = _("cut");
                break;
@@ -3686,7 +3454,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 ();
                }
@@ -3739,7 +3507,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 ();
                                        }
                                }
@@ -3747,7 +3515,7 @@ Editor::cut_copy (CutCopyOp op)
                                if (!selection->points.empty()) {
                                        cut_copy_points (op);
 
-                                       if (op == Cut) {
+                                       if (op == Cut || op == Delete) {
                                                selection->clear_points ();
                                        }
                                }
@@ -3774,7 +3542,7 @@ Editor::cut_copy (CutCopyOp op)
                        cut_copy_ranges (op);
                        commit_reversible_command ();
 
-                       if (op == Cut) {
+                       if (op == Cut || op == Delete) {
                                selection->clear_time ();
                        }
 
@@ -3785,7 +3553,7 @@ Editor::cut_copy (CutCopyOp op)
                }
        }
 
-       if (op == Cut || op == Clear) {
+       if (op == Delete || op == Cut || op == Clear) {
                _drags->abort ();
        }
 }
@@ -3799,6 +3567,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);
@@ -3944,13 +3713,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,22 +3767,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();
@@ -4022,6 +3794,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);
@@ -4031,9 +3807,7 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs)
                case Copy:
                        /* copy region before adding, so we're not putting same object into two different playlists */
                        npl->add_region (RegionFactory::create (r), r->position() - first_position);
-                       break;
-
-               case Clear:
+                                       case Clear:
                        pl->remove_region (r);
                        break;
                }
@@ -4041,27 +3815,30 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs)
                x = tmp;
        }
 
-       list<boost::shared_ptr<Playlist> > foo;
+       if (op != Delete) {
 
-       /* 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);
+               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 ();
                _session->add_command (new StatefulDiffCommand (*pl));
@@ -4074,6 +3851,13 @@ Editor::cut_copy_ranges (CutCopyOp op)
        TrackViewList* ts;
        TrackViewList entered;
 
+       /* 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 (&selection->tracks);
+
        if (selection->tracks.empty()) {
                if (!entered_track) {
                        return;
@@ -4092,6 +3876,7 @@ Editor::cut_copy_ranges (CutCopyOp op)
 void
 Editor::paste (float times)
 {
+        DEBUG_TRACE (DEBUG::CutNPaste, "paste to preferred edit pos\n");
        paste_internal (get_preferred_edit_position(), times);
 }
 
@@ -4112,7 +3897,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()) {
@@ -4126,10 +3911,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 (_("paste"));
-
        TrackViewList ts;
        TrackViewList::iterator i;
        size_t nth;
@@ -4142,16 +3926,16 @@ Editor::paste_internal (framepos_t position, float times)
                ts = selection->tracks;
        } 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;
@@ -4167,16 +3951,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 ();
        }
 }
@@ -4188,10 +3974,10 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times)
        RegionSelection sel = regions; // clear (below) may  clear the argument list if its the current region selection
        RegionSelection foo;
 
-       nframes_t const start_frame = regions.start ();
-       nframes_t const end_frame = regions.end_frame ();
+       framepos_t const start_frame = regions.start ();
+       framepos_t const end_frame = regions.end_frame ();
 
-       begin_reversible_command (_("duplicate region"));
+       begin_reversible_command (Operations::duplicate_region);
 
        selection->clear_regions ();
 
@@ -4331,12 +4117,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));
        }
 
@@ -4381,7 +4167,7 @@ Editor::normalize_region ()
        }
 
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -4414,7 +4200,7 @@ Editor::normalize_region ()
                                set_canvas_cursor (current_canvas_cursor);
                                return;
                        }
-                       
+
                        max_amps.push_back (a);
                        max_amp = max (max_amp, a);
                        dialog.ascend ();
@@ -4424,7 +4210,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) {
@@ -4434,7 +4220,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()));
 
@@ -4491,28 +4277,16 @@ Editor::adjust_region_gain (bool up)
                }
 
                arv->region()->clear_changes ();
-                
-               double fraction = gain_to_slider_position (arv->audio_region()->scale_amplitude ());
+
+               double dB = accurate_coefficient_to_dB (arv->audio_region()->scale_amplitude ());
 
                if (up) {
-                       fraction += 0.05;
-                       fraction = min (fraction, 1.0);
+                       dB += 1;
                } else {
-                       fraction -= 0.05;
-                       fraction = max (fraction, 0.0);
+                       dB -= 1;
                }
 
-               if (!up && fraction <= 0) {
-                       continue;
-               }
-
-               fraction = slider_position_to_gain (fraction);
-
-               if (up && fraction >= 2.0) {
-                       continue;
-               }
-
-               arv->audio_region()->set_scale_amplitude (fraction);
+               arv->audio_region()->set_scale_amplitude (dB_to_coefficient (dB));
                _session->add_command (new StatefulDiffCommand (arv->region()));
        }
 
@@ -4544,20 +4318,24 @@ Editor::strip_region_silence ()
                return;
        }
 
-       std::list<boost::shared_ptr<AudioRegion> > ar;
+       std::list<RegionView*> audio_only;
 
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
                AudioRegionView* const arv = dynamic_cast<AudioRegionView*> (*i);
                if (arv) {
-                       ar.push_back (arv->audio_region ());
+                       audio_only.push_back (arv);
                }
        }
 
-       StripSilenceDialog d (_session, ar);
+       StripSilenceDialog d (_session, audio_only);
        int const r = d.run ();
 
-       if (r == Gtk::RESPONSE_OK) {
-               StripSilence s (*_session, d.threshold (), d.minimum_length (), d.fade_length ());
+        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);
        }
 }
@@ -4571,7 +4349,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
@@ -4630,7 +4411,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));
@@ -4659,10 +4440,7 @@ Editor::quantize_region ()
                return;
        }
 
-       for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ) {
-               RegionSelection::iterator tmp = r;
-               ++tmp;
-
+       for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
                MidiRegionView* const mrv = dynamic_cast<MidiRegionView*> (*r);
                if (mrv) {
                        selected_midi_region_cnt++;
@@ -4689,6 +4467,33 @@ Editor::quantize_region ()
        }
 }
 
+void
+Editor::insert_patch_change ()
+{
+       RegionSelection rs = get_regions_from_selection_and_entered ();
+       if (rs.empty ()) {
+               return;
+       }
+
+       framepos_t const p = get_preferred_edit_position (false);
+
+       Evoral::PatchChange<Evoral::MusicalTime> empty (0, 0, 0, 0);
+       PatchChangeDialog d (0, _session, empty, Gtk::Stock::ADD);
+
+       if (d.run() == RESPONSE_CANCEL) {
+               return;
+       }
+
+       for (RegionSelection::iterator i = rs.begin (); i != rs.end(); ++i) {
+               MidiRegionView* const mrv = dynamic_cast<MidiRegionView*> (*i);
+               if (mrv) {
+                       if (p >= mrv->region()->first_frame() && p <= mrv->region()->last_frame()) {
+                               mrv->add_patch_change (p - mrv->region()->position(), d.patch ());
+                       }
+               }
+       }
+}
+
 void
 Editor::apply_filter (Filter& filter, string command, ProgressReporter* progress)
 {
@@ -4705,7 +4510,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;
@@ -4769,22 +4574,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 ()
 {
@@ -4816,7 +4605,7 @@ Editor::toggle_gain_envelope_visibility ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -4843,7 +4632,7 @@ Editor::toggle_gain_envelope_active ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -4894,7 +4683,7 @@ Editor::toggle_region_lock_style ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -4919,7 +4708,7 @@ Editor::toggle_opaque_region ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -5111,7 +4900,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));
@@ -5160,7 +4949,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) {
@@ -5280,12 +5069,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 ();
 
@@ -5544,11 +5333,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
@@ -5620,7 +5440,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()) {
@@ -5695,12 +5515,14 @@ Editor::split_region_at_transients ()
 }
 
 void
-Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList& positions, bool can_ferret)
+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) {
                return;
        }
@@ -5710,7 +5532,7 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
        }
 
 
-       if (positions.size() > 20) {
+       if (positions.size() > 20 && can_ferret) {
                std::string msgstr = string_compose (_("You are about to split\n%1\ninto %2 pieces.\nThis could take a long time."), r->name(), positions.size() + 1);
                MessageDialog msg (msgstr,
                                   false,
@@ -5729,7 +5551,7 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
 
                int response = msg.run();
                msg.hide ();
-               
+
                switch (response) {
                case RESPONSE_OK:
                        break;
@@ -5762,9 +5584,9 @@ 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()){
+               if (*x <= 0 || *x > r->length()) {
                        ++x;
                        continue;
                }
@@ -5778,7 +5600,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?
                */
@@ -5795,16 +5617,21 @@ 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);
                plist.add (ARDOUR::Properties::layer, 0);
 
                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);
+               }
+
                pos += len;
                ++x;
        }
@@ -5812,10 +5639,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);
@@ -5824,10 +5651,20 @@ 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));
+
+       if (select_new) {
+
+               for (list<boost::shared_ptr<Region> >::iterator i = new_regions.begin(); i != new_regions.end(); ++i){
+                       set_selected_regionview_from_region_list ((*i), Selection::Add);
+               }
+       }
 }
 
 void
@@ -5842,16 +5679,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 ();
 }
 
@@ -5862,36 +5699,57 @@ Editor::remove_transient(ArdourCanvas::Item* item)
                return;
        }
 
-       ArdourCanvas::SimpleLine* _line = reinterpret_cast<ArdourCanvas::SimpleLine*> (item);
+       ArdourCanvas::Line* _line = reinterpret_cast<ArdourCanvas::Line*> (item);
        assert (_line);
 
        AudioRegionView* _arv = reinterpret_cast<AudioRegionView*> (item->get_data ("regionview"));
-       _arv->remove_transient(_line->property_x1());
+       _arv->remove_transient (*(float*) _line->get_data ("position"));
 }
 
 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 */
+
+                       /* remember used playlists so we can thaw them later */
+                       used_playlists.push_back(pl);
+                       pl->freeze();
+               }
+
                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();
+               used_playlists.pop_front();
+       }
+
        _session->commit_reversible_command ();
 }
 
 void
 Editor::close_region_gaps ()
-{      
+{
+       list <boost::shared_ptr<Playlist > > used_playlists;
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -5906,11 +5764,11 @@ 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);
-       spin_crossfade.set_value (3);
+       spin_crossfade.set_value (5);
        table.attach (spin_crossfade, 1, 2, 0, 1);
 
        table.attach (*manage (new Label (_("ms"))), 2, 3, 0, 1);
@@ -5918,15 +5776,15 @@ 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, 15);
+       spin_pullback.set_range (0, 100);
        spin_pullback.set_increments (1, 1);
-       spin_pullback.set_value (5);
+       spin_pullback.set_value(30);
        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);
@@ -5936,39 +5794,55 @@ 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 */
+
+                       /* remember used playlists so we can thaw them later */
+                       used_playlists.push_back(pl);
+                       pl->freeze();
+               }
+
                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();
+               used_playlists.pop_front();
+       }
+
        _session->commit_reversible_command ();
 }
 
@@ -6078,7 +5952,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);
        }
 }
 
@@ -6101,7 +5975,7 @@ Editor::toggle_tracks_active ()
                                target = !rtv->_route->active();
                                first = false;
                        }
-                       rtv->_route->set_active (target);
+                       rtv->_route->set_active (target, this);
                }
        }
 }
@@ -6157,9 +6031,9 @@ edit your ardour.rc file to set the\n\
                msg.run ();
                return;
        }
-                
+
        if (ntracks + nbusses == 0) {
-               return;
+               return;
        }
 
        if (ntracks > 1) {
@@ -6279,7 +6153,7 @@ Editor::insert_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
                        vector<Command*> cmds;
                        pl->rdiff (cmds);
                        _session->add_commands (cmds);
-                       
+
                        _session->add_command (new StatefulDiffCommand (pl));
                        commit = true;
                }
@@ -6316,7 +6190,7 @@ Editor::insert_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
                                        }
                                        moved = true;
                                }
-                               
+
                        }
 
                        if (was_locked) {
@@ -6342,7 +6216,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
@@ -6353,6 +6251,7 @@ Editor::fit_tracks (TrackViewList & tracks)
        }
 
        uint32_t child_heights = 0;
+       int visible_tracks = 0;
 
        for (TrackSelection::iterator t = tracks.begin(); t != tracks.end(); ++t) {
 
@@ -6361,9 +6260,10 @@ Editor::fit_tracks (TrackViewList & tracks)
                }
 
                child_heights += (*t)->effective_height() - (*t)->current_height();
+               ++visible_tracks;
        }
 
-       uint32_t h = (uint32_t) floor ((_canvas_height - child_heights - canvas_timebars_vsize) / tracks.size());
+       uint32_t h = (uint32_t) floor ((_canvas_height - child_heights - canvas_timebars_vsize) / visible_tracks);
        double first_y_pos = DBL_MAX;
 
        if (h < TimeAxisView::preset_height (HeightSmall)) {
@@ -6404,12 +6304,14 @@ Editor::fit_tracks (TrackViewList & tracks)
                        next_is_selected = false;
                }
 
-               if (is_selected) {
-                       (*t)->set_height (h);
-                       first_y_pos = std::min ((*t)->y_position (), first_y_pos);
-               } else {
-                       if (prev_was_selected && next_is_selected) {
-                               hide_track_in_display (*t);
+               if ((*t)->marked_for_display ()) {
+                       if (is_selected) {
+                               (*t)->set_height (h);
+                               first_y_pos = std::min ((*t)->y_position (), first_y_pos);
+                       } else {
+                               if (prev_was_selected && next_is_selected) {
+                                       hide_track_in_display (*t);
+                               }
                        }
                }
 
@@ -6498,7 +6400,7 @@ Editor::toggle_region_mute ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (rs.empty ()) {
@@ -6510,15 +6412,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 ();
 }