X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdcpomatic_time.cc;h=6f8f5efa2d4eb01b8b7249447c271ac79dc33bc4;hb=1d68fe1e3ad1a9aa85fa7fc6071a0b8c64973953;hp=98888646d0a841e26bcb077a426be8ac66e1e8e4;hpb=39bc73fe192f932ed6695eb87b19de446e8b4f55;p=dcpomatic.git diff --git a/src/lib/dcpomatic_time.cc b/src/lib/dcpomatic_time.cc index 98888646d..6f8f5efa2 100644 --- a/src/lib/dcpomatic_time.cc +++ b/src/lib/dcpomatic_time.cc @@ -21,13 +21,42 @@ using std::ostream; -ContentTime::ContentTime (DCPTime d, FrameRateChange f) - : Time (rint (d.get() * f.speed_up)) +template <> +Time::Time (DCPTime d, FrameRateChange f) + : _t (llrint (d.get() * f.speed_up)) { } -DCPTime min (DCPTime a, DCPTime b) +template <> +Time::Time (ContentTime d, FrameRateChange f) + : _t (llrint (d.get() / f.speed_up)) +{ + +} + +DCPTime +min (DCPTime a, DCPTime b) +{ + if (a < b) { + return a; + } + + return b; +} + +DCPTime +max (DCPTime a, DCPTime b) +{ + if (a > b) { + return a; + } + + return b; +} + +ContentTime +min (ContentTime a, ContentTime b) { if (a < b) { return a; @@ -36,6 +65,16 @@ DCPTime min (DCPTime a, DCPTime b) return b; } +ContentTime +max (ContentTime a, ContentTime b) +{ + if (a > b) { + return a; + } + + return b; +} + ostream & operator<< (ostream& s, ContentTime t) { @@ -49,3 +88,15 @@ operator<< (ostream& s, DCPTime t) s << "[DCP " << t.get() << " " << t.seconds() << "s]"; return s; } + +bool +ContentTimePeriod::overlaps (ContentTimePeriod const & other) const +{ + return (from < other.to && to >= other.from); +} + +bool +ContentTimePeriod::contains (ContentTime const & other) const +{ + return (from <= other && other < to); +}