Skip to content

Commit

Permalink
track/serato: Lay groundwork for taking timing offsets into account
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Feb 29, 2020
1 parent 45e7874 commit 7ed1cb3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/track/serato/markers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ QByteArray SeratoMarkers::dump() const {
return data;
}

QList<CueInfo> SeratoMarkers::getCues() const {
QList<CueInfo> SeratoMarkers::getCues(double timingOffsetMillis) const {
qDebug() << "Reading cues from 'Serato Markers_' tag data...";

QList<CueInfo> cueInfos;
Expand All @@ -276,7 +276,7 @@ QList<CueInfo> SeratoMarkers::getCues() const {
case SeratoMarkersEntry::TypeId::Cue: {
CueInfo cueInfo(
CueType::HotCue,
pEntry->getStartPosition(),
pEntry->getStartPosition() + timingOffsetMillis,
std::nullopt,
cueIndex,
"",
Expand Down
2 changes: 1 addition & 1 deletion src/track/serato/markers.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class SeratoMarkers final {
m_trackColor = color;
}

QList<CueInfo> getCues() const;
QList<CueInfo> getCues(double timingOffsetMillis) const;

private:
QList<SeratoMarkersEntryPointer> m_entries;
Expand Down
4 changes: 2 additions & 2 deletions src/track/serato/markers2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ QByteArray SeratoMarkers2::dump() const {
return outerData.leftJustified(size, '\0');
}

QList<CueInfo> SeratoMarkers2::getCues() const {
QList<CueInfo> SeratoMarkers2::getCues(double timingOffsetMillis) const {
qDebug() << "Reading cues from 'Serato Markers2' tag data...";
QList<CueInfo> cueInfos;
for (auto& pEntry : m_entries) {
Expand All @@ -436,7 +436,7 @@ QList<CueInfo> SeratoMarkers2::getCues() const {
const SeratoMarkers2CueEntry* pCueEntry = static_cast<SeratoMarkers2CueEntry*>(pEntry.get());
CueInfo cueInfo(
CueType::HotCue,
pCueEntry->getPosition(),
pCueEntry->getPosition() + timingOffsetMillis,
std::nullopt,
pCueEntry->getIndex(),
pCueEntry->getLabel(),
Expand Down
2 changes: 1 addition & 1 deletion src/track/serato/markers2.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class SeratoMarkers2 final {
m_entries = std::move(entries);
}

QList<CueInfo> getCues() const;
QList<CueInfo> getCues(double timingOffsetMillis) const;
RgbColor::optional_t getTrackColor() const;
bool isBpmLocked() const;

Expand Down
15 changes: 12 additions & 3 deletions src/track/serato/tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,23 @@ RgbColor SeratoTags::colorToStoredTrackColor(RgbColor::optional_t color) {
return RgbColor(value);
}

QList<CueInfo> SeratoTags::getCues() const {
double SeratoTags::findTimingOffsetMillis(const QString& filePath) {
// TODO: Find timing offset using mp3guessenc
Q_UNUSED(filePath);

return 0;
}

QList<CueInfo> SeratoTags::getCues(const QString& filePath) const {
// Import "Serato Markers2" first, then overwrite values with those
// from "Serato Markers_". This is what Serato does too (i.e. if
// "Serato Markers_" and "Serato Markers2" contradict each other,
// Serato will use the values from "Serato Markers_").

double timingOffsetMillis = SeratoTags::findTimingOffsetMillis(filePath);

QMap<int, CueInfo> cueMap;
for (const CueInfo& cueInfo : m_seratoMarkers2.getCues()) {
for (const CueInfo& cueInfo : m_seratoMarkers2.getCues(timingOffsetMillis)) {
DEBUG_ASSERT(cueInfo.getHotCueNumber());
int index = *cueInfo.getHotCueNumber();
DEBUG_ASSERT(index >= 0);
Expand All @@ -76,7 +85,7 @@ QList<CueInfo> SeratoTags::getCues() const {

// TODO: If a hotcue is set in SeratoMarkers2, but not in SeratoMarkers_,
// we could remove it from the output. We'll just leave it in for now.
for (const CueInfo& cueInfo : m_seratoMarkers.getCues()) {
for (const CueInfo& cueInfo : m_seratoMarkers.getCues(timingOffsetMillis)) {
DEBUG_ASSERT(cueInfo.getHotCueNumber());
int index = *cueInfo.getHotCueNumber();
DEBUG_ASSERT(index >= 0);
Expand Down
3 changes: 2 additions & 1 deletion src/track/serato/tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SeratoTags final {

static RgbColor colorToStoredTrackColor(RgbColor::optional_t color);
static RgbColor::optional_t colorFromStoredTrackColor(RgbColor color);
static double findTimingOffsetMillis(const QString& filePath);

bool isEmpty() const {
return m_seratoMarkers.isEmpty() && m_seratoMarkers2.isEmpty();
Expand All @@ -38,7 +39,7 @@ class SeratoTags final {
return m_seratoMarkers2.dump();
}

QList<CueInfo> getCues() const;
QList<CueInfo> getCues(const QString& filePath) const;

RgbColor::optional_t getTrackColor() const;
bool isBpmLocked() const;
Expand Down
2 changes: 1 addition & 1 deletion src/track/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void Track::importMetadata(
// FIXME: Move the Track::setCuePoints call to another location,
// because we need the sample rate to calculate sample
// positions for cues (and *correct* sample rate isn't known here).
setCuePoints(newSeratoTags.getCues());
setCuePoints(newSeratoTags.getCues(getLocation()));
setColor(newSeratoTags.getTrackColor());
setBpmLocked(newSeratoTags.isBpmLocked());
#endif // __EXTRA_METADATA__
Expand Down

0 comments on commit 7ed1cb3

Please sign in to comment.