Skip to content

Commit

Permalink
Color Palette: Added getNthColor method
Browse files Browse the repository at this point in the history
  • Loading branch information
aqw42 committed Jun 6, 2024
1 parent b9a1f47 commit c986761
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
11 changes: 1 addition & 10 deletions src/mixer/basetrackplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,16 +827,7 @@ void BaseTrackPlayerImpl::slotTrackColorSelector(int steps) {
ColorPalette colorPalette = colorPaletteSettings.getTrackColorPalette();
mixxx::RgbColor::optional_t color = m_pLoadedTrack->getColor();

while (steps != 0) {
if (steps > 0) {
color = colorPalette.nextColor(color);
steps--;
} else {
color = colorPalette.previousColor(color);
steps++;
}
}
m_pLoadedTrack->setColor(color);
m_pLoadedTrack->setColor(colorPalette.getNthColor(color, steps));
}

void BaseTrackPlayerImpl::slotTrackColorChangeRequest(double v) {
Expand Down
14 changes: 14 additions & 0 deletions src/util/color/colorpalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ mixxx::RgbColor::optional_t ColorPalette::previousColor(mixxx::RgbColor::optiona
return at(size() - 1);
}

mixxx::RgbColor::optional_t ColorPalette::getNthColor(
mixxx::RgbColor::optional_t color, int steps) const {
while (steps) {
if (steps > 0) {
color = nextColor(color);
steps--;
} else {
color = previousColor(color);
steps++;
}
}
return color;
}

mixxx::RgbColor ColorPalette::colorForHotcueIndex(unsigned int hotcueIndex) const {
int colorIndex;
if (m_colorIndicesByHotcue.isEmpty()) {
Expand Down
1 change: 1 addition & 0 deletions src/util/color/colorpalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ColorPalette final {
mixxx::RgbColor::optional_t nextColor(mixxx::RgbColor::optional_t color) const;
mixxx::RgbColor previousColor(mixxx::RgbColor color) const;
mixxx::RgbColor::optional_t previousColor(mixxx::RgbColor::optional_t color) const;
mixxx::RgbColor::optional_t getNthColor(mixxx::RgbColor::optional_t color, int steps) const;
mixxx::RgbColor colorForHotcueIndex(unsigned int index) const;

QList<mixxx::RgbColor>::const_iterator begin() const {
Expand Down
23 changes: 8 additions & 15 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,22 +431,15 @@ void WTrackTableView::selectTrackColor(int steps) {

QModelIndex index = indices.at(0);
TrackPointer pTrack = trackModel->getTrack(index);
if (pTrack) {
ColorPaletteSettings colorPaletteSettings(m_pConfig);
ColorPalette colorPalette = colorPaletteSettings.getTrackColorPalette();
mixxx::RgbColor::optional_t color = pTrack->getColor();

while (steps != 0) {
if (steps > 0) {
color = colorPalette.nextColor(color);
steps--;
} else {
color = colorPalette.previousColor(color);
steps++;
}
}
pTrack->setColor(color);
if (!pTrack) {
return;
}

ColorPaletteSettings colorPaletteSettings(m_pConfig);
ColorPalette colorPalette = colorPaletteSettings.getTrackColorPalette();
mixxx::RgbColor::optional_t color = pTrack->getColor();

pTrack->setColor(colorPalette.getNthColor(color, steps));
}

void WTrackTableView::slotPurge() {
Expand Down

0 comments on commit c986761

Please sign in to comment.