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 | |
parent | fbc60e7e489e74fc2f286888ec3a63a6a507d4bf (diff) |
Wrap cue position with its source in CuePosition class
-rw-r--r-- | src/analyzer/analyzersilence.cpp | 6 | ||||
-rw-r--r-- | src/engine/cuecontrol.cpp | 4 | ||||
-rw-r--r-- | src/engine/vinylcontrolcontrol.cpp | 2 | ||||
-rw-r--r-- | src/library/dao/trackdao.cpp | 4 | ||||
-rw-r--r-- | src/library/dlgtrackinfo.cpp | 8 | ||||
-rw-r--r-- | src/test/analyzersilence_test.cpp | 34 | ||||
-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 |
12 files changed, 110 insertions, 62 deletions
diff --git a/src/analyzer/analyzersilence.cpp b/src/analyzer/analyzersilence.cpp index d6045c606d..1e78a2cd1d 100644 --- a/src/analyzer/analyzersilence.cpp +++ b/src/analyzer/analyzersilence.cpp @@ -49,7 +49,7 @@ bool AnalyzerSilence::initialize(TrackPointer tio, int sampleRate, int totalSamp } bool AnalyzerSilence::isDisabledOrLoadStoredSuccess(TrackPointer tio) const { - return tio->getCuePointSource() == Cue::MANUAL && + return tio->getCuePoint().getSource() == Cue::MANUAL && m_pBeginCue->getSource() == Cue::MANUAL && m_pEndCue->getSource() == Cue::MANUAL; } @@ -69,9 +69,9 @@ void AnalyzerSilence::process(const CSAMPLE* pIn, const int iLen) { if (m_iSignalBegin < 0) { m_iSignalBegin = m_iFramesProcessed + i / kChannelCount; - if (m_pTrack->getCuePointSource() != Cue::MANUAL) { + if (m_pTrack->getCuePoint().getSource() != Cue::MANUAL) { double position = m_iFramesProcessed * kChannelCount + i; - m_pTrack->setCuePoint(position, Cue::AUTOMATIC); + m_pTrack->setCuePoint(CuePosition(position, Cue::AUTOMATIC)); } } } else if (!m_bPrevSilence && bSilence) { diff --git a/src/engine/cuecontrol.cpp b/src/engine/cuecontrol.cpp index 8adba21f2e..11a90d1e66 100644 --- a/src/engine/cuecontrol.cpp +++ b/src/engine/cuecontrol.cpp @@ -703,7 +703,7 @@ void CueControl::cueSet(double v) { // Store cue point in loaded track if (pLoadedTrack) { - pLoadedTrack->setCuePoint(cue, Cue::MANUAL); + pLoadedTrack->setCuePoint(CuePosition(cue, Cue::MANUAL)); } } @@ -719,7 +719,7 @@ void CueControl::cueClear(double v) { lock.unlock(); if (pLoadedTrack) { - pLoadedTrack->setCuePoint(-1.0, Cue::UNKNOWN); + pLoadedTrack->setCuePoint(CuePosition()); } } diff --git a/src/engine/vinylcontrolcontrol.cpp b/src/engine/vinylcontrolcontrol.cpp index aaef055ec4..28b11b63bf 100644 --- a/src/engine/vinylcontrolcontrol.cpp +++ b/src/engine/vinylcontrolcontrol.cpp @@ -107,7 +107,7 @@ void VinylControlControl::slotControlVinylSeek(double fractionalPos) { return; // If off, do nothing. case MIXXX_RELATIVE_CUE_ONECUE: //if onecue, just seek to the regular cue - seekExact(m_pCurrentTrack->getCuePoint()); + seekExact(m_pCurrentTrack->getCuePoint().getPosition()); return; case MIXXX_RELATIVE_CUE_HOTCUE: // Continue processing in this function. diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index 0b37dadaac..0181952b2e 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -409,7 +409,7 @@ namespace { pTrackLibraryQuery->bindValue(":rating", track.getRating()); pTrackLibraryQuery->bindValue(":bitrate", track.getBitrate()); pTrackLibraryQuery->bindValue(":samplerate", track.getSampleRate()); - pTrackLibraryQuery->bindValue(":cuepoint", track.getCuePoint()); + pTrackLibraryQuery->bindValue(":cuepoint", track.getCuePoint().getPosition()); pTrackLibraryQuery->bindValue(":bpm_lock", track.isBpmLocked()? 1 : 0); pTrackLibraryQuery->bindValue(":replaygain", track.getReplayGain().getRatio()); pTrackLibraryQuery->bindValue(":replaygain_peak", track.getReplayGain().getPeak()); @@ -1031,7 +1031,7 @@ bool setTrackSampleRate(const QSqlRecord& record, const int column, bool setTrackCuePoint(const QSqlRecord& record, const int column, TrackPointer pTrack) { - pTrack->setCuePoint(record.value(column).toDouble(), Cue::MANUAL); + pTrack->setCuePoint(CuePosition(record.value(column).toDouble(), Cue::MANUAL)); return false; } diff --git a/src/library/dlgtrackinfo.cpp b/src/library/dlgtrackinfo.cpp index f30f1b9bb1..0ee672f7a9 100644 --- a/src/library/dlgtrackinfo.cpp +++ b/src/library/dlgtrackinfo.cpp @@ -526,9 +526,9 @@ void DlgTrackInfo::slotBpmConstChanged(int state) { // almost all cases. // The cue point should be set on a beat, so this seams // to be a good alternative - double cue = m_pLoadedTrack->getCuePoint(); + CuePosition cue = m_pLoadedTrack->getCuePoint(); m_pBeatsClone = BeatFactory::makeBeatGrid( - *m_pLoadedTrack, spinBpm->value(), cue); + *m_pLoadedTrack, spinBpm->value(), cue.getPosition()); } else { m_pBeatsClone.clear(); } @@ -560,9 +560,9 @@ void DlgTrackInfo::slotSpinBpmValueChanged(double value) { } if (!m_pBeatsClone) { - double cue = m_pLoadedTrack->getCuePoint(); + CuePosition cue = m_pLoadedTrack->getCuePoint(); m_pBeatsClone = BeatFactory::makeBeatGrid( - *m_pLoadedTrack, value, cue); + *m_pLoadedTrack, value, cue.getPosition()); } double oldValue = m_pBeatsClone->getBpm(); diff --git a/src/test/analyzersilence_test.cpp b/src/test/analyzersilence_test.cpp index 8e2eed7249..94c6640812 100644 --- a/src/test/analyzersilence_test.cpp +++ b/src/test/analyzersilence_test.cpp @@ -50,8 +50,9 @@ TEST_F(AnalyzerSilenceTest, SilenceTrack) { analyzeTrack(); - EXPECT_DOUBLE_EQ(0.0, pTrack->getCuePoint()); - EXPECT_EQ(Cue::UNKNOWN, pTrack->getCuePointSource()); + CuePosition cue = pTrack->getCuePoint(); + EXPECT_DOUBLE_EQ(0.0, cue.getPosition()); + EXPECT_EQ(Cue::UNKNOWN, cue.getSource()); CuePointer pBeginCue = pTrack->findCueByType(Cue::BEGIN); EXPECT_DOUBLE_EQ(0.0, pBeginCue->getPosition()); @@ -71,8 +72,9 @@ TEST_F(AnalyzerSilenceTest, EndToEndToneTrack) { analyzeTrack(); - EXPECT_DOUBLE_EQ(0.0, pTrack->getCuePoint()); - EXPECT_EQ(Cue::UNKNOWN, pTrack->getCuePointSource()); + CuePosition cue = pTrack->getCuePoint(); + EXPECT_DOUBLE_EQ(0.0, cue.getPosition()); + EXPECT_EQ(Cue::UNKNOWN, cue.getSource()); CuePointer pBeginCue = pTrack->findCueByType(Cue::BEGIN); EXPECT_DOUBLE_EQ(0.0, pBeginCue->getPosition()); @@ -102,8 +104,9 @@ TEST_F(AnalyzerSilenceTest, ToneTrackWithSilence) { analyzeTrack(); - EXPECT_DOUBLE_EQ(nTrackSampleDataLength / 4, pTrack->getCuePoint()); - EXPECT_EQ(Cue::AUTOMATIC, pTrack->getCuePointSource()); + CuePosition cue = pTrack->getCuePoint(); + EXPECT_DOUBLE_EQ(nTrackSampleDataLength / 4, cue.getPosition()); + EXPECT_EQ(Cue::AUTOMATIC, cue.getSource()); CuePointer pBeginCue = pTrack->findCueByType(Cue::BEGIN); EXPECT_DOUBLE_EQ(nTrackSampleDataLength / 4, pBeginCue->getPosition()); @@ -145,8 +148,9 @@ TEST_F(AnalyzerSilenceTest, ToneTrackWithSilenceInTheMiddle) { analyzeTrack(); - EXPECT_DOUBLE_EQ(oneFifthOfTrackLength, pTrack->getCuePoint()); - EXPECT_EQ(Cue::AUTOMATIC, pTrack->getCuePointSource()); + CuePosition cue = pTrack->getCuePoint(); + EXPECT_DOUBLE_EQ(oneFifthOfTrackLength, cue.getPosition()); + EXPECT_EQ(Cue::AUTOMATIC, cue.getSource()); CuePointer pBeginCue = pTrack->findCueByType(Cue::BEGIN); EXPECT_DOUBLE_EQ(oneFifthOfTrackLength, pBeginCue->getPosition()); @@ -160,7 +164,7 @@ TEST_F(AnalyzerSilenceTest, ToneTrackWithSilenceInTheMiddle) { TEST_F(AnalyzerSilenceTest, UpdateNonUserAdjustedCues) { int halfTrackLength = nTrackSampleDataLength / 2; - pTrack->setCuePoint(100, Cue::AUTOMATIC); // Arbitrary value + pTrack->setCuePoint(CuePosition(100, Cue::AUTOMATIC)); // Arbitrary value CuePointer pBeginCue = pTrack->createAndAddCue(); pBeginCue->setType(Cue::BEGIN); @@ -185,8 +189,9 @@ TEST_F(AnalyzerSilenceTest, UpdateNonUserAdjustedCues) { analyzeTrack(); - EXPECT_DOUBLE_EQ(halfTrackLength, pTrack->getCuePoint()); - EXPECT_EQ(Cue::AUTOMATIC, pTrack->getCuePointSource()); + CuePosition cue = pTrack->getCuePoint(); + EXPECT_DOUBLE_EQ(halfTrackLength, cue.getPosition()); + EXPECT_EQ(Cue::AUTOMATIC, cue.getSource()); EXPECT_DOUBLE_EQ(halfTrackLength, pBeginCue->getPosition()); EXPECT_EQ(Cue::AUTOMATIC, pBeginCue->getSource()); @@ -201,7 +206,7 @@ TEST_F(AnalyzerSilenceTest, RespectUserEdits) { const double kManualStartPosition = 0.1 * nTrackSampleDataLength; const double kManualEndPosition = 0.9 * nTrackSampleDataLength; - pTrack->setCuePoint(kManualCuePosition, Cue::MANUAL); + pTrack->setCuePoint(CuePosition(kManualCuePosition, Cue::MANUAL)); CuePointer pBeginCue = pTrack->createAndAddCue(); pBeginCue->setType(Cue::BEGIN); @@ -226,8 +231,9 @@ TEST_F(AnalyzerSilenceTest, RespectUserEdits) { analyzeTrack(); - EXPECT_DOUBLE_EQ(kManualCuePosition, pTrack->getCuePoint()); - EXPECT_EQ(Cue::MANUAL, pTrack->getCuePointSource()); + CuePosition cue = pTrack->getCuePoint(); + EXPECT_DOUBLE_EQ(kManualCuePosition, cue.getPosition()); + EXPECT_EQ(Cue::MANUAL, cue.getSource()); EXPECT_DOUBLE_EQ(kManualStartPosition, pBeginCue->getPosition()); EXPECT_EQ(Cue::MANUAL, pBeginCue->getSource()); 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) |