From 2c08044f1800ff05104fbaa213000a1ab59cb894 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Tue, 8 Dec 2020 15:10:19 +0100 Subject: [PATCH] Beatgrid: Add debug asserts to ensure correct behavior --- src/track/beatgrid.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/track/beatgrid.cpp b/src/track/beatgrid.cpp index 99b279cbee89..d9d43033fc94 100644 --- a/src/track/beatgrid.cpp +++ b/src/track/beatgrid.cpp @@ -141,13 +141,17 @@ bool BeatGrid::isValid() const { // This could be implemented in the Beats Class itself. // If necessary, the child class can redefine it. double BeatGrid::findNextBeat(double dSamples) const { - return findNthBeat(dSamples, +1); + const double position = findNthBeat(dSamples, +1); + DEBUG_ASSERT(position >= dSamples || position == -1); + return position; } // This could be implemented in the Beats Class itself. // If necessary, the child class can redefine it. double BeatGrid::findPrevBeat(double dSamples) const { - return findNthBeat(dSamples, -1); + const double position = findNthBeat(dSamples, -1); + DEBUG_ASSERT(position <= dSamples); + return position; } // This is an internal call. This could be implemented in the Beats Class itself.