102 #ifndef LIB_TIME_TIMEVALUE_H 103 #define LIB_TIME_TIMEVALUE_H 107 #include <boost/operators.hpp> 108 #include <boost/rational.hpp> 114 #include <gavl/gavltime.h> 143 : boost::totally_ordered<TimeValue,
144 boost::totally_ordered<TimeValue, gavl_time_t>>
167 static gavl_time_t
limitedDelta (gavl_time_t origin, gavl_time_t target);
195 operator std::string ()
const;
202 friend bool operator< (
TimeValue const& t1, gavl_time_t t2) {
return t1.
t_ < t2 ; }
203 friend bool operator> (
TimeValue const& t1, gavl_time_t t2) {
return t1.
t_ > t2 ; }
205 friend bool operator== (
TimeValue const& t1, gavl_time_t t2) {
return t1.
t_ == t2 ; }
229 using FSecs = boost::rational<int64_t>;
243 , boost::additive<TimeVar,
244 boost::additive<TimeVar, TimeValue,
245 boost::multipliable<TimeVar, int>
270 operator gavl_time_t()
const {
return t_; }
279 TimeVar& operator*= (int64_t fact) {
t_ *= fact;
return *
this; }
319 static const Time MIN ;
320 static const Time ZERO;
344 operator std::string ()
const;
401 Offset stretchedByRationalFactor (boost::rational<int64_t>)
const;
402 Offset stretchedByFloatFactor (
double)
const;
405 operator std::string ()
const;
408 Offset operator- ()
const;
422 operator- (
Offset const& start,
Offset const& toSubtract)
425 distance -= toSubtract;
429 template<
typename FAC>
431 operator* (
Offset const& distance, FAC factor)
433 return factor*distance;
436 template<
typename INT>
438 operator* (INT factor,
Offset const& o)
445 template<
typename INTX>
447 operator* (boost::rational<INTX> factor,
Offset const& offset)
453 operator* (
double factor,
Offset const& offset)
512 REQUIRE (
t_ >= 0,
"Copy rejected: negative Duration %lu", o.
t_);
522 operator std::string ()
const;
525 Offset operator- ()
const;
544 template<
typename NUM>
546 operator* (NUM factor,
Duration const& dur)
548 return factor *
Offset(dur);
551 template<
typename NUM>
553 operator* (
Duration const& dur, NUM factor)
584 , boost::totally_ordered<TimeSpan>
596 , dur_(duration_in_secs)
600 :
Time(start<=end? start:end)
651 operator std::string ()
const;
656 (t1.
t_==t2.
t_ && t1.dur_< t2.dur_);}
665 :
public boost::rational<uint>
672 FrameRate (boost::rational<uint> fractionalRate);
678 double asDouble()
const;
689 operator std::string()
const;
696 return FSecs{ n*rate.denominator(), rate.numerator()};
706 template<
typename NUM>
708 __ensure_nonzero (NUM n)
711 throw error::Logic (
"Degenerated frame grid not allowed" 712 , LERR_(BOTTOM_VALUE));
717 symmetricLimit (gavl_time_t raw,
TimeValue lim)
719 return raw > lim?
_raw(lim)
720 : -raw > lim? -
_raw(lim)
737 const uint width =
sizeof(
HashVal) * CHAR_BIT;
738 const uint mask = width-1;
739 const uint n = width / 2;
741 static_assert (0 < n and n <= mask);
742 return (x<<n) | (x>>((-n)&mask ));
761 if (0 > (origin^target))
766 gavl_time_t res = target - origin;
782 return Time::MIN < *
this 788 TimeVar::TimeVar (
FSecs const& fractionalSeconds)
793 Offset::Offset (
TimeValue const& distance)
799 Duration::Duration (
TimeSpan const& interval)
804 FrameRate::FrameRate (uint fps)
805 : boost::rational<uint> (__ensure_nonzero(fps))
809 FrameRate::FrameRate (uint num, uint denom)
810 : boost::rational<uint> (__ensure_nonzero(num), denom)
814 FrameRate::FrameRate (boost::rational<uint> fractionalRate)
815 : boost::rational<uint> (__ensure_nonzero(fractionalRate))
819 boost::rational<uint> __framerate_approximation (
double);
822 FrameRate::FrameRate (
size_t count,
Duration timeReference)
823 :
FrameRate{__framerate_approximation (count, timeReference)}
827 FrameRate::approx (
double fps)
829 return FrameRate{__framerate_approximation (fps)};
834 FrameRate::asDouble()
const 836 return boost::rational_cast<
double> (*this);
859 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.