Skip to content

Commit

Permalink
Chrono: add methods FromScale()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Aug 29, 2014
1 parent 2ee8216 commit 94f6380
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Chrono.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ public:
return count() * T(scale) / 1000;
}

/**
* Convert a scalar value with the given scale to a #SongTime
* instance.
*
* @param value the input value
* @param scale the value's scale in Hz
*/
template<typename T=rep>
static constexpr SongTime FromScale(T value, unsigned scale) {
return SongTime(value * T(1000) / T(scale));
}

constexpr double ToDoubleS() const {
return double(count()) / 1000.;
};
Expand Down Expand Up @@ -163,6 +175,18 @@ public:
return count() * T(scale) / 1000;
}

/**
* Convert a scalar value with the given scale to a
* #SignedSongTime instance.
*
* @param value the input value
* @param scale the value's scale in Hz
*/
template<typename T=rep>
static constexpr SignedSongTime FromScale(T value, unsigned scale) {
return SignedSongTime(value * T(1000) / T(scale));
}

constexpr double ToDoubleS() const {
return double(count()) / 1000.;
};
Expand Down

0 comments on commit 94f6380

Please sign in to comment.