Skip to content

Commit

Permalink
Merge pull request #2235 from daschuer/lp1839669
Browse files Browse the repository at this point in the history
fix assertion in Lp1839669
  • Loading branch information
uklotzde authored Dec 9, 2019
2 parents da2e78f + 99033ef commit 80ec75a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1207,15 +1207,24 @@ void EngineBuffer::postProcess(const int iBufferSize) {
}

void EngineBuffer::updateIndicators(double speed, int iBufferSize) {
VERIFY_OR_DEBUG_ASSERT(m_trackSampleRateOld && m_tempo_ratio_old) {
// no track loaded, function not called in this case
if (!m_trackSampleRateOld) {
// This happens if Deck Passthrough is active but no track is loaded.
// We skip indicator updates.
return;
}

// Increase samplesCalculated by the buffer size
m_iSamplesSinceLastIndicatorUpdate += iBufferSize;

const double fFractionalPlaypos = fractionalPlayposFromAbsolute(m_filepos_play);

double ratio = m_tempo_ratio_old;
if (ratio == 0.0) {
// In case the track is slowed done to zero we will have INF remaining seconds.
// We jump back to a rate of 1.0 to show a useful time.
ratio = 1.0;
}

const double tempoTrackSeconds = m_trackSamplesOld / kSamplesPerFrame
/ m_trackSampleRateOld / m_tempo_ratio_old;
if(speed > 0 && fFractionalPlaypos == 1.0) {
Expand Down
19 changes: 12 additions & 7 deletions src/test/durationutiltest.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <limits>

#include <gtest/gtest.h>

#include "util/duration.h"
Expand All @@ -9,15 +11,17 @@ namespace {
class DurationUtilTest : public testing::Test {
protected:
static QString adjustPrecision(
QString withMilliseconds,
mixxx::Duration::Precision precision) {
switch (precision) {
case mixxx::Duration::Precision::SECONDS:
QString withMilliseconds,
mixxx::Duration::Precision precision) {
if (withMilliseconds == mixxx::DurationBase::kInvalidDurationString)
{
return withMilliseconds;
}
switch (precision) {
case mixxx::Duration::Precision::SECONDS: {
return withMilliseconds.left(withMilliseconds.length() - 4);
}
case mixxx::Duration::Precision::CENTISECONDS:
{
case mixxx::Duration::Precision::CENTISECONDS: {
return withMilliseconds.left(withMilliseconds.length() - 1);
}
default:
Expand All @@ -26,7 +30,6 @@ class DurationUtilTest : public testing::Test {
}

void formatTime(QString expectedMilliseconds, double dSeconds) {
ASSERT_LE(4, expectedMilliseconds.length()); // 3 digits + 1 decimal point
const QString actualSeconds =
mixxx::Duration::formatTime(dSeconds, mixxx::Duration::Precision::SECONDS);
const QString expectedSeconds =
Expand Down Expand Up @@ -112,6 +115,8 @@ TEST_F(DurationUtilTest, formatTime) {
formatTime("24:00:00.000", 24 * 3600);
formatTime("24:00:01.000", 24 * 3600 + 1);
formatTime("25:00:01.000", 25 * 3600 + 1);
formatTime("?", std::numeric_limits<double>::infinity());
formatTime("?", -1);
}

TEST_F(DurationUtilTest, formatSeconds) {
Expand Down
6 changes: 4 additions & 2 deletions src/util/duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QTime>

#include "util/assert.h"
#include "util/fpclassify.h"
#include "util/math.h"

namespace mixxx {
Expand All @@ -26,8 +27,9 @@ QChar DurationBase::kDecimalSeparator = QChar(0x002E);

// static
QString DurationBase::formatTime(double dSeconds, Precision precision) {
if (dSeconds < 0.0) {
// negative durations are not supported
if (dSeconds < 0.0 || !isfinite(dSeconds)
|| dSeconds > std::numeric_limits<qint64>::max()) {
// negative durations and infinity or isNaN values are not supported
return kInvalidDurationString;
}

Expand Down

0 comments on commit 80ec75a

Please sign in to comment.