From 08d8478f6674c2e1ce729ae8226b9ce133120f4f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 1 May 2021 17:30:39 +0200 Subject: [PATCH] Cleanup and speedup combine/uncombine Collect signal emissions and remove unneeded locks when operating on the newly created Playlist. --- libs/ardour/playlist.cc | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index edb29c5537..2dda48c08c 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -3045,6 +3045,7 @@ Playlist::find_next_top_layer_position (samplepos_t t) const boost::shared_ptr Playlist::combine (const RegionList& r) { + ThawList thawlist; PropertyList plist; uint32_t channels = 0; uint32_t layer = 0; @@ -3088,7 +3089,7 @@ Playlist::combine (const RegionList& r) /* copy the region */ boost::shared_ptr original_region = (*i); - boost::shared_ptr copied_region = RegionFactory::create (original_region, false); + boost::shared_ptr copied_region = RegionFactory::create (original_region, false, false, &thawlist); old_and_new_regions.push_back (TwoRegions (original_region, copied_region)); originals.push_back (original_region); @@ -3097,9 +3098,7 @@ Playlist::combine (const RegionList& r) RegionFactory::add_compound_association (original_region, copied_region); /* make position relative to zero */ - - pl->add_region (copied_region, original_region->position () - earliest_position); - copied_region->set_layer (original_region->layer ()); + pl->add_region_internal (copied_region, original_region->position () - earliest_position, thawlist); /* use the maximum number of channels for any region */ @@ -3112,12 +3111,13 @@ Playlist::combine (const RegionList& r) pl->in_partition = false; + /* pre-process. e.g. disable audio region fades */ pre_combine (copies); /* now create a new PlaylistSource for each channel in the new playlist */ SourceList sources; - pair extent = pl->get_extent (); + pair extent = pl->_get_extent (); for (uint32_t chn = 0; chn < channels; ++chn) { sources.push_back (SourceFactory::createFromPlaylist (_type, _session, pl, id (), parent_name, chn, 0, extent.second, false, false)); @@ -3130,7 +3130,7 @@ Playlist::combine (const RegionList& r) plist.add (Properties::name, parent_name); plist.add (Properties::whole_file, true); - boost::shared_ptr parent_region = RegionFactory::create (sources, plist, true); + boost::shared_ptr parent_region = RegionFactory::create (sources, plist, true, &thawlist); /* now the non-whole-file region that we will actually use in the playlist */ @@ -3140,7 +3140,7 @@ Playlist::combine (const RegionList& r) plist.add (Properties::name, child_name); plist.add (Properties::layer, layer + 1); - boost::shared_ptr compound_region = RegionFactory::create (parent_region, plist, true); + boost::shared_ptr compound_region = RegionFactory::create (parent_region, plist, true, &thawlist); for (SourceList::iterator s = sources.begin (); s != sources.end (); ++s) { boost::dynamic_pointer_cast (*s)->set_owner (compound_region->id ()); @@ -3164,6 +3164,7 @@ Playlist::combine (const RegionList& r) _combine_ops++; + thawlist.release (); thaw (); return compound_region; @@ -3221,6 +3222,8 @@ Playlist::uncombine (boost::shared_ptr target) const bool need_copies = (boost::dynamic_pointer_cast (pls)->owner () != target->id ()) || (pls->original () != id ()); + ThawList thawlist; + for (RegionList::const_iterator i = rl.begin (); i != rl.end (); ++i) { boost::shared_ptr current (*i); @@ -3240,10 +3243,12 @@ Playlist::uncombine (boost::shared_ptr target) adjusted_end = adjusted_start + target->length (); } - if (need_copies) { + if (!need_copies) { + thawlist.add (original); + } else { samplepos_t pos = original->position (); /* make a copy, but don't announce it */ - original = RegionFactory::create (original, false); + original = RegionFactory::create (original, false, false, &thawlist); /* the pure copy constructor resets position() to zero, so fix that up. */ original->set_position (pos); } @@ -3329,6 +3334,7 @@ Playlist::uncombine (boost::shared_ptr target) in_partition = false; thaw (); + thawlist.release (); } void