summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2014-06-16 00:51:45 +0200
committerRobin Gareus <robin@gareus.org>2014-06-16 00:51:45 +0200
commitc8fd1d26eb6a1a47f3a4507b4e32263623ac84cf (patch)
tree1dc5b255c818a8161564b398fc0669e153abbecf /libs/ardour
parentc7c3c1e924bc28e5c54e62ea3d9883ae2fe005fd (diff)
fix region un/combine, based on a patch by Tom Brand
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/ardour/region_sorters.h13
-rw-r--r--libs/ardour/playlist.cc10
2 files changed, 22 insertions, 1 deletions
diff --git a/libs/ardour/ardour/region_sorters.h b/libs/ardour/ardour/region_sorters.h
index 9fd739a4da..3afd66bf3c 100644
--- a/libs/ardour/ardour/region_sorters.h
+++ b/libs/ardour/ardour/region_sorters.h
@@ -36,6 +36,19 @@ struct LIBARDOUR_API RegionSortByLayer {
}
};
+/* sort by RegionSortByLayerAndPosition()
+ * is equivalent to
+ * stable_sort by RegionSortByPosition();
+ * stable_sort by RegionSortByLayer();
+ */
+struct LIBARDOUR_API RegionSortByLayerAndPosition {
+ bool operator() (boost::shared_ptr<Region> a, boost::shared_ptr<Region> b) {
+ return
+ (a->layer() < b->layer() && a->position() < b->position())
+ || (a->layer() == b->layer() && a->position() < b->position());
+ }
+};
+
} // namespace
#endif /* __libardour_region_sorters_h__ */
diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc
index 47462a3575..d0720b985d 100644
--- a/libs/ardour/playlist.cc
+++ b/libs/ardour/playlist.cc
@@ -2809,7 +2809,14 @@ Playlist::combine (const RegionList& r)
pl->in_partition = true;
- for (RegionList::const_iterator i = r.begin(); i != r.end(); ++i) {
+ /* sort by position then layer.
+ * route_time_axis passes 'selected_regions' - which is not sorted.
+ * here we need the top-most first, then every layer's region softed by position.
+ */
+ RegionList sorted(r);
+ sorted.sort(RegionSortByLayerAndPosition());
+
+ for (RegionList::const_iterator i = sorted.begin(); i != sorted.end(); ++i) {
/* copy the region */
@@ -3050,6 +3057,7 @@ Playlist::uncombine (boost::shared_ptr<Region> target)
for (vector<boost::shared_ptr<Region> >::iterator i = originals.begin(); i != originals.end(); ++i) {
add_region ((*i), (*i)->position());
+ set_layer((*i), (*i)->layer());
}
in_partition = false;