X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplaylist.cc;h=c54b24c1c947e3bc78c134c74fc36f0e30468ee5;hb=d98bdad019ba9be5d800dece0414d7a080609027;hp=e9ea3e3c7143179afbb82e3ee4dfb331a75b7dcf;hpb=9db14938dda095b0693148386ee1c2e7cc882481;p=dcpomatic.git diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index e9ea3e3c7..c54b24c1c 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -72,7 +72,6 @@ Playlist::content_changed (weak_ptr content, int property, bool frequen ContentChanged (content, property, frequent); } - void Playlist::maybe_sequence_video () { @@ -83,16 +82,17 @@ Playlist::maybe_sequence_video () _sequencing_video = true; ContentList cl = _content; - sort (cl.begin(), cl.end(), ContentSorter ()); - Time last = 0; - for (ContentList::iterator i = cl.begin(); i != cl.end(); ++i) { + Time next = 0; + for (ContentList::iterator i = _content.begin(); i != _content.end(); ++i) { if (!dynamic_pointer_cast (*i)) { continue; } - (*i)->set_start (last); - last = (*i)->end (); + (*i)->set_position (next); + next = (*i)->end() + 1; } + + /* This won't change order, so it does not need a sort */ _sequencing_video = false; } @@ -121,6 +121,8 @@ Playlist::set_from_xml (shared_ptr film, shared_ptr c) { _content.push_back (c); + sort (_content.begin(), _content.end(), ContentSorter ()); reconnect (); Changed (); } @@ -153,6 +156,8 @@ Playlist::remove (shared_ptr c) _content.erase (i); Changed (); } + + /* This won't change order, so it does not need a sort */ } void @@ -169,6 +174,8 @@ Playlist::remove (ContentList c) } } + /* This won't change order, so it does not need a sort */ + Changed (); } @@ -253,7 +260,7 @@ Playlist::length () const { Time len = 0; for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) { - len = max (len, (*i)->end ()); + len = max (len, (*i)->end() + 1); } return len; @@ -295,7 +302,7 @@ Playlist::set_sequence_video (bool s) bool ContentSorter::operator() (shared_ptr a, shared_ptr b) { - return a->start() < b->start(); + return a->position() < b->position(); } /** @return content in an undefined order */ @@ -310,8 +317,8 @@ Playlist::repeat (ContentList c, int n) { pair range (TIME_MAX, 0); for (ContentList::iterator i = c.begin(); i != c.end(); ++i) { - range.first = min (range.first, (*i)->start ()); - range.second = max (range.second, (*i)->start ()); + range.first = min (range.first, (*i)->position ()); + range.second = max (range.second, (*i)->position ()); range.first = min (range.first, (*i)->end ()); range.second = max (range.second, (*i)->end ()); } @@ -320,12 +327,78 @@ Playlist::repeat (ContentList c, int n) for (int i = 0; i < n; ++i) { for (ContentList::iterator i = c.begin(); i != c.end(); ++i) { shared_ptr copy = (*i)->clone (); - copy->set_start (pos + copy->start() - range.first); + copy->set_position (pos + copy->position() - range.first); _content.push_back (copy); } pos += range.second - range.first; } + sort (_content.begin(), _content.end(), ContentSorter ()); + reconnect (); Changed (); } + +void +Playlist::move_earlier (shared_ptr c) +{ + sort (_content.begin(), _content.end(), ContentSorter ()); + + ContentList::iterator previous = _content.end (); + ContentList::iterator i = _content.begin(); + while (i != _content.end() && *i != c) { + previous = i; + ++i; + } + + assert (i != _content.end ()); + if (previous == _content.end ()) { + return; + } + + Time const p = (*previous)->position (); + (*previous)->set_position (p + c->length_after_trim ()); + c->set_position (p); + sort (_content.begin(), _content.end(), ContentSorter ()); + + Changed (); +} + +void +Playlist::move_later (shared_ptr c) +{ + sort (_content.begin(), _content.end(), ContentSorter ()); + + ContentList::iterator i = _content.begin(); + while (i != _content.end() && *i != c) { + ++i; + } + + assert (i != _content.end ()); + + ContentList::iterator next = i; + ++next; + + if (next == _content.end ()) { + return; + } + + Time const p = (*next)->position (); + (*next)->set_position (c->position ()); + c->set_position (p + c->length_after_trim ()); + sort (_content.begin(), _content.end(), ContentSorter ()); + + Changed (); +} + +bool +Playlist::content_paths_valid () const +{ + for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) { + if (!(*i)->path_valid ()) { + return false; + } + } + + return true; +}