+ if (!_session) {
+ return;
+ }
+
+ if (rs.empty()) {
+ return;
+ }
+
+ begin_reversible_command (_("remove region"));
+
+ list<boost::shared_ptr<Region> > regions_to_remove;
+
+ for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
+ // we can't just remove the region(s) in this loop because
+ // this removes them from the RegionSelection, and they thus
+ // disappear from underneath the iterator, and the ++i above
+ // SEGVs in a puzzling fashion.
+
+ // so, first iterate over the regions to be removed from rs and
+ // add them to the regions_to_remove list, and then
+ // iterate over the list to actually remove them.
+
+ regions_to_remove.push_back ((*i)->region());
+ }
+
+ vector<boost::shared_ptr<Playlist> > playlists;
+
+ for (list<boost::shared_ptr<Region> >::iterator rl = regions_to_remove.begin(); rl != regions_to_remove.end(); ++rl) {
+
+ boost::shared_ptr<Playlist> playlist = (*rl)->playlist();
+
+ if (!playlist) {
+ // is this check necessary?
+ continue;
+ }
+
+ vector<boost::shared_ptr<Playlist> >::iterator i;
+
+ //only prep history if this is a new playlist.
+ for (i = playlists.begin(); i != playlists.end(); ++i) {
+ if ((*i) == playlist) {
+ break;
+ }
+ }
+
+ if (i == playlists.end()) {
+
+ playlist->clear_history ();
+ playlist->freeze ();
+
+ playlists.push_back (playlist);
+ }
+
+ playlist->remove_region (*rl);
+ }
+
+ vector<boost::shared_ptr<Playlist> >::iterator pl;
+
+ for (pl = playlists.begin(); pl != playlists.end(); ++pl) {
+ (*pl)->thaw ();
+ _session->add_command(new StatefulDiffCommand (*pl));
+ }
+
+ commit_reversible_command ();
+}
+
+/** Cut, copy or clear selected regions.
+ * @param op Operation (Cut, Copy or Clear)
+ */
+void
+Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs)
+{
+ /* we can't use a std::map here because the ordering is important, and we can't trivially sort
+ a map when we want ordered access to both elements. i think.
+ */
+
+ vector<PlaylistMapping> pmap;
+
+ nframes64_t first_position = max_frames;
+
+ typedef set<boost::shared_ptr<Playlist> > FreezeList;
+ FreezeList freezelist;
+
+ /* get ordering correct before we cut/copy */
+
+ rs.sort_by_position_and_track ();
+
+ for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
+
+ first_position = min ((nframes64_t) (*x)->region()->position(), first_position);
+
+ if (op == Cut || op == Clear) {