X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fsubrip_decoder.cc;h=e2bdc347b93b202183d483f6a606dfc665324a13;hb=4743bb988b2d60e235da7027dddb90032812e335;hp=47b6ea04410cdc3d477ded4257a331a347789048;hpb=2e504b33eb9f38cac629ad31b7c107fb0cf5efda;p=dcpomatic.git diff --git a/src/lib/subrip_decoder.cc b/src/lib/subrip_decoder.cc index 47b6ea044..e2bdc347b 100644 --- a/src/lib/subrip_decoder.cc +++ b/src/lib/subrip_decoder.cc @@ -19,17 +19,33 @@ #include #include "subrip_decoder.h" +#include "subrip_content.h" using std::list; +using std::vector; using boost::shared_ptr; SubRipDecoder::SubRipDecoder (shared_ptr content) - : SubRip (content) + : SubtitleDecoder (content) + , SubRip (content) , _next (0) { } +void +SubRipDecoder::seek (ContentTime time, bool accurate) +{ + SubtitleDecoder::seek (time, accurate); + + _next = 0; + list::const_iterator i = _subtitles[_next].pieces.begin(); + while (i != _subtitles[_next].pieces.end() && _subtitles[_next].period.from < time) { + ++i; + } + +} + bool SubRipDecoder::pass () { @@ -45,8 +61,8 @@ SubRipDecoder::pass () i->italic, dcp::Color (255, 255, 255), 72, - dcp::Time (rint (_subtitles[_next].from.seconds() * 250)), - dcp::Time (rint (_subtitles[_next].to.seconds() * 250)), + dcp::Time (rint (_subtitles[_next].period.from.seconds() * 250)), + dcp::Time (rint (_subtitles[_next].period.to.seconds() * 250)), 0.9, dcp::BOTTOM, i->text, @@ -59,6 +75,22 @@ SubRipDecoder::pass () } text_subtitle (out); - _next++; + ++_next; return false; } + +list +SubRipDecoder::subtitles_during (ContentTimePeriod p, bool starting) const +{ + /* XXX: inefficient */ + + list d; + + for (vector::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { + if ((starting && p.contains (i->period.from)) || (!starting && p.overlaps (i->period))) { + d.push_back (i->period); + } + } + + return d; +}