Skip to content

Commit

Permalink
track/serato/tags: Add conversion functions for Serato's track colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Feb 29, 2020
1 parent 41fa745 commit a247f99
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/track/serato/tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,64 @@

namespace mixxx {

RgbColor::optional_t SeratoTags::colorFromStoredTrackColor(RgbColor color) {
// Serato stores Track colors differently from how they are displayed in
// the library column. Instead of the color from the library view, the
// value from the color picker is stored instead (which is different).
// To make sure that the track looks the same in both Mixxx' and Serato's
// libraries, we need to convert between the two values.
//
// See this for details:
// https://github.com/Holzhaus/serato-tags/blob/master/docs/colors.md#track-colors

quint32 value = static_cast<quint32>(color);

if (color == 0xFFFFFF) {
return RgbColor::nullopt();
}

if (color == 0x999999) {
return RgbColor::optional(0x090909);
}

if (color == 0x000000) {
return RgbColor::optional(0x333333);
}

value = (value < 0x666666) ? value + 0x99999A : value - 0x666666;
return RgbColor::optional(value);
}

RgbColor SeratoTags::colorToStoredTrackColor(RgbColor::optional_t color) {
if (!color) {
return RgbColor(0xFFFFFF);
}

quint32 value = static_cast<quint32>(*color);

if (value == 0x090909) {
return RgbColor(0x999999);
}

if (value == 0x333333) {
return RgbColor(0x000000);
}

// Special case: 0x999999 and 0x99999a are not representable as Serato
// track color We'll just modify them a little, so that the look the
// same in Serato.
if (value == 0x999999) {
return RgbColor(0x999998);
}

if (value == 0x99999a) {
return RgbColor(0x99999b);
}

value = (value < 0x99999A) ? value + 0x666666 : value - 0x99999A;
return RgbColor(value);
}

RgbColor::optional_t SeratoTags::getTrackColor() const {
RgbColor::optional_t color = m_seratoMarkers.getTrackColor();

Expand All @@ -10,6 +68,10 @@ RgbColor::optional_t SeratoTags::getTrackColor() const {
color = m_seratoMarkers2.getTrackColor();
}

if (color) {
color = SeratoTags::colorFromStoredTrackColor(*color);
}

return color;
}

Expand Down
3 changes: 3 additions & 0 deletions src/track/serato/tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class SeratoTags final {

SeratoTags() = default;

static RgbColor colorToStoredTrackColor(RgbColor::optional_t color);
static RgbColor::optional_t colorFromStoredTrackColor(RgbColor color);

bool isEmpty() const {
return m_seratoMarkers.isEmpty() && m_seratoMarkers2.isEmpty();
}
Expand Down

0 comments on commit a247f99

Please sign in to comment.