Fix crash on "Consolidate Range" on MIDI tracks (#4226).
[ardour.git] / gtk2_ardour / editor_ops.cc
index 29471aa913d5a05a995ac5058c70d6a8a29407f5..8ba2115003d29b0bb8a621dd11651d16bed39de9 100644 (file)
@@ -56,6 +56,7 @@
 #include "ardour/strip_silence.h"
 #include "ardour/route_group.h"
 #include "ardour/operations.h"
+#include "ardour/session_playlists.h"
 
 #include "ardour_ui.h"
 #include "debug.h"
@@ -1838,11 +1839,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));
@@ -2190,7 +2193,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));
@@ -3365,6 +3368,10 @@ Editor::bounce_range_selection (bool replace, bool enable_processing)
 
                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));
@@ -4795,7 +4802,7 @@ Editor::toggle_mute ()
                }
 
                if (first) {
-                       new_state = !rtav->route()->soloed ();
+                       new_state = !rtav->route()->muted();
                        first = false;
                }
 
@@ -5003,7 +5010,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 ();
 
@@ -6177,6 +6184,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(),
@@ -6186,8 +6194,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;
 
@@ -6198,25 +6208,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;
                }