summaryrefslogtreecommitdiffstats
path: root/src/track
diff options
context:
space:
mode:
authorFerran Pujol Camins <ferranpujolcamins@gmail.com>2019-11-11 13:19:43 +0100
committerFerran Pujol Camins <ferranpujolcamins@gmail.com>2019-11-11 13:19:43 +0100
commita16a2905296c938803196bdf729ab090587f0663 (patch)
tree82f4dcb737744d20ace4d86ac5dd906324b60a4c /src/track
parent03b4f06557d6c25301af69cb96b033b1b825a15d (diff)
parentb23d56e2df37db12fb7860306bd878b2a968f118 (diff)
Merge branch 'master' into new_colors_impl
Diffstat (limited to 'src/track')
-rw-r--r--src/track/cue.cpp76
-rw-r--r--src/track/cue.h71
-rw-r--r--src/track/track.cpp22
-rw-r--r--src/track/track.h4
4 files changed, 71 insertions, 102 deletions
diff --git a/src/track/cue.cpp b/src/track/cue.cpp
index 828c0958ab..2c34957a2f 100644
--- a/src/track/cue.cpp
+++ b/src/track/cue.cpp
@@ -23,10 +23,9 @@ Cue::Cue(TrackId trackId)
: m_bDirty(false),
m_iId(-1),
m_trackId(trackId),
- m_source(UNKNOWN),
- m_type(INVALID),
- m_samplePosition(-1.0),
- m_length(0.0),
+ m_type(Cue::Type::Invalid),
+ m_sampleStartPosition(Cue::kNoPosition),
+ m_sampleEndPosition(Cue::kNoPosition),
m_iHotCue(-1),
m_label(kDefaultLabel),
m_color(QColor()) {
@@ -35,8 +34,7 @@ Cue::Cue(TrackId trackId)
Cue::Cue(int id,
TrackId trackId,
- Cue::CueSource source,
- Cue::CueType type,
+ Cue::Type type,
double position,
double length,
int hotCue,
@@ -45,16 +43,22 @@ Cue::Cue(int id,
: m_bDirty(false),
m_iId(id),
m_trackId(trackId),
- m_source(source),
m_type(type),
- m_samplePosition(position),
- m_length(length),
+ m_sampleStartPosition(position),
m_iHotCue(hotCue),
m_label(label),
m_color(color) {
DEBUG_ASSERT(!m_label.isNull());
+ if (length) {
+ if (position != Cue::kNoPosition) {
+ m_sampleEndPosition = position + length;
+ } else {
+ m_sampleEndPosition = length;
+ }
+ } else {
+ m_sampleEndPosition = Cue::kNoPosition;
+ }
}
-
int Cue::getId() const {
QMutexLocker lock(&m_mutex);
return m_iId;
@@ -81,40 +85,35 @@ void Cue::setTrackId(TrackId trackId) {
emit(updated());
}
-Cue::CueSource Cue::getSource() const {
+Cue::Type Cue::getType() const {
QMutexLocker lock(&m_mutex);
- return m_source;
+ return m_type;
}
-void Cue::setSource(CueSource source) {
+void Cue::setType(Cue::Type type) {
QMutexLocker lock(&m_mutex);
- m_source = source;
+ m_type = type;
m_bDirty = true;
lock.unlock();
emit(updated());
}
-Cue::CueType Cue::getType() const {
+double Cue::getPosition() const {
QMutexLocker lock(&m_mutex);
- return m_type;
+ return m_sampleStartPosition;
}
-void Cue::setType(Cue::CueType type) {
+void Cue::setStartPosition(double samplePosition) {
QMutexLocker lock(&m_mutex);
- m_type = type;
+ m_sampleStartPosition = samplePosition;
m_bDirty = true;
lock.unlock();
emit(updated());
}
-double Cue::getPosition() const {
- QMutexLocker lock(&m_mutex);
- return m_samplePosition;
-}
-
-void Cue::setPosition(double samplePosition) {
+void Cue::setEndPosition(double samplePosition) {
QMutexLocker lock(&m_mutex);
- m_samplePosition = samplePosition;
+ m_sampleEndPosition = samplePosition;
m_bDirty = true;
lock.unlock();
emit(updated());
@@ -122,15 +121,13 @@ void Cue::setPosition(double samplePosition) {
double Cue::getLength() const {
QMutexLocker lock(&m_mutex);
- return m_length;
-}
-
-void Cue::setLength(double length) {
- QMutexLocker lock(&m_mutex);
- m_length = length;
- m_bDirty = true;
- lock.unlock();
- emit(updated());
+ if (m_sampleEndPosition == Cue::kNoPosition) {
+ return 0;
+ }
+ if (m_sampleStartPosition == Cue::kNoPosition) {
+ return m_sampleEndPosition;
+ }
+ return m_sampleEndPosition - m_sampleStartPosition;
}
int Cue::getHotCue() const {
@@ -187,16 +184,9 @@ void Cue::setDirty(bool dirty) {
double Cue::getEndPosition() const {
QMutexLocker lock(&m_mutex);
- if (m_samplePosition == -1.0) {
- return m_length;
- } else if (m_length == 0.0) {
- return -1.0;
- } else {
- return m_samplePosition + m_length;
- }
+ return m_sampleEndPosition;
}
bool operator==(const CuePosition& lhs, const CuePosition& rhs) {
- return lhs.getPosition() == rhs.getPosition() &&
- lhs.getSource() == rhs.getSource();
+ return lhs.getPosition() == rhs.getPosition();
}
diff --git a/src/track/cue.h b/src/track/cue.h
index 8ea3891de9..9b6d133766 100644
--- a/src/track/cue.h
+++ b/src/track/cue.h
@@ -16,24 +16,21 @@ class Cue : public QObject {
Q_OBJECT
public:
- enum CueSource {
- UNKNOWN = 0,
- AUTOMATIC = 1,
- MANUAL = 2,
+ enum class Type {
+ Invalid = 0,
+ HotCue = 1,
+ MainCue = 2,
+ Beat = 3, // unused (what is this for?)
+ Loop = 4,
+ Jump = 5,
+ Intro = 6,
+ Outro = 7,
+ AudibleSound = 8, // range that covers beginning and end of audible sound;
+ // not shown to user
};
- enum CueType {
- INVALID = 0,
- CUE = 1, // hot cue
- LOAD = 2, // the cue
- BEAT = 3,
- LOOP = 4,
- JUMP = 5,
- INTRO = 6,
- OUTRO = 7,
- };
-
- static constexpr double kPositionNotDefined = -1.0;
+ static constexpr double kNoPosition = -1.0;
+ static const int kNoHotCue = -1;
~Cue() override = default;
@@ -41,17 +38,14 @@ class Cue : public QObject {
int getId() const;
TrackId getTrackId() const;
- CueSource getSource() const;
- void setSource(CueSource source);
-
- CueType getType() const;
- void setType(CueType type);
+ Cue::Type getType() const;
+ void setType(Cue::Type type);
double getPosition() const;
- void setPosition(double samplePosition);
+ void setStartPosition(double samplePosition);
+ void setEndPosition(double samplePosition);
double getLength() const;
- void setLength(double length);
int getHotCue() const;
void setHotCue(int hotCue);
@@ -71,8 +65,7 @@ class Cue : public QObject {
explicit Cue(TrackId trackId);
Cue(int id,
TrackId trackId,
- CueSource source,
- CueType type,
+ Cue::Type type,
double position,
double length,
int hotCue,
@@ -87,10 +80,9 @@ class Cue : public QObject {
bool m_bDirty;
int m_iId;
TrackId m_trackId;
- CueSource m_source;
- CueType m_type;
- double m_samplePosition;
- double m_length;
+ Cue::Type m_type;
+ double m_sampleStartPosition;
+ double m_sampleEndPosition;
int m_iHotCue;
QString m_label;
QColor m_color;
@@ -113,9 +105,9 @@ 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) {}
+ : m_position(0.0) {}
+ CuePosition(double position)
+ : m_position(position) {}
double getPosition() const {
return m_position;
@@ -125,27 +117,16 @@ class CuePosition {
m_position = position;
}
- Cue::CueSource getSource() const {
- return m_source;
- }
-
- void setSource(Cue::CueSource source) {
- m_source = source;
- }
-
- void set(double position, Cue::CueSource source) {
+ void set(double position) {
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);
@@ -157,7 +138,7 @@ bool operator!=(const CuePosition& lhs, const CuePosition& rhs) {
inline
QDebug operator<<(QDebug dbg, const CuePosition& arg) {
- return dbg << "position =" << arg.getPosition() << "/" << "source =" << arg.getSource();
+ return dbg << "position =" << arg.getPosition();
}
#endif // MIXXX_CUE_H
diff --git a/src/track/track.cpp b/src/track/track.cpp
index 705d3df7e8..06e2e06dd1 100644
--- a/src/track/track.cpp
+++ b/src/track/track.cpp
@@ -653,21 +653,19 @@ void Track::setCuePoint(CuePosition cue) {
}
// Store the cue point in a load cue
- CuePointer pLoadCue = findCueByType(Cue::LOAD);
- Cue::CueSource source = cue.getSource();
+ CuePointer pLoadCue = findCueByType(Cue::Type::MainCue);
double position = cue.getPosition();
if (position != -1.0) {
if (!pLoadCue) {
pLoadCue = CuePointer(new Cue(m_record.getId()));
- pLoadCue->setType(Cue::LOAD);
+ pLoadCue->setType(Cue::Type::MainCue);
connect(pLoadCue.get(),
&Cue::updated,
this,
&Track::slotCueUpdated);
m_cuePoints.push_back(pLoadCue);
}
- pLoadCue->setPosition(position);
- pLoadCue->setSource(source);
+ pLoadCue->setStartPosition(position);
} else if (pLoadCue) {
disconnect(pLoadCue.get(), 0, this, 0);
m_cuePoints.removeOne(pLoadCue);
@@ -697,10 +695,10 @@ CuePointer Track::createAndAddCue() {
return pCue;
}
-CuePointer Track::findCueByType(Cue::CueType type) const {
+CuePointer Track::findCueByType(Cue::Type type) const {
// This method cannot be used for hotcues because there can be
// multiple hotcues and this function returns only a single CuePointer.
- DEBUG_ASSERT(type != Cue::CUE);
+ DEBUG_ASSERT(type != Cue::Type::HotCue);
QMutexLocker lock(&m_qMutex);
for (const CuePointer& pCue: m_cuePoints) {
if (pCue->getType() == type) {
@@ -718,20 +716,20 @@ void Track::removeCue(const CuePointer& pCue) {
QMutexLocker lock(&m_qMutex);
disconnect(pCue.get(), 0, this, 0);
m_cuePoints.removeOne(pCue);
- if (pCue->getType() == Cue::LOAD) {
+ if (pCue->getType() == Cue::Type::MainCue) {
m_record.setCuePoint(CuePosition());
}
markDirtyAndUnlock(&lock);
emit(cuesUpdated());
}
-void Track::removeCuesOfType(Cue::CueType type) {
+void Track::removeCuesOfType(Cue::Type type) {
QMutexLocker lock(&m_qMutex);
bool dirty = false;
QMutableListIterator<CuePointer> it(m_cuePoints);
while (it.hasNext()) {
CuePointer pCue = it.next();
- // FIXME: Why does this only work for the CUE CueType?
+ // FIXME: Why does this only work for the Hotcue Type?
if (pCue->getType() == type) {
disconnect(pCue.get(), 0, this, 0);
it.remove();
@@ -764,8 +762,8 @@ void Track::setCuePoints(const QList<CuePointer>& cuePoints) {
for (const auto& pCue: m_cuePoints) {
connect(pCue.get(), &Cue::updated, this, &Track::slotCueUpdated);
// update main cue point
- if (pCue->getType() == Cue::LOAD) {
- m_record.setCuePoint(CuePosition(pCue->getPosition(), pCue->getSource()));
+ if (pCue->getType() == Cue::Type::MainCue) {
+ m_record.setCuePoint(CuePosition(pCue->getPosition()));
}
}
markDirtyAndUnlock(&lock);
diff --git a/src/track/track.h b/src/track/track.h
index 2596a4599e..c3223003a8 100644
--- a/src/track/track.h
+++ b/src/track/track.h
@@ -244,9 +244,9 @@ class Track : public QObject {
// Calls for managing the track's cue points
CuePointer createAndAddCue();
- CuePointer findCueByType(Cue::CueType type) const; // NOTE: Cannot be used for hotcues.
+ CuePointer findCueByType(Cue::Type type) const; // NOTE: Cannot be used for hotcues.
void removeCue(const CuePointer& pCue);
- void removeCuesOfType(Cue::CueType);
+ void removeCuesOfType(Cue::Type);
QList<CuePointer> getCuePoints() const;
void setCuePoints(const QList<CuePointer>& cuePoints);