diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-08-13 02:14:00 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-08-13 02:14:00 +0100 |
| commit | cadec42b9547665ac03a7180af374ebb40df7c78 (patch) | |
| tree | fed45715e96ce2b0046fd956963efb6625407f78 /src | |
| parent | 4c987f7feb504fe4011b52ffeb231e3b25823de1 (diff) | |
Subtitles at method.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dcp_time.cc | 22 | ||||
| -rw-r--r-- | src/dcp_time.h | 1 | ||||
| -rw-r--r-- | src/subtitle_asset.cc | 29 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 4 |
4 files changed, 55 insertions, 1 deletions
diff --git a/src/dcp_time.cc b/src/dcp_time.cc index 2e79e742..5e8bf801 100644 --- a/src/dcp_time.cc +++ b/src/dcp_time.cc @@ -28,6 +28,28 @@ libdcp::operator== (Time const & a, Time const & b) return (a.h == b.h && a.m == b.m && a.s == b.s && a.ms == b.ms); } +bool +libdcp::operator<= (Time const & a, Time const & b) +{ + if (a.h != b.h) { + return a.h <= b.h; + } + + if (a.m != b.m) { + return a.m <= b.m; + } + + if (a.s != b.s) { + return a.s <= b.s; + } + + if (a.ms != b.ms) { + return a.ms <= b.ms; + } + + return true; +} + ostream & libdcp::operator<< (ostream& s, Time const & t) { diff --git a/src/dcp_time.h b/src/dcp_time.h index 4e91dc18..48560596 100644 --- a/src/dcp_time.h +++ b/src/dcp_time.h @@ -40,6 +40,7 @@ public: }; extern bool operator== (Time const & a, Time const & b); +extern bool operator<= (Time const & a, Time const & b); extern std::ostream & operator<< (std::ostream & s, Time const & t); } diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index ca27d6da..22098213 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -19,9 +19,11 @@ #include "subtitle_asset.h" +using namespace std; +using namespace boost; using namespace libdcp; -SubtitleAsset::SubtitleAsset (std::string directory, std::string xml) +SubtitleAsset::SubtitleAsset (string directory, string xml) : Asset (directory, xml) , XMLFile (path().string(), "DCSubtitle") { @@ -55,3 +57,28 @@ Text::Text (xmlpp::Node const * node) _text = content (); _v_position = float_attribute ("VPosition"); } + +list<shared_ptr<Text> > +SubtitleAsset::subtitles_at (Time t) const +{ + for (list<shared_ptr<Font> >::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { + list<shared_ptr<Text> > s = (*i)->subtitles_at (t); + if (!s.empty ()) { + return s; + } + } + + return list<shared_ptr<Text> > (); +} + +list<shared_ptr<Text> > +Font::subtitles_at (Time t) const +{ + for (list<shared_ptr<Subtitle> >::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { + if ((*i)->in() <= t && t <= (*i)->out()) { + return (*i)->texts (); + } + } + + return list<shared_ptr<Text> > (); +} diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 02db6815..6d584a0a 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -77,6 +77,8 @@ public: return _subtitles; } + std::list<boost::shared_ptr<Text> > subtitles_at (Time t) const; + private: std::list<boost::shared_ptr<Subtitle> > _subtitles; }; @@ -95,6 +97,8 @@ public: return _language; } + std::list<boost::shared_ptr<Text> > subtitles_at (Time t) const; + std::list<boost::shared_ptr<Font> > const & fonts () const { return _fonts; } |
