Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library controls color selector #13077

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions src/controllers/controlpickermenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,11 @@ ControlPickerMenu::ControlPickerMenu(QWidget* pParent)
tr("Select the previous color in the color palette"
" for the first selected track"),
pLibraryMenu);
addLibraryControl("track_color_selector",
tr("Navigate Through Track Colors"),
tr("Select either next or previous color in the"
" palette for the first selected track."),
pLibraryMenu);

pLibraryMenu->addSeparator();
addControl("[Recording]",
Expand Down
38 changes: 24 additions & 14 deletions src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,31 @@ LibraryControl::LibraryControl(Library* pLibrary)
// Track Color controls
m_pTrackColorPrev = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "track_color_prev"));
m_pTrackColorNext = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "track_color_next"));
m_pTrackColorSelector = std::make_unique<ControlEncoder>(
ConfigKey("[Library]", "track_color_selector"), false);
connect(m_pTrackColorPrev.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotTrackColorPrev);
[this](double value) {
if (value > 0) {
LibraryControl::slotTrackColorSelector(-1);
}
aqw42 marked this conversation as resolved.
Show resolved Hide resolved
});
connect(m_pTrackColorNext.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotTrackColorNext);
[this](double value) {
if (value > 0) {
LibraryControl::slotTrackColorSelector(1);
}
});
connect(m_pTrackColorSelector.get(),
&ControlEncoder::valueChanged,
this,
[this](double steps) {
int iSteps = static_cast<int>(steps);
LibraryControl::slotTrackColorSelector(iSteps);
});

// Controls to select saved searchbox queries and to clear the searchbox
m_pSelectHistoryNext = std::make_unique<ControlPushButton>(
Expand Down Expand Up @@ -1115,24 +1132,17 @@ void LibraryControl::slotDecrementFontSize(double v) {
}
}

void LibraryControl::slotTrackColorPrev(double v) {
if (!m_pLibraryWidget || v <= 0) {
void LibraryControl::slotTrackColorSelector(int steps) {
if (!m_pLibraryWidget || steps == 0) {
return;
}

WTrackTableView* pTrackTableView = m_pLibraryWidget->getCurrentTrackTableView();
if (pTrackTableView) {
pTrackTableView->assignPreviousTrackColor();
}
}

void LibraryControl::slotTrackColorNext(double v) {
if (!m_pLibraryWidget || v <= 0) {
if (!pTrackTableView) {
return;
}

WTrackTableView* pTrackTableView = m_pLibraryWidget->getCurrentTrackTableView();
if (pTrackTableView) {
pTrackTableView->assignNextTrackColor();
if (steps != 0) {
pTrackTableView->selectTrackColor(steps);
}
aqw42 marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 2 additions & 2 deletions src/library/librarycontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ class LibraryControl : public QObject {
void slotMoveTrack(double);
void slotGoToItem(double v);

void slotTrackColorPrev(double v);
void slotTrackColorNext(double v);
void slotTrackColorSelector(int steps);

// Deprecated navigation slots
void slotSelectNextTrack(double v);
Expand Down Expand Up @@ -165,6 +164,7 @@ class LibraryControl : public QObject {
// Controls to change track color
std::unique_ptr<ControlPushButton> m_pTrackColorPrev;
std::unique_ptr<ControlPushButton> m_pTrackColorNext;
std::unique_ptr<ControlEncoder> m_pTrackColorSelector;

// Control to show/hide the track menu
std::unique_ptr<ControlPushButton> m_pShowTrackMenu;
Expand Down
5 changes: 2 additions & 3 deletions src/library/libraryview.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class LibraryView {
}
/// If applicable, requests that the LibraryView changes the track color of
/// the selected track. Does nothing otherwise.
virtual void assignPreviousTrackColor() {
}
virtual void assignNextTrackColor() {
virtual void selectTrackColor(int steps) {
Q_UNUSED(steps)
}
aqw42 marked this conversation as resolved.
Show resolved Hide resolved
};
11 changes: 1 addition & 10 deletions src/mixer/basetrackplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,16 +874,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
15 changes: 15 additions & 0 deletions src/util/color/colorpalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ 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 {
// TODO : Use rem_euclid modulo function instead of a loop
while (steps) {
Comment on lines +43 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should address this in this PR IMO. The repeated calls to nextColor/previousColor which in turn call indexOf are highly suboptimal (in terms of wasted computations).

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
24 changes: 2 additions & 22 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ TrackModel::SortColumnId WTrackTableView::getColumnIdFromCurrentIndex() {
return pTrackModel->sortColumnIdFromColumnIndex(currentIndex().column());
}

void WTrackTableView::assignPreviousTrackColor() {
void WTrackTableView::selectTrackColor(int steps) {
TrackModel* pTrackModel = getTrackModel();
if (!pTrackModel) {
return;
Expand All @@ -438,27 +438,7 @@ void WTrackTableView::assignPreviousTrackColor() {
ColorPaletteSettings colorPaletteSettings(m_pConfig);
ColorPalette colorPalette = colorPaletteSettings.getTrackColorPalette();
mixxx::RgbColor::optional_t color = pTrack->getColor();
pTrack->setColor(colorPalette.previousColor(color));
}
}

void WTrackTableView::assignNextTrackColor() {
TrackModel* pTrackModel = getTrackModel();
if (!pTrackModel) {
return;
}
const QModelIndexList indices = getSelectedRows();
if (indices.isEmpty()) {
return;
}

QModelIndex index = indices.at(0);
TrackPointer pTrack = pTrackModel->getTrack(index);
if (pTrack) {
ColorPaletteSettings colorPaletteSettings(m_pConfig);
ColorPalette colorPalette = colorPaletteSettings.getTrackColorPalette();
mixxx::RgbColor::optional_t color = pTrack->getColor();
pTrack->setColor(colorPalette.nextColor(color));
pTrack->setColor(colorPalette.getNthColor(color, steps));
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/widget/wtracktableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class WTrackTableView : public WLibraryTableView {
void resizeEvent(QResizeEvent* event) override;
void activateSelectedTrack();
void loadSelectedTrackToGroup(const QString& group, bool play);
void assignNextTrackColor() override;
void assignPreviousTrackColor() override;
void selectTrackColor(int) override;
aqw42 marked this conversation as resolved.
Show resolved Hide resolved
TrackModel::SortColumnId getColumnIdFromCurrentIndex() override;
QList<TrackId> getSelectedTrackIds() const;
bool isTrackInCurrentView(const TrackId& trackId);
Expand Down
Loading