Various fixes to make audio analysis sort-of work.
[dcpomatic.git] / src / lib / playlist.cc
index 7ab320558b01324e78cfe2d821f0d6379bbc1eb1..9cc1789d135d5c38a66e416b4c90888421d7142e 100644 (file)
@@ -1,5 +1,3 @@
-/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
-
 /*
     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
 
@@ -51,6 +49,8 @@ using boost::lexical_cast;
 
 Playlist::Playlist ()
        : _loop (1)
+       , _sequence_video (true)
+       , _sequencing_video (false)
 {
 
 }
@@ -72,30 +72,25 @@ Playlist::~Playlist ()
 void
 Playlist::content_changed (weak_ptr<Content> c, int p)
 {
-       ContentChanged (c, p);
-}
+       if (p == ContentProperty::LENGTH && _sequence_video && !_sequencing_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) {
+                       if (!dynamic_pointer_cast<VideoContent> (*i)) {
+                               continue;
+                       }
 
-string
-Playlist::audio_digest () const
-{
-       string t;
-       
-       for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
-               if (!dynamic_pointer_cast<const AudioContent> (*i)) {
-                       continue;
+                       (*i)->set_start (last);
+                       last = (*i)->end ();
                }
-               
-               t += (*i)->digest ();
 
-               shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
-               if (fc) {
-                       t += lexical_cast<string> (fc->audio_stream()->id);
-               }
+               _sequencing_video = false;
        }
-
-       t += lexical_cast<string> (_loop);
-
-       return md5_digest (t.c_str(), t.length());
+       
+       ContentChanged (c, p);
 }
 
 string
@@ -143,6 +138,7 @@ 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 */
@@ -154,6 +150,7 @@ Playlist::as_xml (xmlpp::Node* node)
        }
 
        node->add_child("Loop")->add_child_text(lexical_cast<string> (_loop));
+       node->add_child("SequenceVideo")->add_child_text(_sequence_video ? "1" : "0");
 }
 
 void
@@ -285,3 +282,27 @@ Playlist::reconnect ()
        }
 }
 
+Time
+Playlist::video_end () const
+{
+       Time end = 0;
+       for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+               if (dynamic_pointer_cast<const VideoContent> (*i)) {
+                       end = max (end, (*i)->end ());
+               }
+       }
+
+       return end;
+}
+
+void
+Playlist::set_sequence_video (bool s)
+{
+       _sequence_video = s;
+}
+
+bool
+ContentSorter::operator() (shared_ptr<Content> a, shared_ptr<Content> b)
+{
+       return a->start() < b->start();
+}