Tidy up HMSF handling in a few places.
[dcpomatic.git] / src / lib / reel_writer.cc
index 4888a1567d5150b145c235c90dd6024c6094410c..294c0b7b64c85ecc214e1f0e8974c738d2134c2d 100644 (file)
@@ -691,10 +691,9 @@ ReelWriter::create_reel_markers (shared_ptr<dcp::Reel> reel) const
        if (!reel_markers.empty ()) {
                auto ma = make_shared<dcp::ReelMarkersAsset>(dcp::Fraction(film()->video_frame_rate(), 1), reel->duration(), 0);
                for (auto const& i: reel_markers) {
-                       int h, m, s, f;
                        DCPTime relative = i.second - _period.from;
-                       relative.split (film()->video_frame_rate(), h, m, s, f);
-                       ma->set (i.first, dcp::Time(h, m, s, f, film()->video_frame_rate()));
+                       auto hmsf = relative.split (film()->video_frame_rate());
+                       ma->set (i.first, dcp::Time(hmsf.h, hmsf.m, hmsf.s, hmsf.f, film()->video_frame_rate()));
                }
                reel->add (ma);
        }
@@ -790,7 +789,7 @@ ReelWriter::empty_text_asset (TextType type, optional<DCPTextTrack> track) const
                s->set_reel_number (raw_convert<string> (_reel_index + 1));
                asset = s;
        } else {
-               shared_ptr<dcp::SMPTESubtitleAsset> s (new dcp::SMPTESubtitleAsset ());
+               auto s = make_shared<dcp::SMPTESubtitleAsset>();
                s->set_content_title_text (film()->name());
                s->set_metadata (mxf_metadata());
                if (type == TextType::OPEN_SUBTITLE && !lang.empty()) {
@@ -805,6 +804,29 @@ ReelWriter::empty_text_asset (TextType type, optional<DCPTextTrack> track) const
                if (film()->encrypted()) {
                        s->set_key (film()->key());
                }
+               s->add (
+                       std::make_shared<dcp::SubtitleString>(
+                               optional<std::string>(),
+                               false,
+                               false,
+                               false,
+                               dcp::Colour(),
+                               42,
+                               1.0,
+                               dcp::Time(0, 0, 0, 0, 24),
+                               dcp::Time(0, 0, 1, 0, 24),
+                               0.5,
+                               dcp::HAlign::CENTER,
+                               0.5,
+                               dcp::VAlign::CENTER,
+                               dcp::Direction::LTR,
+                               "",
+                               dcp::Effect::NONE,
+                               dcp::Colour(),
+                               dcp::Time(),
+                               dcp::Time()
+                               )
+                      );
                asset = s;
        }
 
@@ -845,19 +867,21 @@ ReelWriter::write (PlayerText subs, TextType type, optional<DCPTextTrack> track,
                DCPOMATIC_ASSERT (false);
        }
 
+       /* timecode rate for subtitles we emit; we might as well stick to ms accuracy here, I think */
+       auto const tcr = 1000;
+
        for (auto i: subs.string) {
-               /* XXX: couldn't / shouldn't we use period here rather than getting time from the subtitle? */
-               i.set_in  (i.in()  - dcp::Time (_period.from.seconds(), i.in().tcr));
-               i.set_out (i.out() - dcp::Time (_period.from.seconds(), i.out().tcr));
-               asset->add (shared_ptr<dcp::Subtitle>(new dcp::SubtitleString(i)));
+               i.set_in  (dcp::Time(period.from.seconds() - _period.from.seconds(), tcr));
+               i.set_out (dcp::Time(period.to.seconds() - _period.from.seconds(), tcr));
+               asset->add (make_shared<dcp::SubtitleString>(i));
        }
 
        for (auto i: subs.bitmap) {
                asset->add (
                        make_shared<dcp::SubtitleImage>(
                                i.image->as_png(),
-                               dcp::Time(period.from.seconds() - _period.from.seconds(), film()->video_frame_rate()),
-                               dcp::Time(period.to.seconds() - _period.from.seconds(), film()->video_frame_rate()),
+                               dcp::Time(period.from.seconds() - _period.from.seconds(), tcr),
+                               dcp::Time(period.to.seconds() - _period.from.seconds(), tcr),
                                i.rectangle.x, dcp::HAlign::LEFT, i.rectangle.y, dcp::VAlign::TOP,
                                dcp::Time(), dcp::Time()
                                )