13
0

fix region un/combine, based on a patch by Tom Brand

This commit is contained in:
Robin Gareus 2014-06-16 00:51:45 +02:00
parent c7c3c1e924
commit c8fd1d26eb
2 changed files with 22 additions and 1 deletions

View File

@ -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__ */

View File

@ -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;