summaryrefslogtreecommitdiff
path: root/libs/evoral
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2016-09-13 13:54:02 -0500
committerPaul Davis <paul@linuxaudiosystems.com>2016-09-13 14:11:29 -0500
commite05cb11bb003d80781006152d97b4dc35e4275c6 (patch)
tree5bce9cc0e35d11ef9f0c98b7275467206922510d /libs/evoral
parentc578fc724be09245addff4010c93b85828ea99a7 (diff)
extend Evoral::Range<T> to offer ::length() and ::squish()
The latter maps a T into a range, using loop semantics
Diffstat (limited to 'libs/evoral')
-rw-r--r--libs/evoral/evoral/Range.hpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/libs/evoral/evoral/Range.hpp b/libs/evoral/evoral/Range.hpp
index 9d47faf30d..e2ac87e909 100644
--- a/libs/evoral/evoral/Range.hpp
+++ b/libs/evoral/evoral/Range.hpp
@@ -138,6 +138,18 @@ struct /*LIBEVORAL_API*/ Range {
T from; ///< start of the range
T to; ///< end of the range (inclusive: to lies inside the range)
bool empty() const { return from == to; }
+ T length() const { return to - from + 1; }
+
+ /** for a T, return a mapping of it into the range (used for
+ * looping). If the argument is earlier than or equal to the end of
+ * this range, do nothing.
+ */
+ T squish (T t) const {
+ if (t > to) {
+ t = (from + ((t - from) % length()));
+ }
+ return t;
+ }
};
template<typename T>