X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fdcpomatic_time.cc;h=28f76607499134933815f888815265fdbceae9c4;hb=b31bf6be17a014eaa9603af4563388070ce3ed73;hp=98888646d0a841e26bcb077a426be8ac66e1e8e4;hpb=7f2e74604a51b984e4c8cbb5d5f4bb642677ec00;p=dcpomatic.git diff --git a/src/lib/dcpomatic_time.cc b/src/lib/dcpomatic_time.cc index 98888646d..28f766074 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); +}