Fix incorrect reels when the first content is not at time 0.
[dcpomatic.git] / src / lib / film.cc
index 988b7e2fe639f6ef40b6f91d09e23a283a753fce..d19dcc73c3d5b8377e2258eeffeb93c361cf7918 100644 (file)
@@ -1276,6 +1276,9 @@ Film::playlist_content_change (ChangeType type, weak_ptr<Content> c, int p, bool
 
        if (type == CHANGE_TYPE_DONE) {
                emit (boost::bind (boost::ref (ContentChange), type, c, p, frequent));
+               if (!frequent) {
+                       check_settings_consistency ();
+               }
        } else {
                ContentChange (type, c, p, frequent);
        }
@@ -1288,29 +1291,37 @@ Film::playlist_change (ChangeType type)
        signal_change (type, NAME);
 
        if (type == CHANGE_TYPE_DONE) {
-               /* Check that this change hasn't made our settings inconsistent */
-               bool change_made = false;
-               BOOST_FOREACH (shared_ptr<Content> i, content()) {
-                       shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
-                       if (!d) {
-                               continue;
-                       }
+               check_settings_consistency ();
+       }
+}
 
-                       string why_not;
-                       if (d->reference_video() && !d->can_reference_video(shared_from_this(), why_not)) {
-                               d->set_reference_video(false);
-                               change_made = true;
-                       }
-                       if (d->reference_audio() && !d->can_reference_audio(shared_from_this(), why_not)) {
-                               d->set_reference_audio(false);
-                               change_made = true;
-                       }
+/** Check for (and if necessary fix) impossible settings combinations, like
+ *  video set to being referenced when it can't be.
+ */
+void
+Film::check_settings_consistency ()
+{
+       bool change_made = false;
+       BOOST_FOREACH (shared_ptr<Content> i, content()) {
+               shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
+               if (!d) {
+                       continue;
                }
 
-               if (change_made) {
-                       Message (_("DCP-o-matic had to change your settings for referring to DCPs as OV.  Please review those settings to make sure they are what you want."));
+               string why_not;
+               if (d->reference_video() && !d->can_reference_video(shared_from_this(), why_not)) {
+                       d->set_reference_video(false);
+                       change_made = true;
+               }
+               if (d->reference_audio() && !d->can_reference_audio(shared_from_this(), why_not)) {
+                       d->set_reference_audio(false);
+                       change_made = true;
                }
        }
+
+       if (change_made) {
+               Message (_("DCP-o-matic had to change your settings for referring to DCPs as OV.  Please review those settings to make sure they are what you want."));
+       }
 }
 
 void
@@ -1595,24 +1606,24 @@ Film::reels () const
                break;
        case REELTYPE_BY_VIDEO_CONTENT:
        {
-               optional<DCPTime> last_split;
+               DCPTime last_split;
                shared_ptr<Content> last_video;
                BOOST_FOREACH (shared_ptr<Content> c, content ()) {
                        if (c->video) {
                                BOOST_FOREACH (DCPTime t, c->reel_split_points(shared_from_this())) {
-                                       if (last_split) {
-                                               p.push_back (DCPTimePeriod (last_split.get(), t));
+                                       if (last_split != t) {
+                                               p.push_back (DCPTimePeriod(last_split, t));
+                                               last_split = t;
                                        }
-                                       last_split = t;
                                }
                                last_video = c;
                        }
                }
 
                DCPTime video_end = last_video ? last_video->end(shared_from_this()) : DCPTime(0);
-               if (last_split) {
+               if (last_split != video_end) {
                        /* Definitely go from the last split to the end of the video content */
-                       p.push_back (DCPTimePeriod (last_split.get(), video_end));
+                       p.push_back (DCPTimePeriod(last_split, video_end));
                }
 
                if (video_end < len) {