remove OS X specific code for key editor binding displays
[ardour.git] / gtk2_ardour / editor_ops.cc
index e1efaa268b2e35c80c2c30ab4873fe0a9a65770d..c598af2453c4fcad2e2f98ee58432a384d8ecff6 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"
@@ -106,6 +104,10 @@ using Gtkmm2ext::Keyboard;
 void
 Editor::undo (uint32_t n)
 {
+       if (_drags->active ()) {
+               _drags->abort ();
+       }
+       
        if (_session) {
                _session->undo (n);
        }
@@ -114,6 +116,10 @@ Editor::undo (uint32_t n)
 void
 Editor::redo (uint32_t n)
 {
+       if (_drags->active ()) {
+               _drags->abort ();
+       }
+       
        if (_session) {
                _session->redo (n);
        }
@@ -146,7 +152,7 @@ Editor::split_regions_at (framepos_t where, RegionSelection& regions)
                }
        } else {
                snap_to (where);
-               
+
                frozen = true;
                EditorFreeze(); /* Emit Signal */
        }
@@ -198,7 +204,7 @@ Editor::split_regions_at (framepos_t where, RegionSelection& regions)
        }
 
        commit_reversible_command ();
-       
+
        if (frozen){
                EditorThaw(); /* Emit Signal */
        }
@@ -245,7 +251,7 @@ Editor::move_range_selection_start_or_end_to_region_boundary (bool move_end, boo
        if (end < start) {
                return;
        }
-       
+
        begin_reversible_command (_("alter selection"));
        selection->set_preserving_all_ranges (start, end);
        commit_reversible_command ();
@@ -379,7 +385,7 @@ Editor::nudge_backward (bool next, bool force_playhead)
                        if (next) {
                                distance = next_distance;
                        }
-                        
+
                        r->clear_changes ();
 
                        if (r->position() > distance) {
@@ -453,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);
                _session->add_command(new StatefulDiffCommand (r));
        }
-       
+
        commit_reversible_command ();
 }
 
@@ -483,14 +489,14 @@ 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);
                } else {
@@ -498,7 +504,7 @@ Editor::nudge_backward_capture_offset ()
                }
                _session->add_command(new StatefulDiffCommand (r));
        }
-       
+
        commit_reversible_command ();
 }
 
@@ -705,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) {
@@ -1238,7 +1244,7 @@ Editor::scroll_tracks_down ()
        if (vert_value > vertical_adjustment.get_upper() - _canvas_height) {
                vert_value = vertical_adjustment.get_upper() - _canvas_height;
        }
-       
+
        vertical_adjustment.set_value (vert_value);
 }
 
@@ -1256,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);
 }
 
@@ -1709,7 +1715,7 @@ void
 Editor::add_locations_from_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -1736,7 +1742,7 @@ void
 Editor::add_location_from_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -1808,11 +1814,11 @@ Editor::set_mark ()
 
        string markername;
        _session->locations()->next_available_name (markername, "mark");
-       
+
        if (!choose_new_marker_name (markername)) {
                return;
        }
-       
+
        _session->locations()->add (new Location (*_session, pos, 0, markername, Location::IsMark), true);
 }
 
@@ -1838,11 +1844,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));
@@ -1936,7 +1944,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;
 
@@ -1949,7 +1956,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) {
@@ -2168,7 +2175,7 @@ void
 Editor::rename_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -2191,7 +2198,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));
@@ -2207,7 +2214,7 @@ Editor::rename_region ()
        if (ret != RESPONSE_OK) {
                return;
        }
-       
+
        std::string str = entry.get_text();
        strip_whitespace_edges (str);
        if (!str.empty()) {
@@ -2253,7 +2260,7 @@ Editor::play_selected_region ()
        framepos_t end = 0;
 
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -2311,8 +2318,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);
@@ -2351,8 +2358,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);
@@ -2365,7 +2372,7 @@ void
 Editor::split_multichannel_region ()
 {
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -2483,12 +2490,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;
@@ -2591,7 +2598,7 @@ Editor::separate_under_selected_regions ()
        vector<PlaylistState> playlists;
 
        RegionSelection rs;
-       
+
        rs = get_regions_from_selection_and_entered();
 
        if (!_session || rs.empty()) {
@@ -2645,7 +2652,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() );
        }
