93 #ifndef LIB_TIME_TIMEVALUE_H 94 #define LIB_TIME_TIMEVALUE_H 98 #include <boost/operators.hpp> 99 #include <boost/rational.hpp> 105 #include <gavl/gavltime.h> 134 : boost::totally_ordered<TimeValue,
135 boost::totally_ordered<TimeValue, gavl_time_t>>
158 static gavl_time_t
limitedDelta (gavl_time_t origin, gavl_time_t target);
186 operator std::string ()
const;
193 friend bool operator< (
TimeValue const& t1, gavl_time_t t2) {
return t1.
t_ < t2 ; }
194 friend bool operator> (
TimeValue const& t1, gavl_time_t t2) {
return t1.
t_ > t2 ; }
196 friend bool operator== (
TimeValue const& t1, gavl_time_t t2) {
return t1.
t_ == t2 ; }
220 using FSecs = boost::rational<int64_t>;
234 , boost::additive<TimeVar,
235 boost::additive<TimeVar, TimeValue,
236 boost::multipliable<TimeVar, int>
261 operator gavl_time_t()
const {
return t_; }
270 TimeVar& operator*= (int64_t fact) {
t_ *= fact;
return *
this; }
310 static const Time MIN ;
311 static const Time ZERO;
335 operator std::string ()
const;
392 Offset stretchedByRationalFactor (boost::rational<int64_t>)
const;
393 Offset stretchedByFloatFactor (
double)
const;
396 operator std::string ()
const;
399 Offset operator- ()
const;
413 operator- (
Offset const& start,
Offset const& toSubtract)
416 distance -= toSubtract;
420 template<
typename FAC>
422 operator* (
Offset const& distance, FAC factor)
424 return factor*distance;
427 template<
typename INT>
429 operator* (INT factor,
Offset const& o)
436 template<
typename INTX>
438 operator* (boost::rational<INTX> factor,
Offset const& offset)
444 operator* (
double factor,
Offset const& offset)
503 REQUIRE (
t_ >= 0,
"Copy rejected: negative Duration %lu", o.
t_);
513 operator std::string ()
const;
516 Offset operator- ()
const;
535 template<
typename NUM>
537 operator* (NUM factor,
Duration const& dur)
539 return factor *
Offset(dur);
542 template<
typename NUM>
544 operator* (
Duration const& dur, NUM factor)
575 , boost::totally_ordered<TimeSpan>
587 , dur_(duration_in_secs)
591 :
Time(start<=end? start:end)
642 operator std::string ()
const;
647 (t1.
t_==t2.
t_ && t1.dur_< t2.dur_);}
656 :
public boost::rational<uint>
663 FrameRate (boost::rational<uint> fractionalRate);
669 double asDouble()
const;
680 operator std::string()
const;
687 return FSecs{ n*rate.denominator(), rate.numerator()};
697 template<
typename NUM>
699 __ensure_nonzero (NUM n)
702 throw error::Logic (
"Degenerated frame grid not allowed" 703 , LERR_(BOTTOM_VALUE));
708 symmetricLimit (gavl_time_t raw,
TimeValue lim)
710 return raw > lim?
_raw(lim)
711 : -raw > lim? -
_raw(lim)
728 const uint width =
sizeof(
HashVal) * CHAR_BIT;
729 const uint mask = width-1;
730 const uint n = width / 2;
732 static_assert (0 < n and n <= mask);
733 return (x<<n) | (x>>((-n)&mask ));
752 if (0 > (origin^target))
757 gavl_time_t res = target - origin;
773 return Time::MIN < *
this 779 TimeVar::TimeVar (
FSecs const& fractionalSeconds)
784 Offset::Offset (
TimeValue const& distance)
790 Duration::Duration (
TimeSpan const& interval)
795 FrameRate::FrameRate (uint fps)
796 : boost::rational<uint> (__ensure_nonzero(fps))
800 FrameRate::FrameRate (uint num, uint denom)
801 : boost::rational<uint> (__ensure_nonzero(num), denom)
805 FrameRate::FrameRate (boost::rational<uint> fractionalRate)
806 : boost::rational<uint> (__ensure_nonzero(fractionalRate))
810 boost::rational<uint> __framerate_approximation (
double);
813 FrameRate::FrameRate (
size_t count,
Duration timeReference)
814 :
FrameRate{__framerate_approximation (count, timeReference)}
818 FrameRate::approx (
double fps)
820 return FrameRate{__framerate_approximation (fps)};
825 FrameRate::asDouble()
const 827 return boost::rational_cast<
double> (*this);
850 template<
typename X,
typename COND>
static const Time ANYTIME
border condition marker value. ANYTIME <= any time value
TimeValue(TimeValue const &o)
copy initialisation allowed
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
TimeValue & operator=(TimeValue const &o)
Assigning of time values is not allowed, but derived classed might allow that.
static const Duration MAX
maximum possible temporal extension
TimeValue(gavl_time_t val)
Framerate specified as frames per second.
static const gavl_time_t SCALE
Number of micro ticks (µs) per second as basic time scale.
Offset stretchedByRationalFactor(boost::rational< int64_t >) const
Duration(FrameCnt count, FrameRate const &fps)
duration of the given number of frames.
Interface: an opaque change imposed onto some time value.
static const Duration NIL
constant to indicate "no duration"
Implementation namespace for support and library code.
Lumiera's internal time value datatype.
std::string operator+(std::string str, Literal const &sym)
string concatenation
Derived specific exceptions within Lumiera's exception hierarchy.
static const FrameRate STEP
1 frame per second
TimeSpan conform() const
<
Duration abs() const
interpret the distance given by this offset as a time duration
TimeValue(TimeValue const &origin, TimeValue const &target)
static TimeValue buildRaw_(gavl_time_t)
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Offset operator-() const
Supporting backwards use as offset.
friend HashVal hash_value(TimeValue const &)
derive a hash from the µ-tick value
Lumiera error handling (C++ interface).
size_t HashVal
a STL compatible hash value
static const Time NEVER
border condition marker value. NEVER >= any time value
Offset measures a distance in time.
static gavl_time_t limitedTime(gavl_time_t raw)
explicit limit of allowed time range
Duration is the internal Lumiera time metric.
static gavl_time_t limitedDelta(gavl_time_t origin, gavl_time_t target)
safe calculation of explicitly limited time offset
boost::rational< uint > __framerate_approximation(double fps)
abstract entry, not yet allocated
A time interval anchored at a specific point in time.
int64_t FrameCnt
relative framecount or frame number.
Offset operator-() const
flip offset direction
basic constant internal time value.
failsafe invocation of custom string conversion.
Offset stretchedByFloatFactor(double) const
gavl_time_t t_
the raw (internal) time value used to implement the time types
friend gavl_time_t _raw(TimeValue const &time)
static const FrameRate PAL
predefined constant for PAL framerate
TimeVar(TimeVar const &o)
Allowing copy and assignment.