From 048d03ecd8e7ff745f4d877f58c246b8bf87938b Mon Sep 17 00:00:00 2001 From: GZharun Date: Wed, 1 Oct 2014 17:56:06 +0300 Subject: [PATCH] [Summary] When range sellection covers multiple regions all of them will be processed by range drag --- gtk2_ardour/editor.h | 4 +- gtk2_ardour/editor_mouse.cc | 54 ++------------- gtk2_ardour/editor_ops.cc | 120 ++++++++++++++------------------- gtk2_ardour/route_time_axis.cc | 40 ++++++----- gtk2_ardour/route_time_axis.h | 2 +- 5 files changed, 84 insertions(+), 136 deletions(-) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 7ed780cdee..183e06f125 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1195,8 +1195,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD void keyboard_paste (); void region_from_selection (); - void create_region_from_selection (std::vector >&, RouteTimeAxisView*); - void cut_region_from_selection (std::vector >&, RouteTimeAxisView*); + void create_region_from_selection (std::vector >&); + void cut_copy_region_from_selection (RegionSelection& new_regions, RouteTimeAxisView* rtv, bool follow_track_selection = false, bool copy = false); void play_from_start (); void play_from_edit_point (); diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index b67cdf6694..2aa72bb569 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -2458,66 +2458,24 @@ Editor::add_region_brush_drag (ArdourCanvas::Item* item, GdkEvent*, RegionView* void Editor::start_selection_grab (ArdourCanvas::Item* item, RouteTimeAxisView* rtv, GdkEvent* event, bool copy/*=false*/) { - if (rtv == 0) { - return; - } - /* lets try to create new Region for the selection */ - - vector > new_regions; - begin_reversible_command (_("new region for selection drag")); - if (copy) { - create_region_from_selection (new_regions, rtv); - } else { - cut_region_from_selection (new_regions, rtv); - } + + RegionSelection new_regions; + cut_copy_region_from_selection (new_regions, rtv, true, copy); + commit_reversible_command (); if (new_regions.empty()) { return; } - /* XXX fix me one day to use all new regions */ - boost::shared_ptr region (new_regions.front()); - - /* add it to the current stream/playlist. - - tricky: the streamview for the track will add a new regionview. we will - catch the signal it sends when it creates the regionview to - set the regionview we want to then drag. - */ - - latest_regionviews.clear(); - sigc::connection c = rtv->view()->RegionViewAdded.connect (sigc::mem_fun(*this, &Editor::collect_new_region_view)); - - /* A selection grab currently creates two undo/redo operations, one for - creating the new region and another for moving it. - */ - - begin_reversible_command (Operations::selection_grab); - - boost::shared_ptr playlist = rtv->playlist(); - - playlist->clear_changes (); - rtv->playlist()->add_region (region, selection->time[clicked_selection].start); - _session->add_command(new StatefulDiffCommand (playlist)); - - commit_reversible_command (); - - c.disconnect (); - - if (latest_regionviews.empty()) { - /* something went wrong */ - return; - } - /* we need to deselect all other regionviews, and select this one i'm ignoring undo stuff, because the region creation will take care of it */ - selection->set (latest_regionviews); + selection->set (new_regions); - _drags->set (new RegionMoveDrag (this, latest_regionviews.front()->get_canvas_group(), latest_regionviews.front(), latest_regionviews, false, false), event); + _drags->set (new RegionMoveDrag (this, new_regions.front()->get_canvas_group(), new_regions.front(), latest_regionviews, false, false), event); } void diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index bb19269006..1b3b2fb15e 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -2673,7 +2673,7 @@ Editor::region_from_selection () } void -Editor::create_region_from_selection (vector >& new_regions, RouteTimeAxisView* rtv) +Editor::create_region_from_selection (vector >& new_regions) { new_regions.clear (); @@ -2687,89 +2687,73 @@ Editor::create_region_from_selection (vector >& new_re TrackViewList ts = selection->tracks.filter_to_unique_playlists (); sort_track_selection (ts); - if (rtv) { + for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) { boost::shared_ptr current; - boost::shared_ptr playlist; - framepos_t internal_start; - string new_name; - - if ((playlist = rtv->playlist()) == 0) { - return; - } - - if ((current = playlist->top_region_at(start)) == 0) { - return; - } - - internal_start = start - current->position(); - RegionFactory::region_name (new_name, current->name(), true); - - 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); - - new_regions.push_back (RegionFactory::create (current, plist)); - - } else { - - for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) { - boost::shared_ptr current; - boost::shared_ptr playlist; - framepos_t internal_start; - string new_name; + boost::shared_ptr playlist; + framepos_t internal_start; + string new_name; - if ((playlist = (*i)->playlist()) == 0) { - continue; - } - - if ((current = playlist->top_region_at(start)) == 0) { - continue; - } - - internal_start = start - current->position(); - RegionFactory::region_name (new_name, current->name(), true); - - 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); - - new_regions.push_back (RegionFactory::create (current, plist)); + if ((playlist = (*i)->playlist()) == 0) { + continue; } + + if ((current = playlist->top_region_at(start)) == 0) { + continue; + } + + internal_start = start - current->position(); + RegionFactory::region_name (new_name, current->name(), true); + + 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); + + new_regions.push_back (RegionFactory::create (current, plist)); } } void -Editor::cut_region_from_selection (vector >& new_regions, RouteTimeAxisView* rtv) +Editor::cut_copy_region_from_selection (RegionSelection& new_regions, RouteTimeAxisView* rtv, bool follow_track_selection/*=false*/, bool copy /*=false*/) { new_regions.clear(); - if (selection->time.empty() || selection->tracks.empty() || !rtv) { + if (selection->time.empty() || selection->tracks.empty() ) { return; } - AudioRange range = selection->time[clicked_selection]; - - rtv->cut_range(range); - rtv->paste(range.start, 1, *cut_buffer, 0); - - boost::shared_ptr current; - boost::shared_ptr playlist; - if ((playlist = rtv->playlist() ) == 0) { - return; + TrackViewList ts; + if (follow_track_selection) { + ts = selection->tracks.filter_to_unique_playlists (); + sort_track_selection (ts); + } else { + if (rtv) { + ts.push_back(rtv); + } } - if ((current = playlist->top_region_at(range.start) ) == 0) { - return; + latest_regionviews.clear(); + for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) { + + RouteTimeAxisView* route_view = dynamic_cast (*i); + + if (!route_view) { + continue; + } + + Selection new_items(this); + route_view->cut_copy_range(*selection, copy, new_items); + + sigc::connection c = route_view->view()->RegionViewAdded.connect (sigc::mem_fun(*this, &Editor::collect_new_region_view)); + + AudioRange range = selection->time[clicked_selection]; + route_view->paste(range.start, 1, new_items, 0); + + c.disconnect (); } - playlist->clear_changes (); - playlist->remove_region (current); - - new_regions.push_back( current ); + new_regions = latest_regionviews; } @@ -4561,7 +4545,7 @@ Editor::duplicate_selection (float times) vector > new_regions; vector >::iterator ri; - create_region_from_selection (new_regions, NULL); + create_region_from_selection (new_regions); if (new_regions.empty()) { return; diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index 9450b34e28..c09b11f1c7 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -1434,8 +1434,10 @@ RouteTimeAxisView::fade_range (TimeSelection& selection) } void -RouteTimeAxisView::cut_range (ARDOUR::AudioRange& range) +RouteTimeAxisView::cut_copy_range (Selection& selection, bool copy, Selection& new_items) { + new_items.clear(); + boost::shared_ptr what_we_got; boost::shared_ptr tr = track (); boost::shared_ptr playlist; @@ -1447,28 +1449,32 @@ RouteTimeAxisView::cut_range (ARDOUR::AudioRange& range) playlist = tr->playlist(); - float const speed = tr->speed(); - if (speed != 1.0f) { - range.start = session_frame_to_track_frame(range.start, speed); - range.end = session_frame_to_track_frame(range.end, speed); - } + TimeSelection time (selection.time); + float const speed = tr->speed(); + if (speed != 1.0f) { + for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) { + (*i).start = session_frame_to_track_frame((*i).start, speed); + (*i).end = session_frame_to_track_frame((*i).end, speed); + } + } playlist->clear_changes (); playlist->clear_owned_changes (); - std::list audio_ranges; - audio_ranges.push_back(range); - if ((what_we_got = playlist->cut (audio_ranges)) != 0) { - _editor.get_cut_buffer().set (what_we_got); - if (Config->get_edit_mode() == Ripple) - playlist->ripple(range.start, -range.length(), NULL); - // no need to exclude any regions from rippling here + if (copy) { - vector cmds; - playlist->rdiff (cmds); - _session->add_commands (cmds); + if ((what_we_got = playlist->copy (time)) != 0) { + new_items.set (what_we_got); + } + + } else { + + if ((what_we_got = playlist->cut (time)) != 0) { + new_items.set (what_we_got); + if (Config->get_edit_mode() == Ripple) + playlist->ripple(time.start(), -time.length(), NULL); + } - _session->add_command (new StatefulDiffCommand (playlist)); } } diff --git a/gtk2_ardour/route_time_axis.h b/gtk2_ardour/route_time_axis.h index df9f7e4d84..b132534b3c 100644 --- a/gtk2_ardour/route_time_axis.h +++ b/gtk2_ardour/route_time_axis.h @@ -108,7 +108,7 @@ public: void uncombine_region (RegionView*); void toggle_automation_track (const Evoral::Parameter& param); void fade_range (TimeSelection&); - void cut_range (ARDOUR::AudioRange& range); + void cut_copy_range (Selection& selection, bool copy, Selection& new_items); /* The editor calls these when mapping an operation across multiple tracks */ void use_new_playlist (bool prompt, std::vector > const &);