X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplaylist.cc;h=c46e65d8bfface99d07ef8d5dc00e2475c374f31;hb=2e504b33eb9f38cac629ad31b7c107fb0cf5efda;hp=e9ea3e3c7143179afbb82e3ee4dfb331a75b7dcf;hpb=9db14938dda095b0693148386ee1c2e7cc882481;p=dcpomatic.git diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index e9ea3e3c7..c46e65d8b 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -26,8 +26,7 @@ #include "video_content.h" #include "ffmpeg_decoder.h" #include "ffmpeg_content.h" -#include "still_image_decoder.h" -#include "still_image_content.h" +#include "image_decoder.h" #include "content_factory.h" #include "job.h" #include "config.h" @@ -72,7 +71,6 @@ Playlist::content_changed (weak_ptr content, int property, bool frequen ContentChanged (content, property, frequent); } - void Playlist::maybe_sequence_video () { @@ -83,16 +81,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) { + DCPTime next; + 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() + DCPTime::delta (); } + + /* This won't change order, so it does not need a sort */ _sequencing_video = false; } @@ -114,13 +113,15 @@ Playlist::video_identifier () const /** @param node node */ void -Playlist::set_from_xml (shared_ptr film, shared_ptr node) +Playlist::set_from_xml (shared_ptr film, shared_ptr node, int version, list& notes) { - list > c = node->node_children ("Content"); - for (list >::iterator i = c.begin(); i != c.end(); ++i) { - _content.push_back (content_factory (film, *i)); + list c = node->node_children ("Content"); + for (list::iterator i = c.begin(); i != c.end(); ++i) { + _content.push_back (content_factory (film, *i, version, notes)); } + sort (_content.begin(), _content.end(), ContentSorter ()); + reconnect (); } @@ -137,6 +138,7 @@ void Playlist::add (shared_ptr c) { _content.push_back (c); + sort (_content.begin(), _content.end(), ContentSorter ()); reconnect (); Changed (); } @@ -153,6 +155,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 +173,8 @@ Playlist::remove (ContentList c) } } + /* This won't change order, so it does not need a sort */ + Changed (); } @@ -248,12 +254,12 @@ Playlist::best_dcp_frame_rate () const return best->dcp; } -Time +DCPTime Playlist::length () const { - Time len = 0; + DCPTime len; for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) { - len = max (len, (*i)->end ()); + len = max (len, (*i)->end() + DCPTime::delta ()); } return len; @@ -273,10 +279,10 @@ Playlist::reconnect () } } -Time +DCPTime Playlist::video_end () const { - Time end = 0; + DCPTime end; for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) { if (dynamic_pointer_cast (*i)) { end = max (end, (*i)->end ()); @@ -286,6 +292,23 @@ Playlist::video_end () const return end; } +FrameRateChange +Playlist::active_frame_rate_change (DCPTime t, int dcp_video_frame_rate) const +{ + for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) { + shared_ptr vc = dynamic_pointer_cast (*i); + if (!vc) { + break; + } + + if (vc->position() >= t && t < vc->end()) { + return FrameRateChange (vc->video_frame_rate(), dcp_video_frame_rate); + } + } + + return FrameRateChange (dcp_video_frame_rate, dcp_video_frame_rate); +} + void Playlist::set_sequence_video (bool s) { @@ -295,7 +318,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 */ @@ -308,24 +331,78 @@ Playlist::content () const void Playlist::repeat (ContentList c, int n) { - pair range (TIME_MAX, 0); + pair range (DCPTime::max (), DCPTime ()); 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 ()); } - Time pos = range.second; + DCPTime pos = range.second; 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; + } + + DCPTime 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; + } + + DCPTime const p = (*next)->position (); + (*next)->set_position (c->position ()); + c->set_position (p + c->length_after_trim ()); + sort (_content.begin(), _content.end(), ContentSorter ()); + + Changed (); +}