diff options
author | Nino Miškić-Pletenac <nino.mip@gmail.com> | 2017-07-01 02:15:05 +0200 |
---|---|---|
committer | Nino Miškić-Pletenac <nino.mip@gmail.com> | 2018-11-03 23:29:00 +0100 |
commit | 7f1625705279754b2d616bd63dcfeabac14fe12a (patch) | |
tree | 5057f6dc4811ea229aa36f8fa529499c9f0a2fd6 /src/track | |
parent | fbc60e7e489e74fc2f286888ec3a63a6a507d4bf (diff) |
Wrap cue position with its source in CuePosition class
Diffstat (limited to 'src/track')
-rw-r--r-- | src/track/cue.cpp | 5 | ||||
-rw-r--r-- | src/track/cue.h | 57 | ||||
-rw-r--r-- | src/track/track.cpp | 34 | ||||
-rw-r--r-- | src/track/track.h | 14 | ||||
-rw-r--r-- | src/track/trackrecord.cpp | 1 | ||||
-rw-r--r-- | src/track/trackrecord.h | 3 |
6 files changed, 78 insertions, 36 deletions
diff --git a/src/track/cue.cpp b/src/track/cue.cpp index c376d35194..17705e01d7 100644 --- a/src/track/cue.cpp +++ b/src/track/cue.cpp @@ -175,3 +175,8 @@ void Cue::setDirty(bool dirty) { QMutexLocker lock(&m_mutex); m_bDirty = dirty; } + +bool operator==(const CuePosition& lhs, const CuePosition& rhs) { + return lhs.getPosition() == rhs.getPosition() && + lhs.getSource() == rhs.getSource(); +} diff --git a/src/track/cue.h b/src/track/cue.h index 197dd67942..9e9029dfd3 100644 --- a/src/track/cue.h +++ b/src/track/cue.h @@ -8,6 +8,7 @@ #include "track/trackid.h" #include "util/memory.h" +class CuePosition; class CueDAO; class Track; @@ -58,6 +59,9 @@ class Cue : public QObject { QColor getColor() const; void setColor(QColor color); + CuePosition getCuePosition() const; + void setCuePosition(CuePosition position); + signals: void updated(); @@ -101,4 +105,57 @@ class CuePointer: public std::shared_ptr<Cue> { } }; +class CuePosition { + public: + CuePosition() + : m_position(0.0), m_source(Cue::UNKNOWN) {} + CuePosition(double position, Cue::CueSource source) + : m_position(position), m_source(source) {} + + double getPosition() const { + return m_position; + } + + void setPosition(double position) { + m_position = position; + } + + Cue::CueSource getSource() const { + if (m_position == 0.0 || m_position == -1.0) { + return Cue::UNKNOWN; + } + return m_source; + } + + void setSource(Cue::CueSource source) { + m_source = source; + } + + void set(double position, Cue::CueSource source) { + m_position = position; + m_source = source; + } + + void reset() { + m_position = 0.0; + m_source = Cue::UNKNOWN; + } + + private: + double m_position; + Cue::CueSource m_source; +}; + +bool operator==(const CuePosition& lhs, const CuePosition& rhs); + +inline +bool operator!=(const CuePosition& lhs, const CuePosition& rhs) { + return !(lhs == rhs); +} + +inline +QDebug operator<<(QDebug dbg, const CuePosition& arg) { + return dbg << "position =" << arg.getPosition() << "/" << "source =" << arg.getSource(); +} + #endif // MIXXX_CUE_H diff --git a/src/track/track.cpp b/src/track/track.cpp index 2725497937..867e40d5b8 100644 --- a/src/track/track.cpp +++ b/src/track/track.cpp @@ -70,7 +70,6 @@ Track::Track( m_record(trackId), m_bDirty(false), m_bMarkedForMetadataExport(false), - m_cueSource(Cue::UNKNOWN), m_analyzerProgress(-1) { if (kLogStats && kLogger.debugEnabled()) { long numberOfInstancesBefore = s_numberOfInstances.fetch_add(1); @@ -299,7 +298,7 @@ double Track::setBpm(double bpmValue) { if (!m_pBeats) { // No beat grid available -> create and initialize - double cue = getCuePoint(); + double cue = getCuePoint().getPosition(); BeatsPointer pBeats(BeatFactory::makeBeatGrid(*this, bpmValue, cue)); setBeatsAndUnlock(&lock, pBeats); return bpmValue; @@ -725,18 +724,18 @@ int Track::getAnalyzerProgress() const { return load_atomic(m_analyzerProgress); } -void Track::setCuePoint(double position, Cue::CueSource source) { +void Track::setCuePoint(CuePosition cue) { QMutexLocker lock(&m_qMutex); - bool positionModified = compareAndSet(&m_record.refCuePoint(), position); - bool sourceModified = compareAndSet(&m_cueSource, source); - if (!positionModified && !sourceModified) { + if (!compareAndSet(&m_record.refCuePoint(), cue)) { // Nothing changed. return; } // Store the cue point in a load cue CuePointer pLoadCue = findCueByType(Cue::LOAD); + Cue::CueSource source = cue.getSource(); + double position = cue.getPosition(); if (position != 0.0 && position != -1.0) { if (!pLoadCue) { pLoadCue = CuePointer(new Cue(m_record.getId())); @@ -750,27 +749,17 @@ void Track::setCuePoint(double position, Cue::CueSource source) { } else { disconnect(pLoadCue.get(), 0, this, 0); m_cuePoints.removeOne(pLoadCue); - m_cueSource = Cue::UNKNOWN; } markDirtyAndUnlock(&lock); emit(cuesUpdated()); } -double Track::getCuePoint() const { +CuePosition Track::getCuePoint() const { QMutexLocker lock(&m_qMutex); return m_record.getCuePoint(); } -Cue::CueSource Track::getCuePointSource() const { - QMutexLocker lock(&m_qMutex); - double position = m_record.getCuePoint(); - if (position == 0.0 || position == -1.0) { - return Cue::UNKNOWN; - } - return m_cueSource; -} - void Track::slotCueUpdated() { markDirty(); emit(cuesUpdated()); @@ -809,8 +798,7 @@ void Track::removeCue(const CuePointer& pCue) { disconnect(pCue.get(), 0, this, 0); m_cuePoints.removeOne(pCue); if (pCue->getType() == Cue::LOAD) { - m_record.setCuePoint(0.0); - m_cueSource = Cue::UNKNOWN; + m_record.setCuePoint(CuePosition()); } markDirtyAndUnlock(&lock); emit(cuesUpdated()); @@ -829,10 +817,7 @@ void Track::removeCuesOfType(Cue::CueType type) { dirty = true; } } - if (compareAndSet(&m_record.refCuePoint(), -1.0)) { - dirty = true; - } - if (compareAndSet(&m_cueSource, Cue::UNKNOWN)) { + if (compareAndSet(&m_record.refCuePoint(), CuePosition())) { dirty = true; } if (dirty) { @@ -860,8 +845,7 @@ void Track::setCuePoints(const QList<CuePointer>& cuePoints) { this, SLOT(slotCueUpdated())); // update main cue point if (pCue->getType() == Cue::LOAD) { - m_record.setCuePoint(pCue->getPosition()); - m_cueSource = pCue->getSource(); + m_record.setCuePoint(CuePosition(pCue->getPosition(), pCue->getSource())); } } markDirtyAndUnlock(&lock); diff --git a/src/track/track.h b/src/track/track.h index e50153ff8e..a259144553 100644 --- a/src/track/track.h +++ b/src/track/track.h @@ -100,6 +100,7 @@ class Track : public QObject { void setType(const QString&); QString getType() const; + // Set number of channels void setChannels(int iChannels); // Get number of channels int getChannels() const; @@ -108,7 +109,6 @@ class Track : public QObject { void setSampleRate(int iSampleRate); // Get sample rate int getSampleRate() const; - // Set number of channels // Sets the bitrate void setBitrate(int); @@ -244,11 +244,10 @@ class Track : public QObject { void setAnalyzerProgress(int progress); int getAnalyzerProgress() const; - // Save the cue point in samples - void setCuePoint(double position, Cue::CueSource source); - // Get saved the cue point - double getCuePoint() const; - Cue::CueSource getCuePointSource() const; + // Get the track's main cue point + CuePosition getCuePoint() const; + // Set the track's main cue point + void setCuePoint(CuePosition cue); // Calls for managing the track's cue points CuePointer createAndAddCue(); @@ -375,9 +374,6 @@ class Track : public QObject { // the metadata. bool m_bMarkedForMetadataExport; - // Cue point source - Cue::CueSource m_cueSource; - // The list of cue points for the track QList<CuePointer> m_cuePoints; diff --git a/src/track/trackrecord.cpp b/src/track/trackrecord.cpp index 8bf82f3cc1..2785303fb2 100644 --- a/src/track/trackrecord.cpp +++ b/src/track/trackrecord.cpp @@ -8,7 +8,6 @@ namespace mixxx { TrackRecord::TrackRecord(TrackId id) : m_id(std::move(id)), m_metadataSynchronized(false), - m_cuePoint(0.0), m_rating(0), m_bpmLocked(false) { } diff --git a/src/track/trackrecord.h b/src/track/trackrecord.h index 8f66cd60a5..e2ae213e88 100644 --- a/src/track/trackrecord.h +++ b/src/track/trackrecord.h @@ -3,6 +3,7 @@ #include "proto/keys.pb.h" #include "track/trackid.h" +#include "track/cue.h" #include "track/keys.h" #include "track/keyutils.h" #include "track/trackmetadata.h" @@ -43,7 +44,7 @@ class TrackRecord final { PROPERTY_SET_BYVAL_GET_BYREF(QString, fileType, FileType) PROPERTY_SET_BYVAL_GET_BYREF(QString, url, Url) PROPERTY_SET_BYVAL_GET_BYREF(PlayCounter, playCounter, PlayCounter) - PROPERTY_SET_BYVAL_GET_BYREF(double, cuePoint, CuePoint) + PROPERTY_SET_BYVAL_GET_BYREF(CuePosition, cuePoint, CuePoint) PROPERTY_SET_BYVAL_GET_BYREF(int, rating, Rating) PROPERTY_SET_BYVAL_GET_BYREF(bool, bpmLocked, BpmLocked) |