Remove duplicate save of SequenceVideo setting.
[dcpomatic.git] / src / lib / playlist.cc
index 172b6fbb96f6dbb82cdec0f0b912ae311e7747b4..e9ea3e3c7143179afbb82e3ee4dfb331a75b7dcf 100644 (file)
@@ -26,8 +26,8 @@
 #include "video_content.h"
 #include "ffmpeg_decoder.h"
 #include "ffmpeg_content.h"
-#include "imagemagick_decoder.h"
-#include "imagemagick_content.h"
+#include "still_image_decoder.h"
+#include "still_image_content.h"
 #include "content_factory.h"
 #include "job.h"
 #include "config.h"
@@ -42,6 +42,7 @@ using std::min;
 using std::max;
 using std::string;
 using std::stringstream;
+using std::pair;
 using boost::optional;
 using boost::shared_ptr;
 using boost::weak_ptr;
@@ -49,8 +50,7 @@ using boost::dynamic_pointer_cast;
 using boost::lexical_cast;
 
 Playlist::Playlist ()
-       : _loop (1)
-       , _sequence_video (true)
+       : _sequence_video (true)
        , _sequencing_video (false)
 {
 
@@ -109,8 +109,6 @@ Playlist::video_identifier () const
                }
        }
 
-       t += lexical_cast<string> (_loop);
-
        return md5_digest (t.c_str(), t.length());
 }
 
@@ -124,8 +122,6 @@ Playlist::set_from_xml (shared_ptr<const Film> film, shared_ptr<const cxml::Node
        }
 
        reconnect ();
-       _loop = node->number_child<int> ("Loop");
-       _sequence_video = node->bool_child ("SequenceVideo");
 }
 
 /** @param node <Playlist> node */
@@ -135,9 +131,6 @@ Playlist::as_xml (xmlpp::Node* node)
        for (ContentList::iterator i = _content.begin(); i != _content.end(); ++i) {
                (*i)->as_xml (node->add_child ("Content"));
        }
-
-       node->add_child("Loop")->add_child_text(lexical_cast<string> (_loop));
-       node->add_child("SequenceVideo")->add_child_text(_sequence_video ? "1" : "0");
 }
 
 void
@@ -163,9 +156,19 @@ Playlist::remove (shared_ptr<Content> c)
 }
 
 void
-Playlist::set_loop (int l)
+Playlist::remove (ContentList c)
 {
-       _loop = l;
+       for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
+               ContentList::iterator j = _content.begin ();
+               while (j != _content.end() && *j != *i) {
+                       ++j;
+               }
+       
+               if (j != _content.end ()) {
+                       _content.erase (j);
+               }
+       }
+
        Changed ();
 }
 
@@ -246,7 +249,7 @@ Playlist::best_dcp_frame_rate () const
 }
 
 Time
-Playlist::length_without_loop () const
+Playlist::length () const
 {
        Time len = 0;
        for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
@@ -256,12 +259,6 @@ Playlist::length_without_loop () const
        return len;
 }
 
-Time
-Playlist::length_with_loop () const
-{
-       return length_without_loop() * _loop;
-}
-
 void
 Playlist::reconnect ()
 {
@@ -301,29 +298,34 @@ ContentSorter::operator() (shared_ptr<Content> a, shared_ptr<Content> b)
        return a->start() < b->start();
 }
 
-/** @return content in an undefined order, not taking looping into account */
-Playlist::ContentList
-Playlist::content_without_loop () const
+/** @return content in an undefined order */
+ContentList
+Playlist::content () const
 {
        return _content;
 }
 
-/** @return content in an undefined order, taking looping into account */
-Playlist::ContentList
-Playlist::content_with_loop () const
+void
+Playlist::repeat (ContentList c, int n)
 {
-       ContentList looped = _content;
-       Time const length = length_without_loop ();
+       pair<Time, Time> 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)->end ());
+               range.second = max (range.second, (*i)->end ());
+       }
 
-       Time offset = length;
-       for (int i = 1; i < _loop; ++i) {
-               for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+       Time pos = range.second;
+       for (int i = 0; i < n; ++i) {
+               for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
                        shared_ptr<Content> copy = (*i)->clone ();
-                       copy->set_start (copy->start() + offset);
-                       looped.push_back (copy);
+                       copy->set_start (pos + copy->start() - range.first);
+                       _content.push_back (copy);
                }
-               offset += length;
+               pos += range.second - range.first;
        }
-       
-       return looped;
+
+       reconnect ();
+       Changed ();
 }