From 94f6380d693b8bece655885d37495a3a73c78b62 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@duempel.org>
Date: Fri, 29 Aug 2014 20:57:25 +0200
Subject: Chrono: add methods FromScale()

---
 src/Chrono.hxx | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

(limited to 'src/Chrono.hxx')

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.;
 	};
-- 
cgit v1.2.3