@@ -2871,20 +2878,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 ();
 }
 
@@ -2902,13 +2909,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 ();
                _session->add_command (new StatefulDiffCommand ((*i)->region()));
        }
-       
+
        commit_reversible_command ();
 }
 
@@ -2916,7 +2923,7 @@ void
 Editor::align_regions (RegionPoint what)
 {
        RegionSelection const rs = get_regions_from_selection_and_edit_point ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -2942,7 +2949,7 @@ void
 Editor::align_regions_relative (RegionPoint point)
 {
        RegionSelection const rs = get_regions_from_selection_and_edit_point ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -3018,7 +3025,7 @@ Editor::align_regions_relative (RegionPoint point)
                } else {
                        region->set_position (region->position() - distance);
                }
-                
+
                _session->add_command(new StatefulDiffCommand (region));
 
        }
@@ -3089,15 +3096,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);
                        } else {
                                (*i)->region()->trim_end (where);
                        }
-                       
+
                        _session->add_command (new StatefulDiffCommand ((*i)->region()));
                }
        }
@@ -3159,7 +3166,7 @@ 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));
                _session->add_command(new StatefulDiffCommand (rv->region()));
@@ -3274,6 +3281,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;
        }
@@ -3355,9 +3370,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));
@@ -3375,6 +3394,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 ()
@@ -3427,6 +3453,9 @@ Editor::cut_copy (CutCopyOp op)
        string opname;
 
        switch (op) {
+       case Delete:
+               opname = _("delete");
+               break;
        case Cut:
                opname = _("cut");
                break;
@@ -3444,7 +3473,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 ();
                }
@@ -3497,7 +3526,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 ();
                                        }
                                }
@@ -3505,11 +3534,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
                        }
@@ -3532,7 +3560,7 @@ Editor::cut_copy (CutCopyOp op)
                        cut_copy_ranges (op);
                        commit_reversible_command ();
 
-                       if (op == Cut) {
+                       if (op == Cut || op == Delete) {
                                selection->clear_time ();
                        }
 
@@ -3543,7 +3571,7 @@ Editor::cut_copy (CutCopyOp op)
                }
        }
 
-       if (op == Cut || op == Clear) {
+       if (op == Delete || op == Cut || op == Clear) {
                _drags->abort ();
        }
 }
@@ -3703,13 +3731,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;
@@ -3757,22 +3785,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();
@@ -3781,6 +3812,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);
@@ -3793,34 +3828,37 @@ 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;
+       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));
@@ -3916,15 +3954,15 @@ Editor::paste_internal (framepos_t position, float times)
        if (internal_editing ()) {
 
                /* undo/redo is handled by individual tracks/regions */
-               
+
                for (nth = 0, i = ts.begin(); i != ts.end(); ++i, ++nth) {
-                       
+
                        RegionSelection rs;
                        RegionSelection::iterator r;
                        MidiNoteSelection::iterator cb;
-                       
+
                        get_regions_at (rs, position, ts);
-                       
+
                        for (cb = cut_buffer->midi_notes.begin(), r = rs.begin();
                             cb != cut_buffer->midi_notes.end() && r != rs.end(); ++r) {
                                MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*r);
@@ -3934,17 +3972,17 @@ Editor::paste_internal (framepos_t position, float times)
                                }
                        }
                }
