summaryrefslogtreecommitdiffstats
path: root/src/audio
diff options
context:
space:
mode:
authorJan Holthuis <jholthuis@mixxx.org>2021-07-03 23:02:59 +0200
committerJan Holthuis <jholthuis@mixxx.org>2021-07-03 23:23:10 +0200
commit3ac8866e0b9e88fd7a2c01cb3b1bdb4e55ca25e2 (patch)
treeca4a2df5cd58a4a0ba88178a61e935452a12a7ac /src/audio
parent7c5f330f2357dc7cd936c346e27cdbb27a222a13 (diff)
FramePos: Add assertions when invalid values are accessed
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/frame.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/audio/frame.h b/src/audio/frame.h
index 5548e6a45f..a22ba84a7f 100644
--- a/src/audio/frame.h
+++ b/src/audio/frame.h
@@ -15,6 +15,8 @@ typedef double FrameDiff_t;
/// FramePos defines the position of a frame in a track
/// with respect to a fixed origin, i.e. start of the track.
+///
+/// Note that all invalid frame positions are considered equal.
class FramePos final {
public:
typedef double value_t;
@@ -33,7 +35,7 @@ class FramePos final {
return FramePos(engineSamplePos / mixxx::kEngineChannelCount);
}
- constexpr double toEngineSamplePos() const {
+ double toEngineSamplePos() const {
return value() * mixxx::kEngineChannelCount;
}
@@ -49,7 +51,10 @@ class FramePos final {
}
/// Return the underlying primitive value for this frame position.
- constexpr value_t value() const {
+ value_t value() const {
+ VERIFY_OR_DEBUG_ASSERT(isValid()) {
+ return FramePos::kInvalidValue;
+ }
return m_framePosition;
}
@@ -135,11 +140,11 @@ inline bool operator>=(FramePos frame1, FramePos frame2) {
}
inline bool operator==(FramePos frame1, FramePos frame2) {
- if (frame1.isValid() && frame1.isValid()) {
+ if (frame1.isValid() && frame2.isValid()) {
return frame1.value() == frame2.value();
}
- if (!frame1.isValid() && !frame1.isValid()) {
+ if (!frame1.isValid() && !frame2.isValid()) {
return true;
}
@@ -147,11 +152,15 @@ inline bool operator==(FramePos frame1, FramePos frame2) {
}
inline bool operator!=(FramePos frame1, FramePos frame2) {
- return !(frame1.value() == frame2.value());
+ return !(frame1 == frame2);
}
inline QDebug operator<<(QDebug dbg, FramePos arg) {
- dbg << arg.value();
+ if (arg.isValid()) {
+ dbg.nospace() << "FramePos(" << arg.value() << ")";
+ } else {
+ dbg << "FramePos()";
+ }
return dbg;
}