From 481334ae2a313e684897f3096107c2a832ca5759 Mon Sep 17 00:00:00 2001 From: Julien ROGER Date: Wed, 30 Nov 2016 17:02:20 +0100 Subject: Proposed fix managing shared playlists (see #7150) Actually, when duplicating a track with "share playlist", the current playlist is owned by the new created track(orig-track-id). The sharing mecanism is made by diskstreams pointing on the same(shared) playlist. Since playlist now owned by the new track, selecting another playlist in the original track "forgets" the playlist for this track.You can't select the shared playlist anymore from the original track. This commit adds a way to keep trace of shared playlist between tracks. --- libs/ardour/playlist.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'libs/ardour/playlist.cc') diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index cc6c0d3f40..d38c8d57bd 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -26,6 +26,7 @@ #include "pbd/convert.h" #include "pbd/stateful_diff_command.h" +#include "pbd/strsplit.h" #include "pbd/xml++.h" #include "ardour/debug.h" @@ -157,6 +158,7 @@ Playlist::Playlist (boost::shared_ptr other, string namestr, boo , regions (*this) , _type(other->_type) , _orig_track_id (other->_orig_track_id) + , _shared_with_ids (other->_shared_with_ids) { init (hide); @@ -189,6 +191,7 @@ Playlist::Playlist (boost::shared_ptr other, framepos_t start, f , regions (*this) , _type(other->_type) , _orig_track_id (other->_orig_track_id) + , _shared_with_ids (other->_shared_with_ids) { RegionReadLock rlock2 (const_cast (other.get())); @@ -2234,6 +2237,16 @@ Playlist::find_next_region (framepos_t frame, RegionPoint point, int dir) _frozen = string_is_affirmative (prop->value()); } else if (prop->name() == X_("combine-ops")) { _combine_ops = atoi (prop->value()); + } else if (prop->name() == X_("shared-with-ids")) { + string shared_ids = prop->value (); + if (!shared_ids.empty()) { + vector result; + ::split (shared_ids, result, ','); + vector::iterator it = result.begin(); + for (; it != result.end(); ++it) { + _shared_with_ids.push_back (PBD::ID(*it)); + } + } } } @@ -2321,6 +2334,17 @@ Playlist::state (bool full_state) _orig_track_id.print (buf, sizeof (buf)); node->add_property (X_("orig-track-id"), buf); + + string shared_ids; + list::const_iterator it = _shared_with_ids.begin(); + for (; it != _shared_with_ids.end(); ++it) { + shared_ids += "," + (*it).to_s(); + } + if (!shared_ids.empty()) { + shared_ids.erase(0,1); + } + + node->add_property (X_("shared-with-ids"), shared_ids); node->add_property (X_("frozen"), _frozen ? "yes" : "no"); if (full_state) { @@ -3317,9 +3341,56 @@ Playlist::max_source_level () const void Playlist::set_orig_track_id (const PBD::ID& id) { + if (shared_with(id)) { + // Swap 'shared_id' / origin_track_id + unshare_with (id); + share_with (_orig_track_id); + } _orig_track_id = id; } +void +Playlist::share_with (const PBD::ID& id) +{ + if (!shared_with(id)) { + _shared_with_ids.push_back (id); + } +} + +void +Playlist::unshare_with (const PBD::ID& id) +{ + list::iterator it = _shared_with_ids.begin (); + while (it != _shared_with_ids.end()) { + if (*it == id) { + _shared_with_ids.erase (it); + break; + } + ++it; + } +} + +bool +Playlist::shared_with (const PBD::ID& id) const +{ + bool shared = false; + list::const_iterator it = _shared_with_ids.begin (); + while (it != _shared_with_ids.end() && !shared) { + if (*it == id) { + shared = true; + } + ++it; + } + + return shared; +} + +void +Playlist::reset_shares () +{ + _shared_with_ids.clear(); +} + /** Take a list of ranges, coalesce any that can be coalesced, then call * check_crossfades for each one. */ -- cgit v1.2.3