- if (_film->interop ()) {
- shared_ptr<dcp::InteropSubtitleAsset> s (new dcp::InteropSubtitleAsset ());
- s->set_movie_title (_film->name ());
- s->set_language (lang);
- s->set_reel_number (raw_convert<string> (_reel_index + 1));
- _subtitle_asset = s;
- } else {
- shared_ptr<dcp::SMPTESubtitleAsset> s (new dcp::SMPTESubtitleAsset ());
- s->set_content_title_text (_film->name ());
- s->set_language (lang);
- s->set_edit_rate (dcp::Fraction (_film->video_frame_rate (), 1));
- s->set_reel_number (_reel_index + 1);
- s->set_time_code_rate (_film->video_frame_rate ());
- s->set_start_time (dcp::Time ());
- if (_film->encrypted ()) {
- s->set_key (_film->key ());
- }
- _subtitle_asset = s;
+ s->set_reel_number (raw_convert<string> (_reel_index + 1));
+ asset = s;
+ } else {
+ auto s = make_shared<dcp::SMPTESubtitleAsset>();
+ s->set_content_title_text (film()->name());
+ s->set_metadata (mxf_metadata());
+ if (type == TextType::OPEN_SUBTITLE && lang.first) {
+ s->set_language (*lang.first);
+ } else if (track && track->language) {
+ s->set_language (dcp::LanguageTag(track->language->to_string()));
+ }
+ s->set_edit_rate (dcp::Fraction (film()->video_frame_rate(), 1));
+ s->set_reel_number (_reel_index + 1);
+ s->set_time_code_rate (film()->video_frame_rate());
+ s->set_start_time (dcp::Time ());
+ if (film()->encrypted()) {
+ s->set_key (film()->key());
+ }
+ if (with_dummy) {
+ 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(),
+ 0
+ )
+ );
+ }
+ asset = s;
+ }
+
+ return asset;
+}
+
+
+void
+ReelWriter::write (PlayerText subs, TextType type, optional<DCPTextTrack> track, DCPTimePeriod period, FontIdMap const& fonts)
+{
+ shared_ptr<dcp::SubtitleAsset> asset;
+
+ switch (type) {
+ case TextType::OPEN_SUBTITLE:
+ asset = _subtitle_asset;
+ break;
+ case TextType::CLOSED_CAPTION:
+ DCPOMATIC_ASSERT (track);
+ asset = _closed_caption_assets[*track];
+ break;
+ default:
+ DCPOMATIC_ASSERT (false);
+ }
+
+ if (!asset) {
+ asset = empty_text_asset (type, track, false);
+ }
+
+ switch (type) {
+ case TextType::OPEN_SUBTITLE:
+ _subtitle_asset = asset;
+ break;
+ case TextType::CLOSED_CAPTION:
+ DCPOMATIC_ASSERT (track);
+ _closed_caption_assets[*track] = asset;
+ break;
+ default:
+ 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) {
+ i.set_in (dcp::Time(period.from.seconds() - _period.from.seconds(), tcr));
+ i.set_out (dcp::Time(period.to.seconds() - _period.from.seconds(), tcr));
+ auto sub = make_shared<dcp::SubtitleString>(i);
+ if (type == TextType::OPEN_SUBTITLE) {
+ sub->set_font(fonts.get(i.font));