pot/merge.
[dcpomatic.git] / src / lib / playlist.cc
index b5faec5679ed97eb435e59812ca9c8736261e2f5..82a4666cdd162185dd8a19530eaf363797f45182 100644 (file)
@@ -51,8 +51,8 @@ using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
 
 Playlist::Playlist ()
-       : _sequence_video (true)
-       , _sequencing_video (false)
+       : _sequence (true)
+       , _sequencing (false)
 {
 
 }
@@ -72,7 +72,7 @@ Playlist::content_changed (weak_ptr<Content> content, int property, bool frequen
                   - any other position changes will be timeline drags which should not result in content
                   being sequenced.
                */
-               maybe_sequence_video ();
+               maybe_sequence ();
        }
 
        if (
@@ -92,13 +92,20 @@ Playlist::content_changed (weak_ptr<Content> content, int property, bool frequen
 }
 
 void
-Playlist::maybe_sequence_video ()
+Playlist::maybe_sequence ()
 {
-       if (!_sequence_video || _sequencing_video) {
+       if (!_sequence || _sequencing) {
                return;
        }
 
-       _sequencing_video = true;
+       _sequencing = true;
+
+       /* Keep track of the content that we've set the position of so that we don't
+          do it twice.
+       */
+       ContentList placed;
+
+       /* Video */
 
        DCPTime next_left;
        DCPTime next_right;
@@ -115,11 +122,27 @@ Playlist::maybe_sequence_video ()
                        vc->set_position (next_left);
                        next_left = vc->end();
                }
+
+               placed.push_back (vc);
        }
 
+       /* Subtitles */
+
+       DCPTime next;
+       BOOST_FOREACH (shared_ptr<Content> i, _content) {
+               shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (i);
+               if (!sc || !sc->has_subtitles() || find (placed.begin(), placed.end(), i) != placed.end()) {
+                       continue;
+               }
+
+               sc->set_position (next);
+               next = sc->end();
+       }
+
+
        /* This won't change order, so it does not need a sort */
 
-       _sequencing_video = false;
+       _sequencing = false;
 }
 
 string
@@ -333,6 +356,19 @@ Playlist::video_end () const
        return end;
 }
 
+DCPTime
+Playlist::subtitle_end () const
+{
+       DCPTime end;
+       BOOST_FOREACH (shared_ptr<Content> i, _content) {
+               if (dynamic_pointer_cast<const SubtitleContent> (i)) {
+                       end = max (end, i->end ());
+               }
+       }
+
+       return end;
+}
+
 FrameRateChange
 Playlist::active_frame_rate_change (DCPTime t, int dcp_video_frame_rate) const
 {
@@ -354,9 +390,9 @@ Playlist::active_frame_rate_change (DCPTime t, int dcp_video_frame_rate) const
 }
 
 void
-Playlist::set_sequence_video (bool s)
+Playlist::set_sequence (bool s)
 {
-       _sequence_video = s;
+       _sequence = s;
 }
 
 bool