From e668388d1a552c845dbe9ae3cdcdfd979f2da582 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 11 Jan 2021 21:20:47 +0100 Subject: Change subtitle SubtitleAsset API to return const Subtitle pointers; add subtitles_in_reel(). --- src/subtitle_asset.cc | 43 +++++++++++++++++++++++++++++++++++++++---- src/subtitle_asset.h | 10 ++++++---- 2 files changed, 45 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 59aff6be..fc9b972a 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2019 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of libdcp. @@ -41,6 +41,7 @@ #include "subtitle_image.h" #include "dcp_assert.h" #include "load_font_node.h" +#include "reel_asset.h" #include #include #include @@ -56,6 +57,7 @@ using std::cerr; using std::map; using std::shared_ptr; using std::vector; +using std::make_shared; using boost::shared_array; using boost::optional; using boost::lexical_cast; @@ -407,11 +409,23 @@ SubtitleAsset::maybe_add_subtitle (string text, vector const & parse } } -vector> + +vector> +SubtitleAsset::subtitles () const +{ + vector> s; + for (auto i: _subtitles) { + s.push_back (i); + } + return s; +} + + +vector> SubtitleAsset::subtitles_during (Time from, Time to, bool starting) const { - vector > s; - BOOST_FOREACH (shared_ptr i, _subtitles) { + vector> s; + for (auto i: _subtitles) { if ((starting && from <= i->in() && i->in() < to) || (!starting && i->out() >= from && i->in() <= to)) { s.push_back (i); } @@ -420,6 +434,27 @@ SubtitleAsset::subtitles_during (Time from, Time to, bool starting) const return s; } + +/* XXX: this needs a test */ +vector> +SubtitleAsset::subtitles_in_reel (shared_ptr asset) const +{ + auto frame_rate = asset->edit_rate().as_float(); + auto start = dcp::Time(asset->entry_point().get_value_or(0), frame_rate, time_code_rate()); + auto during = subtitles_during (start, start + dcp::Time(asset->intrinsic_duration(), frame_rate, time_code_rate()), false); + + vector> corrected; + for (auto i: during) { + auto c = make_shared(*i); + c->set_in (c->in() - start); + c->set_out (c->out() - start); + corrected.push_back (c); + } + + return corrected; +} + + void SubtitleAsset::add (shared_ptr s) { diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 60ddc357..02976f7d 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -62,6 +62,7 @@ class FontNode; class TextNode; class SubtitleNode; class LoadFontNode; +class ReelAsset; namespace order { class Part; @@ -88,10 +89,9 @@ public: NoteHandler note ) const; - std::vector> subtitles_during (Time from, Time to, bool starting) const; - std::vector> const & subtitles () const { - return _subtitles; - } + std::vector> subtitles_during (Time from, Time to, bool starting) const; + std::vector> subtitles_in_reel(std::shared_ptr asset) const; + std::vector> subtitles () const; virtual void add (std::shared_ptr); virtual void add_font (std::string id, dcp::ArrayData data) = 0; @@ -107,6 +107,8 @@ public: virtual std::vector> load_font_nodes () const = 0; + virtual int time_code_rate () const = 0; + std::string raw_xml () const { return _raw_xml; } -- cgit v1.2.3