Skip to content

Commit

Permalink
Merge pull request #2543 from ehendrikd/rekordbox-memory-cues
Browse files Browse the repository at this point in the history
Store remaining Rekordbox memory cues as hotcues
  • Loading branch information
uklotzde authored Mar 13, 2020
2 parents f93f41b + a45194b commit 8f67272
Showing 1 changed file with 52 additions and 21 deletions.
73 changes: 52 additions & 21 deletions src/library/rekordbox/rekordboxfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -803,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):
Expand Down Expand Up @@ -871,8 +877,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<memory_cue_t> memoryCues;
int lastHotCueIndex = 0;
double cueLoopStartPosition = kLongestPosition;
double cueLoopEndPosition = kLongestPosition;

Expand Down Expand Up @@ -922,10 +928,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
Expand All @@ -942,7 +951,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<int>((*cueEntry)->hot_cue() - 1), QString(), -1, -1, -1, -1);
int hotCueIndex = static_cast<int>((*cueEntry)->hot_cue() - 1);
if (hotCueIndex > lastHotCueIndex) {
lastHotCueIndex = hotCueIndex;
}
setHotCue(track, position, hotCueIndex, QString(), -1, -1, -1, -1);
} break;
}
}
Expand All @@ -962,11 +975,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<int>((*cueExtendedEntry)->color_code());
memoryCue.colorRed = static_cast<int>((*cueExtendedEntry)->color_red());
memoryCue.colorGreen = static_cast<int>((*cueExtendedEntry)->color_green());
memoryCue.colorBlue = static_cast<int>((*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
Expand All @@ -983,7 +999,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<int>((*cueExtendedEntry)->hot_cue() - 1), toUnicode((*cueExtendedEntry)->comment()), static_cast<int>((*cueExtendedEntry)->color_code()), static_cast<int>((*cueExtendedEntry)->color_red()), static_cast<int>((*cueExtendedEntry)->color_green()), static_cast<int>((*cueExtendedEntry)->color_blue()));
int hotCueIndex = static_cast<int>((*cueExtendedEntry)->hot_cue() - 1);
if (hotCueIndex > lastHotCueIndex) {
lastHotCueIndex = hotCueIndex;
}
setHotCue(track, position, hotCueIndex, toUnicode((*cueExtendedEntry)->comment()), static_cast<int>((*cueExtendedEntry)->color_code()), static_cast<int>((*cueExtendedEntry)->color_red()), static_cast<int>((*cueExtendedEntry)->color_green()), static_cast<int>((*cueExtendedEntry)->color_blue()));
} break;
}
}
Expand All @@ -993,13 +1013,24 @@ void readAnalyze(TrackPointer track, double sampleRate, int timingOffset, bool i
}
}

if (cueLoadPosition < kLongestPosition) {
track->setCuePoint(CuePosition(cueLoadPosition));
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));
CuePointer pLoadCue = track->findCueByType(mixxx::CueType::MainCue);
if (!cueLoadComment.isNull()) {
pLoadCue->setLabel(cueLoadComment);
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);
Expand Down

0 comments on commit 8f67272

Please sign in to comment.