X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fsubrip_decoder.cc;h=e2bdc347b93b202183d483f6a606dfc665324a13;hb=d2137ac5db409e686b4d9b3fa567935a5e416d41;hp=cdc8ccbfe4613f9a745966121101be82fb640a1c;hpb=cfdd68eb5fb0ef8423e860103ad4e5510994f1da;p=dcpomatic.git diff --git a/src/lib/subrip_decoder.cc b/src/lib/subrip_decoder.cc index cdc8ccbfe..e2bdc347b 100644 --- a/src/lib/subrip_decoder.cc +++ b/src/lib/subrip_decoder.cc @@ -19,12 +19,15 @@ #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) { @@ -37,7 +40,7 @@ SubRipDecoder::seek (ContentTime time, bool accurate) _next = 0; list::const_iterator i = _subtitles[_next].pieces.begin(); - while (i != _subtitles[_next].pieces.end() && _subtitles[_next].from < time) { + while (i != _subtitles[_next].pieces.end() && _subtitles[_next].period.from < time) { ++i; } @@ -58,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, @@ -72,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; +}