Move some functions to kdm_with_metadata
[dcpomatic.git] / src / lib / empty.cc
index 2233b43426e7d859875fae85792c693d5d04f832..c145c231bc02c1cef932282602aa7f8e0b27ce5b 100644 (file)
 */
 
 #include "empty.h"
+#include "film.h"
 #include "playlist.h"
 #include "content.h"
 #include "content_part.h"
 #include "dcp_content.h"
 #include "dcpomatic_time_coalesce.h"
+#include "piece.h"
 #include <boost/foreach.hpp>
 #include <iostream>
 
@@ -32,17 +34,22 @@ using std::list;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using boost::function;
+using namespace dcpomatic;
 
-Empty::Empty (shared_ptr<const Playlist> playlist, function<shared_ptr<ContentPart> (Content *)> part)
+Empty::Empty (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist, function<bool (shared_ptr<const Content>)> part, DCPTime length)
 {
        list<DCPTimePeriod> full;
        BOOST_FOREACH (shared_ptr<Content> i, playlist->content()) {
-               if (part (i.get())) {
-                       full.push_back (DCPTimePeriod (i->position(), i->end()));
+               if (part(i)) {
+                       full.push_back (DCPTimePeriod (i->position(), i->end(film)));
                }
        }
 
-       _periods = subtract (DCPTimePeriod(DCPTime(), playlist->length()), coalesce(full));
+       _periods = subtract (DCPTimePeriod(DCPTime(), length), coalesce(full));
+
+       if (!_periods.empty ()) {
+               _position = _periods.front().from;
+       }
 }
 
 void
@@ -79,11 +86,10 @@ Empty::period_at_position () const
 bool
 Empty::done () const
 {
+       DCPTime latest;
        BOOST_FOREACH (DCPTimePeriod i, _periods) {
-               if (i.contains(_position)) {
-                       return false;
-               }
+               latest = max (latest, i.to);
        }
 
-       return true;
+       return _position >= latest;
 }