From 72761734e84d86e0beca53610dd7a18851060dd0 Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Wed, 27 Sep 2023 10:56:53 -0500 Subject: [PATCH] region groups: more fixes for drag-copy and range-paste operations --- gtk2_ardour/editor_audio_import.cc | 2 +- gtk2_ardour/editor_drag.cc | 3 +++ gtk2_ardour/editor_ops.cc | 4 ++-- libs/ardour/ardour/region.h | 4 ++-- libs/ardour/playlist.cc | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc index cea6b128f5..fd223ef231 100644 --- a/gtk2_ardour/editor_audio_import.cc +++ b/gtk2_ardour/editor_audio_import.cc @@ -1059,7 +1059,7 @@ Editor::finish_bringing_in_material (std::shared_ptr region, std::shared_ptr playlist = existing_track->playlist(); std::shared_ptr copy (RegionFactory::create (region, region->derive_properties ())); - copy->set_region_group(false); + copy->set_region_group(Region::get_retained_group_id()); playlist->clear_changes (); playlist->clear_owned_changes (); playlist->add_region (copy, pos); diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index cbea04b3a9..f3fd23cecb 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -1549,6 +1549,8 @@ RegionMoveDrag::motion (GdkEvent* event, bool first_move) /* duplicate the regionview(s) and region(s) */ + Region::RegionGroupRetainer rtr; + list new_regionviews; for (list::const_iterator i = _views.begin (); i != _views.end (); ++i) { @@ -1560,6 +1562,7 @@ RegionMoveDrag::motion (GdkEvent* event, bool first_move) std::shared_ptr region_copy; region_copy = RegionFactory::create (original, true); + region_copy->set_region_group( Region::get_region_operation_group_id (original->region_group(), Paste)); /* need to set this so that the drop zone code can work. This doesn't actually put the region into the playlist, but just sets a weak pointer diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 90980097b1..44c432bd7f 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -3126,7 +3126,7 @@ Editor::group_selected_regions () begin_reversible_command (_("group regions")); for (RegionSelection::iterator i = rs.begin (); i != rs.end (); ++i) { (*i)->region ()->clear_changes (); - (*i)->region ()->set_region_group (true); + (*i)->region ()->set_region_group (Region::get_retained_group_id(), true); _session->add_command (new StatefulDiffCommand ((*i)->region ())); } commit_reversible_command (); @@ -3144,7 +3144,7 @@ Editor::ungroup_selected_regions () begin_reversible_command (_("ungroup regions")); for (RegionSelection::iterator i = rs.begin (); i != rs.end (); ++i) { (*i)->region ()->clear_changes (); - (*i)->region ()->unset_region_group (); + (*i)->region ()->unset_region_group (true); _session->add_command (new StatefulDiffCommand ((*i)->region ())); } selection->clear_regions (); diff --git a/libs/ardour/ardour/region.h b/libs/ardour/ardour/region.h index 789790b1a1..60023a5db4 100644 --- a/libs/ardour/ardour/region.h +++ b/libs/ardour/ardour/region.h @@ -209,8 +209,8 @@ public: static uint64_t get_region_operation_group_id (uint64_t old_region_group, RegionOperationFlag flags); uint64_t region_group () const { return _reg_group; } - void set_region_group (bool explicitly) { _reg_group = get_retained_group_id () | (explicitly ? Explicit : NoGroup); } - void unset_region_group () { _reg_group = Explicit; } + void set_region_group (uint64_t rg, bool explicitly = false) { _reg_group = rg | (explicitly ? Explicit : NoGroup); } + void unset_region_group (bool explicitly = false) { _reg_group = (explicitly ? Explicit : NoGroup); } bool is_explicitly_grouped() { return (_reg_group & Explicit) == Explicit; } bool is_implicitly_ungrouped() { return (_reg_group == NoGroup); } diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index aae1b2b443..5b59e221be 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -1318,8 +1318,8 @@ Playlist::paste (std::shared_ptr other, timepos_t const & position, fl for (auto const & r : other->regions) { std::shared_ptr copy_of_region = RegionFactory::create (r, true, false, &rl1.thawlist); - /* we want newly-pasted regions to share one (implicit) group-id */ - copy_of_region->set_region_group(false); + /* we want newly-pasted regions to retain prior group-sharing relationship, but with a new group-id */ + copy_of_region->set_region_group (Region::get_region_operation_group_id(r->region_group(), Paste)); /* put these new regions on top of all existing ones, but preserve the ordering they had in the original playlist.