46#include <boost/rational.hpp>
47#include <boost/lexical_cast.hpp>
54using boost::rational_cast;
55using boost::lexical_cast;
110 if (abs(fractionalSeconds) > lib::time::FSEC_MAX)
111 return (fractionalSeconds < 0? -1:+1)
112 * std::numeric_limits<int64_t>::max();
115 ,fractionalSeconds.denominator()
127 + 1000 * 60 * 60 * hours;
150 :
TimeValue(build_time_from (millis,secs,mins,hours))
159 :
TimeValue(build_time_from (fractionalSeconds))
163 :
TimeValue{buildRaw_(symmetricLimit (build_time_from (delta_in_secs)
171 TimeValue::operator string()
const
174 int64_t millis, seconds;
175 bool negative = (
time < 0);
178 time /= TIME_SCALE_MS;
179 millis =
time % 1000;
180 seconds =
time / 1000;
182 return string (negative ?
"-" :
"")
183 + (seconds>0 or
time==0? lexical_cast<string> (seconds)+
"s" :
"")
184 + (millis>0? lexical_cast<string> (millis)+
"ms" :
"")
196 Time::operator string()
const
199 int millis, seconds, minutes, hours;
200 bool negative = (
time < 0);
205 time /= TIME_SCALE_MS;
206 millis =
time % 1000;
223 Offset::operator string()
const
225 return (t_< 0?
"" :
"∆")
226 + TimeValue::operator string();
229 Duration::operator string()
const
231 return "≺"+TimeValue::operator string()+
"≻";
234 TimeSpan::operator string()
const
236 return string (start())
237 + string (duration());
242 template<
typename RAT>
246 std::ostringstream buffer;
247 if (1 == frac.denominator() or 0 == frac.numerator())
248 buffer << frac.numerator() << postfx;
250 buffer << frac <<postfx;
258 FrameRate::operator string()
const
260 return renderFraction (*
this,
"FPS");
270 return reinterpret_cast<TimeValue const&
> (raw);
289 throw error::Logic (
"Impossible to quantise to an zero spaced frame grid"
290 , error::LUMIERA_ERROR_BOTTOM_VALUE);
308 boost::rational<uint>
311 const double UPPER_LIMIT = int64_t(
RATE_LIMIT*1024) << 31;
314 double doo = limited (1.0, fabs(fps) *
RATE_LIMIT + 0.5, UPPER_LIMIT);
320 int64_t num = quantised.numerator();
324 int64_t base = quantised.denominator();
339 boost::rational<uint>
342 boost::rational<uint64_t> quot{cnt, _raw(timeReference)};
346 ,
uint(quot.denominator())
359 boost::rational<int64_t> distance (this->
t_);
361 raw_time_64 microTicks = floordiv (distance.numerator(), distance.denominator());
370 double distance(this->
t_);
382 boost::rational<uint64_t> framerate (fps.numerator(), fps.denominator());
391 count? (count<0? -1:+1) * framecount_to_time (::abs(count), fps)
404 return reinterpret_cast<Duration const&
> (maxDelta);
417 return lib::time::renderFraction (val,
"sec");
Duration is the internal Lumiera time metric.
static const Duration MAX
maximum possible temporal extension
static const Duration NIL
constant to indicate "no duration"
Framerate specified as frames per second.
static const FrameRate STEP
1 frame per second
Duration duration() const
duration of one frame
static const FrameRate PAL
predefined constant for PAL framerate
static const FrameRate NTSC
static const FrameRate HALTED
Offset measures a distance in time.
Offset stretchedByFloatFactor(double) const
Offset(TimeValue const &distance=Time::ZERO)
Offset stretchedByRationalFactor(boost::rational< int64_t >) const
static const TimeSpan ALL
basic constant internal time value.
static const raw_time_64 SCALE
Number of micro ticks (µs) per second as basic time scale.
static TimeValue buildRaw_(raw_time_64)
raw_time_64 t_
the raw (internal) time value used to implement the time types
static const Time NEVER
border condition marker value. NEVER >= any time value
static const Time ANYTIME
border condition marker value. ANYTIME <= any time value
Time(int)
suppress possible direct conversions
A front-end for using printf-style formatting.
Lumiera error handling (C++ interface).
raw_time_64 framecount_to_time(uint64_t frameCount, FrameRate const &fps)
Literal DIAGNOSTIC_FORMAT
raw_time_64 build_time_from(FSecs const &fractionalSeconds)
Converts a fraction of seconds to Lumiera's internal opaque time scale.
string renderFraction(RAT const &frac, Literal postfx) noexcept
const raw_time_64 TIME_SCALE_MS(lib::time::TimeValue::SCALE/1000)
scale factor used locally within this implementation header.
int64_t FrameCnt
relative framecount or frame number.
int64_t raw_time_64
Raw µ-tick time representation used in Lumiera.
const uint RATE_LIMIT
a rather arbitrary safety limit imposed on internal numbers used to represent a frame rate.
boost::rational< int64_t > FSecs
rational representation of fractional seconds
boost::rational< uint > __framerate_approximation(double fps)
Implementation namespace for support and library code.
LumieraError< LERR_(LOGIC)> Logic
constexpr int ilog2(I num)
Integral binary logarithm (disregarding fractional part)
boost::rational< int64_t > Rat
I floordiv(I num, I den)
floor function for integer arithmetics.
constexpr NUM limited(NB lowerBound, NUM val, NB upperBound)
force a numeric to be within bounds, inclusively
int64_t reQuant(int64_t num, int64_t den, int64_t u)
Re-Quantise a number into a new grid, truncating to the next lower grid point.
Rational number support, based on boost::rational.
static std::string invoke(X const &x) noexcept
a family of time value like entities and their relationships.
Utilities for quantisation (grid alignment) and comparisons.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
#define MAX(A, B)
the inevitable MAX macro, sometimes still necessary in template code