diff options
-rw-r--r-- | src/track/track.cpp | 37 | ||||
-rw-r--r-- | src/track/track.h | 8 |
2 files changed, 27 insertions, 18 deletions
diff --git a/src/track/track.cpp b/src/track/track.cpp index 92d6bab86b..b7689adb32 100644 --- a/src/track/track.cpp +++ b/src/track/track.cpp @@ -187,7 +187,7 @@ void Track::importMetadata( // If the Serato tags are empty they are not present. In this case // all existing metadata must be preserved! if (!newSeratoTags.isEmpty()) { - importBeats(newSeratoTags.importBeats(), newSeratoTags.isBpmLocked()); + tryImportBeats(newSeratoTags.importBeats(), newSeratoTags.isBpmLocked()); importCueInfos(newSeratoTags.importCueInfos()); setColor(newSeratoTags.getTrackColor()); } @@ -909,9 +909,9 @@ void Track::setCuePoints(const QList<CuePointer>& cuePoints) { cuePoints); } -Track::ImportStatus Track::importBeats( +Track::ImportStatus Track::tryImportBeats( mixxx::BeatsImporterPointer pBeatsImporter, - bool bpmLocked) { + bool lockBpmAfterSet) { QMutexLocker lock(&m_qMutex); VERIFY_OR_DEBUG_ASSERT(pBeatsImporter) { return ImportStatus::Complete; @@ -923,7 +923,7 @@ Track::ImportStatus Track::importBeats( return ImportStatus::Complete; } else if (m_record.hasStreamInfoFromSource()) { // Replace existing beats with imported beats immediately - importPendingBeatsMarkDirtyAndUnlock(&lock, bpmLocked); + tryImportPendingBeatsMarkDirtyAndUnlock(&lock, lockBpmAfterSet); return ImportStatus::Complete; } else { kLogger.debug() @@ -932,7 +932,7 @@ Track::ImportStatus Track::importBeats( // to be replaced with the imported beats soon. if (trySetBeatsMarkDirtyAndUnlock(&lock, nullptr, - bpmLocked)) { + lockBpmAfterSet)) { return ImportStatus::Pending; } else { return ImportStatus::Complete; @@ -973,22 +973,29 @@ bool Track::importPendingBeatsWhileLocked() { return setBeatsWhileLocked(pBeats); } -void Track::importPendingBeatsMarkDirtyAndUnlock( +bool Track::tryImportPendingBeatsMarkDirtyAndUnlock( QMutexLocker* pLock, - bool bpmLocked) { - DEBUG_ASSERT(pLock); + bool lockBpmAfterSet) { + DEBUG_ASSERT(lockBpmAfterSet); if (m_record.getBpmLocked()) { - return; + return false; } - if (!importPendingBeatsWhileLocked()) { - pLock->unlock(); - return; + bool dirty = false; + + if (importPendingBeatsWhileLocked()) { + dirty = true; } - if (bpmLocked) { - *(m_record.ptrBpmLocked()) = bpmLocked; + if (compareAndSet(m_record.ptrBpmLocked(), lockBpmAfterSet)) { + dirty = true; + } + + if (!dirty) { + // Already set, nothing todo + pLock->unlock(); + return true; } auto bpmValue = m_pBeats ? m_pBeats->getBpm() : mixxx::Bpm::kValueUndefined; @@ -996,6 +1003,8 @@ void Track::importPendingBeatsMarkDirtyAndUnlock( markDirtyAndUnlock(pLock); emit bpmUpdated(bpmValue); emit beatsUpdated(); + + return true; } Track::ImportStatus Track::importCueInfos( diff --git a/src/track/track.h b/src/track/track.h index d0e2450e2b..bac2f8d037 100644 --- a/src/track/track.h +++ b/src/track/track.h @@ -291,9 +291,9 @@ class Track : public QObject { /// /// If the list is empty it tries to complete any pending /// import and returns the corresponding status. - ImportStatus importBeats( + ImportStatus tryImportBeats( mixxx::BeatsImporterPointer pBeatsImporter, - bool bpmLocked); + bool lockBpmAfterSet); ImportStatus getBeatsImportStatus() const; void resetKeys(); @@ -415,9 +415,9 @@ class Track : public QObject { QMutexLocker* pLock, mixxx::BeatsPointer pBeats, bool lockBpmAfterSet); - void importPendingBeatsMarkDirtyAndUnlock( + bool tryImportPendingBeatsMarkDirtyAndUnlock( QMutexLocker* pLock, - bool bpmLocked); + bool lockBpmAfterSet); void setCuePointsMarkDirtyAndUnlock( QMutexLocker* pLock, |