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

Allow changing track colors from controller #2541

Merged
merged 8 commits into from
Apr 19, 2020
19 changes: 17 additions & 2 deletions res/controllers/Roland_DJ-505-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ DJ505.shutdown = function() {
DJ505.browseEncoder = new components.Encoder({
longPressTimer: 0,
longPressTimeout: 250,
trackColorCycleEnabled: false,
trackColorCycleHappened: false,
previewSeekEnabled: false,
previewSeekHappened: false,
unshift: function() {
Expand Down Expand Up @@ -249,12 +251,25 @@ DJ505.browseEncoder = new components.Encoder({
shift: function() {
this.onKnobEvent = function(rotateValue) {
if (rotateValue !== 0) {
engine.setValue("[Playlist]", "SelectPlaylist", rotateValue);
if (this.trackColorCycleEnabled) {
var key = (rotateValue > 0) ? "track_color_next" : "track_color_prev";
engine.setValue("[Library]", key, 1.0);
this.trackColorCycleHappened = true;
} else {
engine.setValue("[Playlist]", "SelectPlaylist", rotateValue);
}
}
};
this.onButtonEvent = function(value) {
if (value) {
script.triggerControl("[Playlist]", "ToggleSelectedSidebarItem");
this.trackColorCycleEnabled = true;
this.trackColorCycleHappened = false;
} else {
if (!this.trackColorCycleHappened) {
script.triggerControl("[Playlist]", "ToggleSelectedSidebarItem");
}
this.trackColorCycleEnabled = false;
this.trackColorCycleHappened = false;
}
};
},
Expand Down
44 changes: 42 additions & 2 deletions src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ LibraryControl::LibraryControl(Library* pLibrary)
this,
&LibraryControl::slotIncrementFontSize);

// 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"));
connect(m_pTrackColorPrev.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotTrackColorPrev);
connect(m_pTrackColorNext.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotTrackColorNext);

/// Deprecated controls
m_pSelectNextTrack = std::make_unique<ControlPushButton>(ConfigKey("[Playlist]", "SelectNextTrack"));
connect(m_pSelectNextTrack.get(),
Expand Down Expand Up @@ -563,8 +575,8 @@ void LibraryControl::slotGoToItem(double v) {
slotToggleSelectedSidebarItem(v);
}
}
// TODO(xxx) instead of remote control the widgets individual, we should
// translate this into Alt+Return and handle it at each library widget
// TODO(xxx) instead of remote control the widgets individual, we should
// translate this into Alt+Return and handle it at each library widget
// individual https://bugs.launchpad.net/mixxx/+bug/1758618
//emitKeyEvent(QKeyEvent{QEvent::KeyPress, Qt::Key_Return, Qt::AltModifier});
}
Expand Down Expand Up @@ -603,3 +615,31 @@ void LibraryControl::slotDecrementFontSize(double v) {
slotFontSize(-1);
}
}

void LibraryControl::slotTrackColorPrev(double v) {
if (!m_pLibraryWidget) {
return;
}

if (v > 0) {
LibraryView* activeView = m_pLibraryWidget->getActiveView();
if (!activeView) {
return;
}
activeView->assignPreviousTrackColor();
}
}

void LibraryControl::slotTrackColorNext(double v) {
if (!m_pLibraryWidget) {
return;
}

if (v > 0) {
LibraryView* activeView = m_pLibraryWidget->getActiveView();
if (!activeView) {
return;
}
activeView->assignNextTrackColor();
}
}
7 changes: 7 additions & 0 deletions src/library/librarycontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class LibraryControl : public QObject {
void slotMoveFocus(double);
void slotGoToItem(double v);

void slotTrackColorPrev(double v);
void slotTrackColorNext(double v);

// Deprecated navigation slots
void slotSelectNextTrack(double v);
void slotSelectPrevTrack(double v);
Expand Down Expand Up @@ -129,6 +132,10 @@ class LibraryControl : public QObject {
std::unique_ptr<ControlEncoder> m_pSortColumnToggle;
std::unique_ptr<ControlPushButton> m_pSortOrder;

// Controls to change track color
std::unique_ptr<ControlPushButton> m_pTrackColorPrev;
std::unique_ptr<ControlPushButton> m_pTrackColorNext;

// Font sizes
std::unique_ptr<ControlPushButton> m_pFontSizeIncrement;
std::unique_ptr<ControlPushButton> m_pFontSizeDecrement;
Expand Down
31 changes: 18 additions & 13 deletions src/library/libraryview.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// libraryview.h
// Created 8/28/2009 by RJ Ryan ([email protected])
//
// LibraryView is an abstract interface that all views to be used with the
// Library widget should support.
/// libraryview.h
/// Created 8/28/2009 by RJ Ryan ([email protected])
///
/// LibraryView is an abstract interface that all views to be used with the
/// Library widget should support.

#ifndef LIBRARYVIEW_H
#define LIBRARYVIEW_H
Expand All @@ -15,27 +15,32 @@ class LibraryView {

virtual void onShow() = 0;
virtual bool hasFocus() const = 0;
// reimplement if LibraryView should be able to search
/// Reimplement if LibraryView should be able to search
virtual void onSearch(const QString& text) {Q_UNUSED(text);}

// If applicable, requests that the LibraryView load the selected
// track. Does nothing otherwise.
/// If applicable, requests that the LibraryView load the selected
/// track. Does nothing otherwise.
virtual void loadSelectedTrack() {};

virtual void slotAddToAutoDJBottom() {};
virtual void slotAddToAutoDJTop() {};
virtual void slotAddToAutoDJReplace() {};

// If applicable, requests that the LibraryView load the selected track to
// the specified group. Does nothing otherwise.
/// If applicable, requests that the LibraryView load the selected track to
/// the specified group. Does nothing otherwise.
virtual void loadSelectedTrackToGroup(QString group, bool play) {
Q_UNUSED(group); Q_UNUSED(play);
}

// If a selection is applicable for this view, request that the selection be
// increased or decreased by the provided delta. For example, for a value of
// 1, the view should move to the next selection in the list.
/// If a selection is applicable for this view, request that the selection be
/// increased or decreased by the provided delta. For example, for a value of
/// 1, the view should move to the next selection in the list.
virtual void moveSelection(int delta) {Q_UNUSED(delta);}

/// If applicable, requests that the LibraryView changes the track color of
/// the selected track. Does nothing otherwise.
virtual void assignPreviousTrackColor(){};
virtual void assignNextTrackColor(){};
};

#endif /* LIBRARYVIEW_H */
22 changes: 22 additions & 0 deletions src/util/color/colorpalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ mixxx::RgbColor ColorPalette::nextColor(mixxx::RgbColor color) const {
return at((indexOf(color) + 1) % size());
}

mixxx::RgbColor::optional_t ColorPalette::nextColor(mixxx::RgbColor::optional_t color) const {
if (color) {
// If color is the last element in the palette, return no color
Be-ing marked this conversation as resolved.
Show resolved Hide resolved
if (indexOf(*color) == size() - 1) {
return std::nullopt;
}
return nextColor(*color);
}
return at(0);
}

mixxx::RgbColor ColorPalette::previousColor(mixxx::RgbColor color) const {
int iIndex = indexOf(color);
if (iIndex < 0) {
Expand All @@ -16,6 +27,17 @@ mixxx::RgbColor ColorPalette::previousColor(mixxx::RgbColor color) const {
return at(iIndex);
}

mixxx::RgbColor::optional_t ColorPalette::previousColor(mixxx::RgbColor::optional_t color) const {
if (color) {
// If color is the first element in the palette, return no color
if (indexOf(*color) == 0) {
return std::nullopt;
}
return previousColor(*color);
}
return at(size() - 1);
}

mixxx::RgbColor ColorPalette::colorForHotcueIndex(unsigned int hotcueIndex) const {
int colorIndex;
if (m_colorIndicesByHotcue.isEmpty()) {
Expand Down
2 changes: 2 additions & 0 deletions src/util/color/colorpalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class ColorPalette final {
}

mixxx::RgbColor nextColor(mixxx::RgbColor color) const;
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 colorForHotcueIndex(unsigned int index) const;

QList<mixxx::RgbColor>::const_iterator begin() const {
Expand Down
Loading