From ae4118d78dfb4eddfb4492a55953c20a8ee6bab7 Mon Sep 17 00:00:00 2001 From: Evan Dekker Date: Wed, 11 Mar 2020 10:50:57 +1100 Subject: [PATCH 1/3] Store remaining memory cues as hotcues --- src/library/rekordbox/rekordboxfeature.cpp | 70 ++++++++++++++++------ 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/src/library/rekordbox/rekordboxfeature.cpp b/src/library/rekordbox/rekordboxfeature.cpp index 1a1e28f9dbc..1235b8c99f6 100644 --- a/src/library/rekordbox/rekordboxfeature.cpp +++ b/src/library/rekordbox/rekordboxfeature.cpp @@ -68,6 +68,15 @@ constexpr mixxx::RgbColor kTrackColorAqua(0x16C0F8); constexpr mixxx::RgbColor kTrackColorBlue(0x0150F8); constexpr mixxx::RgbColor kTrackColorPurple(0x9808F8); +struct memory_cue_t { + double position; + QString comment; + int colorCode; + int colorRed; + int colorGreen; + int colorBlue; +}; + bool createLibraryTable(QSqlDatabase& database, const QString& tableName) { qDebug() << "Creating Rekordbox library table: " << tableName; @@ -871,8 +880,8 @@ void readAnalyze(TrackPointer track, double sampleRate, int timingOffset, bool i double sampleRateKhz = sampleRate / 1000.0; double samples = sampleRateKhz * mixxx::kEngineChannelCount; - double cueLoadPosition = kLongestPosition; - QString cueLoadComment; + QList memoryCues; + int lastHotCueIndex = 0; double cueLoopStartPosition = kLongestPosition; double cueLoopEndPosition = kLongestPosition; @@ -922,10 +931,13 @@ void readAnalyze(TrackPointer track, double sampleRate, int timingOffset, bool i case rekordbox_anlz_t::CUE_LIST_TYPE_MEMORY_CUES: { switch ((*cueEntry)->type()) { case rekordbox_anlz_t::CUE_ENTRY_TYPE_MEMORY_CUE: { - // As Mixxx can only have 1 saved cue point, use the first occurance of a memory cue relative to the start of the track - if (position < cueLoadPosition) { - cueLoadPosition = position; - } + memory_cue_t memoryCue; + memoryCue.position = position; + memoryCue.colorCode = -1; + memoryCue.colorRed = -1; + memoryCue.colorGreen = -1; + memoryCue.colorBlue = -1; + memoryCues << memoryCue; } break; case rekordbox_anlz_t::CUE_ENTRY_TYPE_LOOP: { // As Mixxx can only have 1 saved loop, use the first occurance of a memory loop relative to the start of the track @@ -942,7 +954,11 @@ void readAnalyze(TrackPointer track, double sampleRate, int timingOffset, bool i } } break; case rekordbox_anlz_t::CUE_LIST_TYPE_HOT_CUES: { - setHotCue(track, position, static_cast((*cueEntry)->hot_cue() - 1), QString(), -1, -1, -1, -1); + int hotCueIndex = static_cast((*cueEntry)->hot_cue() - 1); + if (hotCueIndex > lastHotCueIndex) { + lastHotCueIndex = hotCueIndex; + } + setHotCue(track, position, hotCueIndex, QString(), -1, -1, -1, -1); } break; } } @@ -962,11 +978,14 @@ void readAnalyze(TrackPointer track, double sampleRate, int timingOffset, bool i case rekordbox_anlz_t::CUE_LIST_TYPE_MEMORY_CUES: { switch ((*cueExtendedEntry)->type()) { case rekordbox_anlz_t::CUE_ENTRY_TYPE_MEMORY_CUE: { - // As Mixxx can only have 1 saved cue point, use the first occurance of a memory cue relative to the start of the track - if (position < cueLoadPosition) { - cueLoadPosition = position; - cueLoadComment = toUnicode((*cueExtendedEntry)->comment()); - } + memory_cue_t memoryCue; + memoryCue.position = position; + memoryCue.comment = toUnicode((*cueExtendedEntry)->comment()); + memoryCue.colorCode = static_cast((*cueExtendedEntry)->color_code()); + memoryCue.colorRed = static_cast((*cueExtendedEntry)->color_red()); + memoryCue.colorGreen = static_cast((*cueExtendedEntry)->color_green()); + memoryCue.colorBlue = static_cast((*cueExtendedEntry)->color_blue()); + memoryCues << memoryCue; } break; case rekordbox_anlz_t::CUE_ENTRY_TYPE_LOOP: { // As Mixxx can only have 1 saved loop, use the first occurance of a memory loop relative to the start of the track @@ -983,7 +1002,11 @@ void readAnalyze(TrackPointer track, double sampleRate, int timingOffset, bool i } } break; case rekordbox_anlz_t::CUE_LIST_TYPE_HOT_CUES: { - setHotCue(track, position, static_cast((*cueExtendedEntry)->hot_cue() - 1), toUnicode((*cueExtendedEntry)->comment()), static_cast((*cueExtendedEntry)->color_code()), static_cast((*cueExtendedEntry)->color_red()), static_cast((*cueExtendedEntry)->color_green()), static_cast((*cueExtendedEntry)->color_blue())); + int hotCueIndex = static_cast((*cueExtendedEntry)->hot_cue() - 1); + if (hotCueIndex > lastHotCueIndex) { + lastHotCueIndex = hotCueIndex; + } + setHotCue(track, position, hotCueIndex, toUnicode((*cueExtendedEntry)->comment()), static_cast((*cueExtendedEntry)->color_code()), static_cast((*cueExtendedEntry)->color_red()), static_cast((*cueExtendedEntry)->color_green()), static_cast((*cueExtendedEntry)->color_blue())); } break; } } @@ -993,13 +1016,26 @@ void readAnalyze(TrackPointer track, double sampleRate, int timingOffset, bool i } } - if (cueLoadPosition < kLongestPosition) { - track->setCuePoint(CuePosition(cueLoadPosition)); + std::sort(memoryCues.begin(), memoryCues.end(), [](const memory_cue_t& a, const memory_cue_t& b) -> bool { + return a.position < b.position; + }); + + if (memoryCues.size() > 0) { + // Set first chronological memory cue as Mixxx MainCue + memory_cue_t firstCue = memoryCues[0]; + track->setCuePoint(CuePosition(firstCue.position)); CuePointer pLoadCue = track->findCueByType(mixxx::CueType::MainCue); - if (!cueLoadComment.isNull()) { - pLoadCue->setLabel(cueLoadComment); + if (!firstCue.comment.isNull()) { + pLoadCue->setLabel(firstCue.comment); + } + + // Add remaining memory cues as hot cues (after actual found hotcues) as Mixxx can only have 1 cue + for (int memoryCueIndex = 1; memoryCueIndex < memoryCues.size(); memoryCueIndex++) { + memory_cue_t memoryCue = memoryCues[memoryCueIndex]; + setHotCue(track, memoryCue.position, lastHotCueIndex + memoryCueIndex, memoryCue.comment, memoryCue.colorCode, memoryCue.colorRed, memoryCue.colorGreen, memoryCue.colorBlue); } } + if (cueLoopStartPosition < kLongestPosition) { CuePointer pCue(track->createAndAddCue()); pCue->setStartPosition(cueLoopStartPosition); From 90edfc668dbefa3dfa3339f6580554d6b4128dfc Mon Sep 17 00:00:00 2001 From: Evan Dekker Date: Fri, 13 Mar 2020 09:36:39 +1100 Subject: [PATCH 2/3] Remove cue label null checks --- src/library/rekordbox/rekordboxfeature.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/library/rekordbox/rekordboxfeature.cpp b/src/library/rekordbox/rekordboxfeature.cpp index 1235b8c99f6..b558f2a20a7 100644 --- a/src/library/rekordbox/rekordboxfeature.cpp +++ b/src/library/rekordbox/rekordboxfeature.cpp @@ -812,10 +812,7 @@ void setHotCue(TrackPointer track, double position, int id, QString label, int / pCue->setType(mixxx::CueType::HotCue); pCue->setStartPosition(position); pCue->setHotCue(id); - - if (!label.isNull()) { - pCue->setLabel(label); - } + pCue->setLabel(label); /* TODO(ehendrikd): @@ -1025,9 +1022,7 @@ void readAnalyze(TrackPointer track, double sampleRate, int timingOffset, bool i memory_cue_t firstCue = memoryCues[0]; track->setCuePoint(CuePosition(firstCue.position)); CuePointer pLoadCue = track->findCueByType(mixxx::CueType::MainCue); - if (!firstCue.comment.isNull()) { - pLoadCue->setLabel(firstCue.comment); - } + pLoadCue->setLabel(firstCue.comment); // Add remaining memory cues as hot cues (after actual found hotcues) as Mixxx can only have 1 cue for (int memoryCueIndex = 1; memoryCueIndex < memoryCues.size(); memoryCueIndex++) { From a45194b31603e0b842906d4017529afbf11f2052 Mon Sep 17 00:00:00 2001 From: Evan Dekker Date: Fri, 13 Mar 2020 12:34:12 +1100 Subject: [PATCH 3/3] Move memory cue sorting --- src/library/rekordbox/rekordboxfeature.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/library/rekordbox/rekordboxfeature.cpp b/src/library/rekordbox/rekordboxfeature.cpp index b558f2a20a7..a2da47e3a8f 100644 --- a/src/library/rekordbox/rekordboxfeature.cpp +++ b/src/library/rekordbox/rekordboxfeature.cpp @@ -1013,11 +1013,11 @@ void readAnalyze(TrackPointer track, double sampleRate, int timingOffset, bool i } } - std::sort(memoryCues.begin(), memoryCues.end(), [](const memory_cue_t& a, const memory_cue_t& b) -> bool { - return a.position < b.position; - }); - if (memoryCues.size() > 0) { + std::sort(memoryCues.begin(), memoryCues.end(), [](const memory_cue_t& a, const memory_cue_t& b) -> bool { + return a.position < b.position; + }); + // Set first chronological memory cue as Mixxx MainCue memory_cue_t firstCue = memoryCues[0]; track->setCuePoint(CuePosition(firstCue.position));