-               
+
        } else {
 
                /* 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);
                }
-               
+
                commit_reversible_command ();
        }
 }
@@ -4099,12 +4137,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));
        }
 
@@ -4149,7 +4187,7 @@ Editor::normalize_region ()
        }
 
        RegionSelection rs = get_regions_from_selection_and_entered ();
-       
+
        if (rs.empty()) {
                return;
        }
@@ -4182,7 +4220,7 @@ Editor::normalize_region ()
                                set_canvas_cursor (current_canvas_cursor);
                                return;
                        }
-                       
+
                        max_amps.push_back (a);
                        max_amp = max (max_amp, a);
                        dialog.ascend ();
@@ -4192,7 +4230,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) {
@@ -4202,7 +4240,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()));
 
@@ -4313,13 +4351,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*
@@ -4331,7 +4369,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
@@ -4390,7 +4431,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));
@@ -4458,7 +4499,7 @@ Editor::insert_patch_change ()
 
        Evoral::PatchChange<Evoral::MusicalTime> empty (0, 0, 0, 0);
        PatchChangeDialog d (0, _session, empty, Gtk::Stock::ADD);
-       
+
        if (d.run() == RESPONSE_CANCEL) {
                return;
        }
@@ -4489,7 +4530,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;
@@ -4584,7 +4625,7 @@ Editor::toggle_gain_envelope_visibility ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -4611,7 +4652,7 @@ Editor::toggle_gain_envelope_active ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -4662,7 +4703,7 @@ Editor::toggle_region_lock_style ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -4687,7 +4728,7 @@ Editor::toggle_opaque_region ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (!_session || rs.empty()) {
@@ -4726,6 +4767,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)
@@ -4879,7 +4974,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));
@@ -4920,7 +5015,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 ();
 
@@ -4928,7 +5023,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) {
@@ -5048,12 +5143,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 ();
 
@@ -5419,7 +5514,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()) {
@@ -5497,9 +5592,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) {
@@ -5530,7 +5625,7 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
 
                int response = msg.run();
                msg.hide ();
-               
+
                switch (response) {
                case RESPONSE_OK:
                        break;
@@ -5563,7 +5658,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;
@@ -5579,7 +5674,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?
                */
@@ -5596,8 +5691,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);
@@ -5618,10 +5713,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);
@@ -5629,7 +5724,7 @@ 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);
        }
@@ -5637,7 +5732,7 @@ Editor::split_region_at_points (boost::shared_ptr<Region> r, AnalysisFeatureList
        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){
@@ -5658,16 +5753,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 ();
 }
 
@@ -5689,19 +5784,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 */
 
@@ -5714,7 +5809,7 @@ Editor::snap_regions_to_grid ()
                snap_to (start_frame);
                (*r)->region()->set_position (start_frame);
        }
-       
+
        while (used_playlists.size() > 0) {
                list <boost::shared_ptr<Playlist > >::iterator i = used_playlists.begin();
                (*i)->thaw();
@@ -5728,7 +5823,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()) {
@@ -5743,7 +5838,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);
@@ -5755,7 +5850,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);
@@ -5763,7 +5858,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);
@@ -5773,25 +5868,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 */
 
@@ -5801,21 +5896,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));
                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();
@@ -6094,6 +6189,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(),
@@ -6103,8 +6199,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;
 
@@ -6115,25 +6213,37 @@ 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) {
+
                /* regions */
-               boost::shared_ptr<Playlist> pl = (*x)->playlist();
 
-               if (pl) {
+               vector<boost::shared_ptr<Playlist> > pl;
+               if (all_playlists) {
+                       RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*x);
+                       if (rtav) {
+                               pl = _session->playlists->playlists_for_track (rtav->track ());
+                       }
+               } else {
+                       if ((*x)->playlist ()) {
+                               pl.push_back ((*x)->playlist ());
+                       }
+               }
 
-                       pl->clear_changes ();
-                       pl->clear_owned_changes ();
+               for (vector<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;
                }
 
@@ -6169,7 +6279,7 @@ Editor::insert_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
                                        }
                                        moved = true;
                                }
-                               
+
                        }
 
                        if (was_locked) {
@@ -6206,7 +6316,7 @@ Editor::fit_selected_tracks ()
                         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);
                         }
@@ -6379,7 +6489,7 @@ Editor::toggle_region_mute ()
        if (_ignore_region_action) {
                return;
        }
-       
+
        RegionSelection rs = get_regions_from_selection_and_entered ();
 
        if (rs.empty ()) {
@@ -6391,15 +6501,15 @@ 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 ();
 }
 
@@ -6427,7 +6537,7 @@ Editor::combine_regions ()
        }
 
        begin_reversible_command (_("combine regions"));
-       
+
        vector<RegionView*> new_selection;
 
        for (RTVS::iterator i = tracks.begin(); i != tracks.end(); ++i) {