From 4cdac290290d24265089c3ffa0379a500b5d15dc Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 21 Jul 2023 13:48:50 -0600 Subject: [PATCH] attempt to follow time domain changes in playlists when tracks change --- libs/ardour/playlist.cc | 10 ++++++++++ libs/ardour/region.cc | 9 +++++++++ libs/ardour/track.cc | 17 +++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index b251f1c5a5..066bf72dbe 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -3516,6 +3516,16 @@ Playlist::globally_change_time_domain (Temporal::TimeDomain from, Temporal::Time void Playlist::time_domain_changed () { + using namespace Temporal; + TimeDomainProvider::time_domain_changed (); + + Temporal::TimeDomain to = time_domain(); + Temporal::TimeDomain from = (to == AudioTime ? BeatTime : AudioTime); + + for (auto & region : regions) { + region->change_time_domain (from, to); + } + } diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index f7c91592eb..1b341293ab 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -2205,3 +2205,12 @@ Region::globally_change_time_domain (Temporal::TimeDomain from, Temporal::TimeDo std::cerr << "new domain after GCTD " << _length.val() << std::endl; } } + +void +Region::change_time_domain (Temporal::TimeDomain from, Temporal::TimeDomain to) +{ + if (_length.val().time_domain() == from) { + timecnt_t& l (_length.non_const_val()); + l.set_time_domain (to); + } +} diff --git a/libs/ardour/track.cc b/libs/ardour/track.cc index ced688a030..37b42ac807 100644 --- a/libs/ardour/track.cc +++ b/libs/ardour/track.cc @@ -712,12 +712,29 @@ Track::use_playlist (DataType dt, std::shared_ptr p, bool set_orig) if (rl->size () > 0) { Region::RegionsPropertyChanged (rl, Properties::hidden); } + /* we don't know for certain that we controlled the old + * playlist's time domain, but it's a pretty good guess. If it + * has an actual parent, revert to using its parent's domain + */ + if (old->time_domain_parent()) { + old->clear_time_domain (); + } } + if (p) { std::shared_ptr rl (new RegionList (p->region_list_property ().rlist ())); if (rl->size () > 0) { Region::RegionsPropertyChanged (rl, Properties::hidden); } + + /* If the playlist has no time domain parent or its parent is + * the session, reset to the explicit time domain of this + * track. + */ + + if (!p->time_domain_parent() || p->time_domain_parent() == &_session) { + p->set_time_domain (time_domain()); + } } _session.set_dirty ();