From 59953282b9f9da1164f39181347a01672c4f674c Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 6 Jun 2022 21:00:50 +0200 Subject: [PATCH] Make jump-to-first-subtitle also work with DCP subs. --- src/lib/dcp_subtitle_decoder.cc | 24 +++++++++++++++------- src/lib/dcp_subtitle_decoder.h | 2 ++ src/wx/content_panel.cc | 35 +++++++++++++++++++++------------ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/lib/dcp_subtitle_decoder.cc b/src/lib/dcp_subtitle_decoder.cc index 169a41751..d5cbabf1b 100644 --- a/src/lib/dcp_subtitle_decoder.cc +++ b/src/lib/dcp_subtitle_decoder.cc @@ -19,22 +19,21 @@ */ -#include "dcp_subtitle_decoder.h" #include "dcp_subtitle_content.h" +#include "dcp_subtitle_decoder.h" #include "font.h" #include "text_content.h" #include #include -#include -using std::cout; +using std::dynamic_pointer_cast; using std::list; +using std::make_shared; +using std::shared_ptr; using std::string; using std::vector; -using std::shared_ptr; -using std::dynamic_pointer_cast; -using std::make_shared; +using boost::optional; using namespace dcpomatic; @@ -42,7 +41,7 @@ DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr film, shared_ptr< : Decoder (film) { /* Load the XML or MXF file */ - shared_ptr const c = load (content->path(0)); + auto const c = load (content->path(0)); c->fix_empty_font_ids (); _subtitles = c->subtitles (); _next = _subtitles.begin (); @@ -162,3 +161,14 @@ DCPSubtitleDecoder::fonts () const return _fonts; } + +/** @return time of first subtitle, if there is one */ +optional +DCPSubtitleDecoder::first () const +{ + if (_subtitles.empty()) { + return {}; + } + + return ContentTime::from_seconds(_subtitles[0]->in().as_seconds()); +} diff --git a/src/lib/dcp_subtitle_decoder.h b/src/lib/dcp_subtitle_decoder.h index 4a54aaf2e..d1237b276 100644 --- a/src/lib/dcp_subtitle_decoder.h +++ b/src/lib/dcp_subtitle_decoder.h @@ -37,6 +37,8 @@ public: std::vector fonts () const override; + boost::optional first () const; + private: dcpomatic::ContentTimePeriod content_time_period (std::shared_ptr s) const; diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index 8f0994919..69dd72426 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -36,6 +36,8 @@ #include "lib/content_factory.h" #include "lib/cross.h" #include "lib/dcp_content.h" +#include "lib/dcp_subtitle_content.h" +#include "lib/dcp_subtitle_decoder.h" #include "lib/dcpomatic_log.h" #include "lib/ffmpeg_content.h" #include "lib/image_content.h" @@ -300,20 +302,27 @@ ContentPanel::check_selection () } optional go_to; - for (auto i: selected()) { - DCPTime p; - p = i->position(); - if (dynamic_pointer_cast(i) && i->paths_valid()) { - /* Rather special case; if we select a text subtitle file jump to its - first subtitle. - */ - StringTextFile ts (dynamic_pointer_cast(i)); - if (ts.first()) { - p += DCPTime(ts.first().get(), _film->active_frame_rate_change(i->position())); + for (auto content: selected()) { + if (content->paths_valid()) { + auto position = content->position(); + if (auto text_content = dynamic_pointer_cast(content)) { + /* Rather special case; if we select a text subtitle file jump to its + first subtitle. + */ + StringTextFile ts(text_content); + if (auto first = ts.first()) { + position += DCPTime(first.get(), _film->active_frame_rate_change(content->position())); + } + } else if (auto dcp_content = dynamic_pointer_cast(content)) { + /* Do the same for DCP subtitles */ + DCPSubtitleDecoder ts(_film, dcp_content); + if (auto first = ts.first()) { + position += DCPTime(first.get(), _film->active_frame_rate_change(content->position())); + } + } + if (!go_to || position < go_to.get()) { + go_to = position; } - } - if (!go_to || p < go_to.get()) { - go_to = p; } } -- 2.30.2