diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-04-08 21:32:44 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-04-08 21:32:44 +0200 |
| commit | 3339d3bce70afe9ae2ca10e9fcfc4b54b748fbf4 (patch) | |
| tree | 9cac355432ba25cc3d43017382d73e0640f50996 /src/lib/dcpomatic_time.h | |
| parent | 00762c2d9a4240d016150cd7555aee3dad8542ae (diff) | |
Assorted C++11/formatting cleanups.
Diffstat (limited to 'src/lib/dcpomatic_time.h')
| -rw-r--r-- | src/lib/dcpomatic_time.h | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index 00a31a7a7..9e7191b1e 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,13 +18,16 @@ */ + /** @file src/lib/dcpomatic_time.h * @brief Types to describe time. */ + #ifndef DCPOMATIC_TIME_H #define DCPOMATIC_TIME_H + #include "frame_rate_change.h" #include "dcpomatic_assert.h" #include <boost/optional.hpp> @@ -34,9 +37,11 @@ #include <iomanip> #include <cstdio> + struct dcpomatic_time_ceil_test; struct dcpomatic_time_floor_test; + namespace dcpomatic { @@ -156,15 +161,15 @@ public: * @param r Sampling rate. */ Time<S, O> ceil (double r) const { - return Time<S, O> (llrint (HZ * frames_ceil(r) / r)); + return Time<S, O> (llrint(HZ * frames_ceil(r) / r)); } Time<S, O> floor (double r) const { - return Time<S, O> (llrint (HZ * frames_floor(r) / r)); + return Time<S, O> (llrint(HZ * frames_floor(r) / r)); } Time<S, O> round (double r) const { - return Time<S, O> (llrint (HZ * frames_round(r) / r)); + return Time<S, O> (llrint(HZ * frames_round(r) / r)); } double seconds () const { @@ -172,7 +177,7 @@ public: } Time<S, O> abs () const { - return Time<S, O> (std::abs (_t)); + return Time<S, O> (std::abs(_t)); } template <typename T> @@ -231,7 +236,6 @@ public: return buffer; } - static Time<S, O> from_seconds (double s) { return Time<S, O> (llrint (s * HZ)); } @@ -263,9 +267,11 @@ private: Type _t; }; + class ContentTimeDifferentiator {}; class DCPTimeDifferentiator {}; + /* Specializations for the two allowed explicit conversions */ template<> @@ -274,6 +280,7 @@ Time<ContentTimeDifferentiator, DCPTimeDifferentiator>::Time (Time<DCPTimeDiffer template<> Time<DCPTimeDifferentiator, ContentTimeDifferentiator>::Time (Time<ContentTimeDifferentiator, DCPTimeDifferentiator> d, FrameRateChange f); + /** Time relative to the start or position of a piece of content in its native frame rate */ typedef Time<ContentTimeDifferentiator, DCPTimeDifferentiator> ContentTime; /** Time relative to the start of the output DCP in its frame rate */ @@ -303,12 +310,12 @@ public: return TimePeriod<T> (from + o, to + o); } - boost::optional<TimePeriod<T> > overlap (TimePeriod<T> const & other) const { + boost::optional<TimePeriod<T>> overlap (TimePeriod<T> const & other) const { T const max_from = std::max (from, other.from); T const min_to = std::min (to, other.to); if (max_from >= min_to) { - return boost::optional<TimePeriod<T> > (); + return {}; } return TimePeriod<T> (max_from, min_to); @@ -334,36 +341,37 @@ public: } }; + /** @param A Period which is subtracted from. * @param B Periods to subtract from `A', must be in ascending order of start time and must not overlap. */ template <class T> -std::list<TimePeriod<T> > subtract (TimePeriod<T> A, std::list<TimePeriod<T> > const & B) +std::list<TimePeriod<T>> subtract (TimePeriod<T> A, std::list<TimePeriod<T>> const & B) { - std::list<TimePeriod<T> > result; + std::list<TimePeriod<T>> result; result.push_back (A); for (auto i: B) { - std::list<TimePeriod<T> > new_result; + std::list<TimePeriod<T>> new_result; for (auto j: result) { - boost::optional<TimePeriod<T> > ov = i.overlap (j); + auto ov = i.overlap (j); if (ov) { if (*ov == i) { /* A contains all of B */ if (i.from != j.from) { - new_result.push_back (TimePeriod<T> (j.from, i.from)); + new_result.push_back (TimePeriod<T>(j.from, i.from)); } if (i.to != j.to) { - new_result.push_back (TimePeriod<T> (i.to, j.to)); + new_result.push_back (TimePeriod<T>(i.to, j.to)); } } else if (*ov == j) { /* B contains all of A */ } else if (i.from < j.from) { /* B overlaps start of A */ - new_result.push_back (TimePeriod<T> (i.to, j.to)); + new_result.push_back (TimePeriod<T>(i.to, j.to)); } else if (i.to > j.to) { /* B overlaps end of A */ - new_result.push_back (TimePeriod<T> (j.from, i.from)); + new_result.push_back (TimePeriod<T>(j.from, i.from)); } } else { new_result.push_back (j); @@ -375,9 +383,11 @@ std::list<TimePeriod<T> > subtract (TimePeriod<T> A, std::list<TimePeriod<T> > c return result; } + typedef TimePeriod<ContentTime> ContentTimePeriod; typedef TimePeriod<DCPTime> DCPTimePeriod; + DCPTime min (DCPTime a, DCPTime b); DCPTime max (DCPTime a, DCPTime b); ContentTime min (ContentTime a, ContentTime b); @@ -386,6 +396,8 @@ std::string to_string (ContentTime t); std::string to_string (DCPTime t); std::string to_string (DCPTimePeriod p); + } + #endif |
