Skip to content

Commit

Permalink
Bpm: Only access value if it's actually valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Jul 4, 2021
1 parent 61a315b commit 85a5b64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/library/dao/trackdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,8 @@ void bindTrackLibraryValues(
QString beatsVersion;
QString beatsSubVersion;
// Fall back on cached BPM
double dBpm = trackInfo.getBpm().getValue();
const mixxx::Bpm bpm = trackInfo.getBpm();
double dBpm = bpm.hasValue() ? bpm.getValue() : mixxx::Bpm::kValueUndefined;
if (!pBeats.isNull()) {
beatsBlob = pBeats->toByteArray();
beatsVersion = pBeats->getVersion();
Expand Down
6 changes: 4 additions & 2 deletions src/track/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ void Track::replaceMetadataFromSource(
// Need to set BPM after sample rate since beat grid creation depends on
// knowing the sample rate. Bug #1020438.
auto beatsAndBpmModified = false;
if (!m_pBeats || !mixxx::Bpm::isValidValue(m_pBeats->getBpm())) {
if (importedBpm.hasValue() &&
(!m_pBeats || !mixxx::Bpm::isValidValue(m_pBeats->getBpm()))) {
// Only use the imported BPM if the current beat grid is either
// missing or not valid! The BPM value in the metadata might be
// imprecise (normalized or rounded), e.g. ID3v2 only supports
Expand Down Expand Up @@ -363,7 +364,8 @@ bool Track::trySetBpmWhileLocked(double bpmValue) {

double Track::getBpm() const {
const QMutexLocker lock(&m_qMutex);
return getBpmWhileLocked().getValue();
const mixxx::Bpm bpm = getBpmWhileLocked();
return bpm.hasValue() ? bpm.getValue() : mixxx::Bpm::kValueUndefined;
}

bool Track::trySetBpm(double bpmValue) {
Expand Down

0 comments on commit 85a5b64

Please sign in to comment.