X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Factive_text.cc;h=2a5c4d836468a7a8fb3e359e81085c31d807ad55;hb=cb330f076f72000d028b11e88702addb0a2ab480;hp=2988c04a397e66aebb73d8198445e1986f9513f1;hpb=3a7b6acdb993864f319a6ceb3bc4c3fb7d4aaefd;p=dcpomatic.git diff --git a/src/lib/active_text.cc b/src/lib/active_text.cc index 2988c04a3..2a5c4d836 100644 --- a/src/lib/active_text.cc +++ b/src/lib/active_text.cc @@ -18,17 +18,36 @@ */ + #include "active_text.h" #include "text_content.h" -#include -#include + using std::list; using std::pair; using std::make_pair; -using boost::weak_ptr; -using boost::shared_ptr; +using std::weak_ptr; +using std::shared_ptr; using boost::optional; +using namespace dcpomatic; + + +ActiveText::ActiveText(ActiveText&& other) + : _data(std::move(other._data)) +{ + +} + + +ActiveText& +ActiveText::operator=(ActiveText&& other) +{ + if (this != &other) { + _data = std::move(other._data); + } + return *this; +} + /** Get the open captions that should be burnt into a given period. * @param period Period of interest. @@ -41,9 +60,9 @@ ActiveText::get_burnt (DCPTimePeriod period, bool always_burn_captions) const list ps; - for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) { + for (auto const& i: _data) { - shared_ptr caption = i->first.lock (); + auto caption = i.first.lock (); if (!caption) { continue; } @@ -53,9 +72,9 @@ ActiveText::get_burnt (DCPTimePeriod period, bool always_burn_captions) const continue; } - BOOST_FOREACH (Period j, i->second) { + for (auto j: i.second) { DCPTimePeriod test (j.from, j.to.get_value_or(DCPTime::max())); - optional overlap = period.overlap (test); + auto overlap = period.overlap (test); if (overlap && overlap->duration() > DCPTime(period.duration().get() / 2)) { ps.push_back (j.subs); } @@ -65,6 +84,7 @@ ActiveText::get_burnt (DCPTimePeriod period, bool always_burn_captions) const return ps; } + /** Remove subtitles that finish before a given time from our list. * @param time Time to remove before. */ @@ -74,20 +94,21 @@ ActiveText::clear_before (DCPTime time) boost::mutex::scoped_lock lm (_mutex); Map updated; - for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) { + for (auto const& i: _data) { list as; - BOOST_FOREACH (Period j, i->second) { + for (auto j: i.second) { if (!j.to || j.to.get() >= time) { as.push_back (j); } } if (!as.empty ()) { - updated[i->first] = as; + updated[i.first] = as; } } _data = updated; } + /** Add a new subtitle with a from time. * @param content Content that the subtitle is from. * @param ps Subtitles. @@ -104,6 +125,7 @@ ActiveText::add_from (weak_ptr content, PlayerText ps, DCPTim _data[content].push_back (Period (ps, from)); } + /** Add the to time for the last subtitle added from a piece of content. * @param content Content that the subtitle is from. * @param to To time for the last subtitle submitted to add_from for this content. @@ -118,13 +140,14 @@ ActiveText::add_to (weak_ptr content, DCPTime to) _data[content].back().to = to; - BOOST_FOREACH (StringText& i, _data[content].back().subs.string) { + for (auto& i: _data[content].back().subs.string) { i.set_out (dcp::Time(to.seconds(), 1000)); } return make_pair (_data[content].back().subs, _data[content].back().from); } + /** @param content Some content. * @return true if we have any active subtitles from this content. */ @@ -133,7 +156,7 @@ ActiveText::have (weak_ptr content) const { boost::mutex::scoped_lock lm (_mutex); - Map::const_iterator i = _data.find(content); + auto i = _data.find(content); if (i == _data.end()) { return false; } @@ -141,6 +164,7 @@ ActiveText::have (weak_ptr content) const return !i->second.empty(); } + void ActiveText::clear () {