Don't insist on writing optional metadata (#1923).
[dcpomatic.git] / src / lib / writer.cc
index 4386b8e26264dea29a1e4cc41dce74212e915465..839156d34be51534db48b7894373c98e9ce08cef 100644 (file)
@@ -622,13 +622,23 @@ Writer::finish (boost::filesystem::path output_dcp)
 
        cpl->set_full_content_title_text (film()->name());
        cpl->set_full_content_title_text_language (film()->name_language());
-       cpl->set_release_territory (film()->release_territory());
+       if (film()->release_territory()) {
+               cpl->set_release_territory (*film()->release_territory());
+       }
        cpl->set_version_number (film()->version_number());
        cpl->set_status (film()->status());
-       cpl->set_chain (film()->chain());
-       cpl->set_distributor (film()->distributor());
-       cpl->set_facility (film()->facility());
-       cpl->set_luminance (film()->luminance());
+       if (film()->chain()) {
+               cpl->set_chain (*film()->chain());
+       }
+       if (film()->distributor()) {
+               cpl->set_distributor (*film()->distributor());
+       }
+       if (film()->facility()) {
+               cpl->set_facility (*film()->facility());
+       }
+       if (film()->luminance()) {
+               cpl->set_luminance (*film()->luminance());
+       }
 
        auto ac = film()->mapped_audio_channels();
        dcp::MCASoundField field = (
@@ -733,15 +743,14 @@ Writer::write_cover_sheet (boost::filesystem::path output_dcp)
        }
        boost::algorithm::replace_all (text, "$AUDIO", description);
 
-       int h, m, s, fr;
-       film()->length().split(film()->video_frame_rate(), h, m, s, fr);
+       auto const hmsf = film()->length().split(film()->video_frame_rate());
        string length;
-       if (h == 0 && m == 0) {
-               length = String::compose("%1s", s);
-       } else if (h == 0 && m > 0) {
-               length = String::compose("%1m%2s", m, s);
-       } else if (h > 0 && m > 0) {
-               length = String::compose("%1h%2m%3s", h, m, s);
+       if (hmsf.h == 0 && hmsf.m == 0) {
+               length = String::compose("%1s", hmsf.s);
+       } else if (hmsf.h == 0 && hmsf.m > 0) {
+               length = String::compose("%1m%2s", hmsf.m, hmsf.s);
+       } else if (hmsf.h > 0 && hmsf.m > 0) {
+               length = String::compose("%1h%2m%3s", hmsf.h, hmsf.m, hmsf.s);
        }
 
        boost::algorithm::replace_all (text, "$LENGTH", length);
@@ -802,6 +811,11 @@ Writer::write (PlayerText text, TextType type, optional<DCPTextTrack> track, DCP
                write_hanging_text (**reel);
        }
 
+       auto back_off = [this](DCPTimePeriod period) {
+               period.to -= DCPTime::from_frames(2, film()->video_frame_rate());
+               return period;
+       };
+
        if (period.to > (*reel)->period().to) {
                /* This text goes off the end of the reel.  Store parts of it that should go into
                 * other reels.
@@ -809,13 +823,14 @@ Writer::write (PlayerText text, TextType type, optional<DCPTextTrack> track, DCP
                for (auto i = std::next(*reel); i != _reels.end(); ++i) {
                        auto overlap = i->period().overlap(period);
                        if (overlap) {
-                               _hanging_texts.push_back (HangingText{text, type, track, *overlap});
+                               _hanging_texts.push_back (HangingText{text, type, track, back_off(*overlap)});
                        }
                }
                /* Back off from the reel boundary by a couple of frames to avoid tripping checks
                 * for subtitles being too close together.
                 */
-               period.to = (*reel)->period().to - DCPTime::from_frames(2, film()->video_frame_rate());
+               period.to = (*reel)->period().to;
+               period = back_off(period);
        }
 
        (*reel)->write (text, type, track, period);