2 #include <ossia/detail/config.hpp>
4 #include <ossia/detail/flicks.hpp>
6 #include <mach/time_value.h>
20 using physical_time = int64_t;
36 constexpr
time_value& operator=(
bool d) noexcept =
delete;
37 constexpr
time_value& operator=(
double d) noexcept =
delete;
38 constexpr
time_value& operator=(
float d) noexcept =
delete;
39 constexpr
time_value& operator=(uint64_t d) noexcept =
delete;
41 constexpr
time_value& operator=(int64_t d) noexcept
49 constexpr
time_value& operator+=(
float d) noexcept =
delete;
51 constexpr
time_value& operator+=(int64_t d) noexcept
63 if(infinite() || t.infinite())
73 constexpr
time_value& operator-=(int64_t d) noexcept
85 if(infinite() || t.infinite())
93 constexpr time_value& operator-() noexcept
105 assert(!std::isnan(d));
106 assert(d <
static_cast<double>(infinite_min));
109 constexpr
time_value operator+(int64_t d)
const noexcept
113 constexpr time_value operator+(uint64_t d)
const noexcept
115 assert(d < infinite_min);
116 return *
this + time_value{int64_t(d)};
118 constexpr time_value operator-(int64_t d)
const noexcept
120 return *
this + time_value{-d};
122 constexpr time_value operator-(uint64_t d)
const noexcept
124 assert(d < infinite_min);
125 return *
this + time_value{-int64_t(d)};
128 static constexpr
bool
131 if(lhs.infinite() || rhs.infinite())
135 else if(lhs.impl >= 0 && rhs.impl >= 0)
137 uint64_t l = lhs.impl;
138 uint64_t r = rhs.impl;
139 return l + r >= infinite_min;
141 else if(lhs.impl >= 0 && rhs.impl < 0)
143 uint64_t l = lhs.impl;
144 return l + rhs.impl >= infinite_min;
146 else if(lhs.impl < 0 && rhs.impl >= 0)
148 uint64_t r = rhs.impl;
149 return lhs.impl + r >= infinite_min;
151 else if(lhs.impl < 0 && rhs.impl < 0)
154 uint64_t l = -lhs.impl;
155 uint64_t r = -rhs.impl;
156 return l + r >= infinite_min;
162 static constexpr
bool
165 if(lhs.infinite() || rhs.infinite())
169 else if(lhs.impl >= 0 && rhs.impl >= 0)
173 else if(lhs.impl >= 0 && rhs.impl < 0)
175 uint64_t l = lhs.impl;
176 uint64_t r = -rhs.impl;
177 return l + r >= infinite_min;
179 else if(lhs.impl < 0 && rhs.impl >= 0)
181 uint64_t l = -lhs.impl;
182 uint64_t r = rhs.impl;
183 return l + r >= infinite_min;
185 else if(lhs.impl < 0 && rhs.impl < 0)
195 if(add_is_infinite(*
this, t))
196 return time_value{infinity};
198 return time_value{impl + t.impl};
205 assert(!std::isnan(d));
206 assert(d <
static_cast<double>(infinite_min));
212 if(sub_is_infinite(*
this, t))
215 return time_value{impl - t.impl};
224 constexpr
time_value operator*(
double d)
const noexcept
229 constexpr time_value operator*(int32_t d)
const noexcept
231 return time_value{impl * d};
234 constexpr time_value operator*(int64_t d)
const noexcept
236 return time_value{impl * d};
239 constexpr time_value operator*(uint32_t d)
const noexcept
241 return time_value{impl * d};
244 constexpr time_value operator*(uint64_t d)
const noexcept
246 return time_value{int64_t(impl * d)};
249 friend constexpr
double operator/(time_value lhs, time_value rhs) noexcept
251 return double(lhs.impl) / double(rhs.impl);
256 [[nodiscard]] constexpr
bool infinite() const noexcept {
return impl >= infinite_min; }
263 return (infinite() && rhs.infinite()) || (impl == rhs.impl);
267 return (infinite() != rhs.infinite()) || (impl != rhs.impl);
271 return !(infinite() && rhs.infinite()) && (impl < rhs.impl);
275 return !(infinite() && rhs.infinite()) && (impl > rhs.impl);
279 return !(infinite() && rhs.infinite()) && (impl <= rhs.impl);
283 return !(infinite() && rhs.infinite()) && (impl >= rhs.impl);
289 constexpr
inline time_value
operator"" _tv(
long double v) noexcept
291 return time_value{int64_t(v)};
294 constexpr
inline time_value
operator"" _tv(
unsigned long long v) noexcept
296 return time_value{(int64_t)v};
299 const constexpr time_value Infinite{time_value::infinity};
300 const constexpr time_value Zero{0};
301 const constexpr time_value One{1};
303 constexpr
inline time_value abs(time_value t) noexcept
305 return time_value{t.impl >= 0 ? t.impl : -t.impl};
308 constexpr
inline time_value norm(time_value t1, time_value t2) noexcept
310 if(t1.infinite() || t2.infinite())
312 return time_value{t1.impl > t2.impl ? t1.impl - t2.impl : t2.impl - t1.impl};
317 const double samples_per_flicks = rate / ossia::flicks_per_second<double>;
318 return (rate > 0 && !t.infinite()) ? std::round(t.impl * samples_per_flicks) : 0;
constexpr OSSIA_INLINE auto max(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
max function tailored for values
Definition: math.hpp:96
The time_value class.
Definition: ossia/editor/scenario/time_value.hpp:28
constexpr time_value & operator+=(double d) noexcept=delete
self addition operator
time_value operator-(double d) const noexcept
substraction operator
Definition: ossia/editor/scenario/time_value.hpp:203
constexpr time_value operator*(float d) const noexcept
multiplication operator
Definition: ossia/editor/scenario/time_value.hpp:219
time_value operator+(double d) const noexcept
addition operator
Definition: ossia/editor/scenario/time_value.hpp:103
constexpr bool infinite() const noexcept
is the time value infinite ?
Definition: ossia/editor/scenario/time_value.hpp:256
constexpr time_value & operator-=(double d) noexcept=delete
self substraction operator