- frozen_insert_result = frozen_playlists.insert(playlist);
-
- if (frozen_insert_result.second) {
- playlist->freeze();
- }
-
- cerr << "Moving region " << rv->region()->id() << endl;
-
- rv->region()->set_position (where, (void*) this);
-
- sdc.push_back (new StatefulDiffCommand (rv->region()));
- }
-
- if (changed_tracks && !_copy) {
-
- /* get the playlist where this drag started. we can't use rv->region()->playlist()
- because we may have copied the region and it has not been attached to a playlist.
- */
-
- source_tv = dynamic_cast<RouteTimeAxisView*> (&rv->get_time_axis_view());
- tr = source_tv->track();
- from_playlist = tr->playlist();
-
- assert (source_tv);
- assert (tr);
- assert (from_playlist);
-
- /* moved to a different audio track, without copying */
-
- /* the region that used to be in the old playlist is not
- moved to the new one - we use a copy of it. as a result,
- any existing editor for the region should no longer be
- visible.
- */
-
- rv->hide_region_editor();
- rv->fake_set_opaque (false);
-
- /* remove the region from the old playlist */
-
- insert_result = modified_playlists.insert (from_playlist);
-
- if (insert_result.second) {
- from_playlist->clear_history ();
- }
-
- cerr << "From playlist " << from_playlist->name() << " region history contains "
- << from_playlist->region_list().change().added.size() << " adds and "
- << from_playlist->region_list().change().removed.size() << " removes\n";
-
- cerr << "removing region " << rv->region() << endl;
-
- from_playlist->remove_region (rv->region());
-
- /* OK, this is where it gets tricky. If the playlist was being used by >1 tracks, and the region
- was selected in all of them, then removing it from a playlist will have removed all
- trace of it from the selection (i.e. there were N regions selected, we removed 1,
- but since its the same playlist for N tracks, all N tracks updated themselves, removed the
- corresponding regionview, and the selection is now empty).
-
- this could have invalidated any and all iterators into the region selection.
-
- the heuristic we use here is: if the region selection is empty, break out of the loop
- here. if the region selection is not empty, then restart the loop because we know that
- we must have removed at least the region(view) we've just been working on as well as any
- that we processed on previous iterations.
-
- EXCEPT .... if we are doing a copy drag, then the selection hasn't been modified and
- we can just iterate.
- */
-
- if (_views.empty()) {
- if (to_playlist) {
- sdc.push_back (new StatefulDiffCommand (to_playlist));
- cerr << "Saved diff for to:" << to_playlist->name() << endl;
- }
-
- if (from_playlist && (from_playlist != to_playlist)) {
- sdc.push_back (new StatefulDiffCommand (from_playlist));
- cerr << "Saved diff for from:" << from_playlist->name() << endl;
- }
- break;
- } else {
- i = _views.begin();
- }
-
- } else {
- ++i;
- }
-
- if (_copy) {
- copies.push_back (rv);
- }
-
- cerr << "Done with TV, top = " << to_playlist << " from = " << from_playlist << endl;
-
- if (to_playlist) {
- sdc.push_back (new StatefulDiffCommand (to_playlist));
- cerr << "Saved diff for to:" << to_playlist->name() << endl;
- }
-
- if (from_playlist && (from_playlist != to_playlist)) {
- sdc.push_back (new StatefulDiffCommand (from_playlist));
- cerr << "Saved diff for from:" << from_playlist->name() << endl;
- }
- }
-
- /*
- if we've created new regions either by copying or moving
- to a new track, we want to replace the old selection with the new ones
- */
-
- if (new_views.size() > 0) {
- _editor->selection->set (new_views);
- }
-
- for (set<boost::shared_ptr<Playlist> >::iterator p = frozen_playlists.begin(); p != frozen_playlists.end(); ++p) {
- (*p)->thaw();
- }
-
- out:
- for (vector<StatefulDiffCommand*>::iterator i = sdc.begin(); i != sdc.end(); ++i) {
- _editor->session()->add_command (*i);
- }
-
- _editor->commit_reversible_command ();
-
- for (vector<RegionView*>::iterator x = copies.begin(); x != copies.end(); ++x) {
- delete *x;
- }
-}
-
-void
-RegionMoveDrag::aborted ()
-{
- if (_copy) {
-
- for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
- delete i->view;
- }
-
- _views.clear ();
-
- } else {
- RegionMotionDrag::aborted ();
- }
-}