aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-08-29 20:57:25 +0200
committerMax Kellermann <max@duempel.org>2014-08-29 21:38:08 +0200
commit94f6380d693b8bece655885d37495a3a73c78b62 (patch)
tree87a5171aa11b51b062feb53d9437f288281b58b6 /src
parent2ee821656f30d8dbd5369f26d5c9ae2c50188cb6 (diff)
downloadmpd-94f6380d693b8bece655885d37495a3a73c78b62.tar.gz
mpd-94f6380d693b8bece655885d37495a3a73c78b62.tar.xz
mpd-94f6380d693b8bece655885d37495a3a73c78b62.zip
Chrono: add methods FromScale()
Diffstat (limited to 'src')
-rw-r--r--src/Chrono.hxx24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Chrono.hxx b/src/Chrono.hxx
index 66121db99..e4a304e2c 100644
--- a/src/Chrono.hxx
+++ b/src/Chrono.hxx
@@ -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.;
};
@@ -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.;
};