20 #ifndef MPD_CHRONO_HXX 21 #define MPD_CHRONO_HXX 31 class SongTime :
public std::chrono::duration<std::uint32_t, std::milli> {
32 typedef std::chrono::duration<std::uint32_t, std::milli> Base;
33 typedef Base::rep rep;
61 constexpr rep
ToS()
const {
62 return count() / rep(1000);
66 return (count() + 500) / rep(1000);
69 constexpr rep
ToMS()
const {
73 template<
typename T=rep>
74 constexpr T
ToScale(
unsigned scale)
const {
75 return count() * T(scale) / 1000;
85 template<
typename T=rep>
87 return SongTime(value * T(1000) / T(scale));
91 return double(count()) / 1000.;
103 return SongTime(*(
const Base *)
this + (
const Base &)other);
107 return SongTime(*(
const Base *)
this - (
const Base &)other);
116 typedef std::chrono::duration<std::int32_t, std::milli> Base;
117 typedef Base::rep rep;
161 constexpr rep
ToS()
const {
162 return count() / rep(1000);
166 return (count() + 500) / rep(1000);
173 template<
typename T=rep>
175 return count() * T(scale) / 1000;
185 template<
typename T=rep>
191 return double(count()) / 1000.;
static constexpr SignedSongTime FromS(double s)
constexpr SignedSongTime(T t)
constexpr SongTime operator+(const SongTime &other) const
constexpr rep ToS() const
static constexpr SongTime zero()
A time stamp within a song.
static constexpr SongTime FromS(unsigned s)
static constexpr SignedSongTime zero()
constexpr SignedSongTime(SongTime t)
Allow implicit conversion from SongTime to SignedSongTime.
constexpr T ToScale(unsigned scale) const
constexpr rep RoundS() const
constexpr bool IsZero() const
constexpr rep RoundS() const
constexpr rep ToMS() const
static constexpr SignedSongTime FromMS(rep ms)
static constexpr SignedSongTime FromS(int s)
static constexpr SignedSongTime FromScale(T value, unsigned scale)
Convert a scalar value with the given scale to a SignedSongTime instance.
static constexpr SongTime FromS(double s)
static constexpr SignedSongTime Negative()
Generate a negative value.
constexpr bool IsNegative() const
static constexpr SongTime FromS(float s)
static constexpr SongTime FromMS(rep ms)
constexpr bool IsPositive() const
constexpr double ToDoubleS() const
constexpr SignedSongTime operator+(const SignedSongTime &other) const
constexpr bool IsZero() const
constexpr rep ToMS() const
static constexpr SignedSongTime FromS(unsigned s)
A variant of SongTime that is based on a signed integer.
constexpr double ToDoubleS() const
constexpr bool IsPositive() const
constexpr rep ToS() const
static constexpr SongTime FromScale(T value, unsigned scale)
Convert a scalar value with the given scale to a SongTime instance.
constexpr SongTime operator-(const SongTime &other) const
constexpr SignedSongTime operator-(const SignedSongTime &other) const
constexpr T ToScale(unsigned scale) const
static constexpr SignedSongTime FromS(float s)