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

Enable setting hotcue color via controlobject #2016

Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
93c0451
added color column to properties dlg but UI and DB dont update
Oct 2, 2018
e0d73a0
fixed functionality broken by previous commit.
Oct 4, 2018
29df355
woverview waveformsmarks will now reflect their hotcue color
Oct 6, 2018
68efc42
markproperties.m_textColor is now the same color as the mark itself; …
Oct 6, 2018
92d381d
followed daschauers request to VERIFY_OR_DEBUG_ASSERT in a case
Oct 13, 2018
d8057bd
followed uklotzde change requests in widget/woverview
Oct 13, 2018
d4e0735
fixed redundant blank line (codefactor complained)
Oct 14, 2018
2c253ff
fixed inverted VERIFY_OR_DEBUG Statement
Oct 14, 2018
f57e682
Added R/W ControlObject for the HotcueColor
Oct 14, 2018
b0270ba
contrastLineColor of Markers now adapt to MarkerColor Brightness
Oct 18, 2018
9833f67
Removed Comment in cuecontrol.cpp
Oct 19, 2018
d52f107
the marker number color is now set by the skin again, not the m_color
Oct 19, 2018
c8c4150
moved brightness function to color.h; rendermark textColor adapts now
Oct 19, 2018
e58b361
Color is now settable via ComboBox in trackpropertie cuepoints table.
Oct 20, 2018
2372bdf
added more utility functions to util/color.h
Oct 20, 2018
3088c1e
minor changes for performance and codefactor
Oct 21, 2018
20ff8dc
Let skins override cue colors
ferranpujolcamins Dec 2, 2018
1b460cf
Add example, revert before merge.
ferranpujolcamins Dec 3, 2018
ca30b3b
Improve color methods efficiency
ferranpujolcamins Dec 28, 2018
b194d21
Rename Color::defaultRepresentation() to makeDefaultRepresentation()
ferranpujolcamins Dec 28, 2018
54798f3
Let skins override cue colors on overview
ferranpujolcamins Dec 28, 2018
3b324f8
Append "Cue" to the skin node name for waveform cue color overrides
ferranpujolcamins Dec 28, 2018
b6a7dd2
Revert "Add example, revert before merge."
ferranpujolcamins Dec 28, 2018
9afc8d4
Fix WOverview cue colors not being mapped after skin reload
ferranpujolcamins Dec 29, 2018
19480bd
Convert color lists to static const vars
ferranpujolcamins Dec 30, 2018
f950c25
Reduce the number of runtime copies of ColorsRepresentation
ferranpujolcamins Dec 30, 2018
f951a94
Move setupCueColorsRepresentation() to SkinContext
ferranpujolcamins Dec 30, 2018
c49961f
Added JS utility object for dealing with hotcue colors from MixxxControl
Jan 1, 2019
5c84796
Merge branch 'master' into Enable-Setting-hotcue-color-via-controlobject
ferranpujolcamins Jan 25, 2019
9437cd6
Reduce number of colors
ferranpujolcamins Jan 27, 2019
181fbe9
Improve waveform marks visibility
ferranpujolcamins Jan 25, 2019
60e5a09
Refactor color.h
ferranpujolcamins Jan 30, 2019
e2caa1e
Represent cue colors by id instead of color code in CO and DB
ferranpujolcamins Jan 30, 2019
7308ba0
Rename invalid color to noColor
ferranpujolcamins Jan 30, 2019
4bc2549
Remove some cpp files
ferranpujolcamins Jan 30, 2019
84bb670
Improve code comments
ferranpujolcamins Jan 30, 2019
9e2deea
Merge branch 'master' into Enable-Setting-hotcue-color-via-controlobject
ferranpujolcamins Jan 31, 2019
7938f0d
Use skin provided DefaultMark color when a hotcue has noColor
ferranpujolcamins Jan 31, 2019
86337ab
Remove m_iBrightness field from PredefinedColor
ferranpujolcamins Jan 31, 2019
85a6605
Add missing include
ferranpujolcamins Jan 31, 2019
85bbcf9
Rename all the things
ferranpujolcamins Jan 31, 2019
a4b947f
Fix hotcue color CO
ferranpujolcamins Jan 31, 2019
36e3670
Remove predefinedColorNames list from PredefinedColorSet
ferranpujolcamins Jan 31, 2019
614183d
Rename PredefinedColorSet to PredefinedColorsSet
ferranpujolcamins Jan 31, 2019
bfca628
Add default cue color in PredefinedColorsMap
ferranpujolcamins Feb 1, 2019
dd29a4b
Improve code comments
ferranpujolcamins Feb 2, 2019
ce5bb15
Improve code comments
ferranpujolcamins Feb 2, 2019
4ed4d8f
Rename hotcue color CO to "hotcue_color_id"
ferranpujolcamins Feb 2, 2019
65b7219
Add const
ferranpujolcamins Feb 2, 2019
f1c84ea
Use normal for loop
ferranpujolcamins Feb 2, 2019
e1db34d
Don't show THE CUE in track preferences hotcue list
ferranpujolcamins Feb 2, 2019
551ea46
Merge branch 'master' into Enable-Setting-hotcue-color-via-controlobject
ferranpujolcamins Feb 6, 2019
df3a40c
Make Color::chooseContrastColor(QColor) work for dark colors, not onl…
ferranpujolcamins Feb 6, 2019
dcdfbf9
Rename PredefinedColorsMap to PredefinedColorsRepresentation
ferranpujolcamins Feb 6, 2019
3e10c98
Make selected color visible in track preferences cue list
ferranpujolcamins Feb 10, 2019
d3e5a5f
Correct size of cue color column in track preferences
ferranpujolcamins Feb 10, 2019
6f83fe7
Revert "Added JS utility object for dealing with hotcue colors from M…
ferranpujolcamins Feb 10, 2019
71ff4bc
Merge branch 'master' into Enable-Setting-hotcue-color-via-controlobject
Feb 11, 2019
4c47b3a
Add JS api for cue colors
Feb 12, 2019
b55604e
Add comment
Feb 13, 2019
a625424
Merge branch 'master' into Enable-Setting-hotcue-color-via-controlobject
Feb 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@ def sources(self, build):
"src/util/widgetrendertimer.cpp",
"src/util/workerthread.cpp",
"src/util/workerthreadscheduler.cpp",
"src/util/color/predefinedcolor.cpp"
]

proto_args = {
Expand Down
42 changes: 42 additions & 0 deletions res/controllers/common-controller-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,48 @@ bpm.tapButton = function(deck) {
// print("Script: BPM="+average+" setting to "+fRateScale);
}

// color - Basic Object used for convient interface with the hotcue_color ControlObjects
color = {
// member should be set directly but only in the [0;255] range.
red: 0,
green: 0,
blue: 0,
alpha: 255,
}


/* -------- ------------------------------------------------------
color.fromCO
Purpose: Setter that splits the combined colors into their components
and sets the color components in the object
Input: combined color value
Output: -
-------- ------------------------------------------------------ */

color.fromCO = function(color) {
ferranpujolcamins marked this conversation as resolved.
Show resolved Hide resolved
this.alpha = color >> 24 & 0xFF;
this.red = color >> 16 & 0xFF;
this.green = color >> 8 & 0xFF;
this.blue = color & 0xFF;
}
/* -------- ------------------------------------------------------
color.toCO
Purpose: Combines the colors back into a single value that
that could be used to set the MixxxControl value
Input: -
Output: struct containing the color components
-------- ------------------------------------------------------ */
color.toCO = function() {
ferranpujolcamins marked this conversation as resolved.
Show resolved Hide resolved
// javascript objects don't have "access control" and this object
// doesn't provide setters (interaction is supposed to be done via direct access)
// so this getter function sanitizes the values on export.
return (this.alpha % 255) << 24 +
(this.red % 255) << 16 +
(this.green % 255) << 8 +
this. blue % 255;
}


// ----------------- Common regular expressions --------------------------
script.samplerRegEx = /^\[Sampler(\d+)\]$/
script.channelRegEx = /^\[Channel(\d+)\]$/
Expand Down
20 changes: 20 additions & 0 deletions src/engine/controls/cuecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "control/controlindicator.h"
#include "vinylcontrol/defs_vinylcontrol.h"
#include "util/sample.h"
#include "util/color/color.h"

// TODO: Convert these doubles to a standard enum
// and convert elseif logic to switch statements
Expand Down Expand Up @@ -297,6 +298,7 @@ void CueControl::trackCuesUpdated() {
} else {
// If the old hotcue is the same, then we only need to update
pControl->setPosition(pCue->getPosition());
pControl->setColor(pCue->getColor());
}
// Add the hotcue to the list of active hotcues
active_hotcues.insert(hotcue);
Expand Down Expand Up @@ -1036,6 +1038,12 @@ HotcueControl::HotcueControl(QString group, int i)
m_hotcueEnabled = new ControlObject(keyForControl(i, "enabled"));
m_hotcueEnabled->setReadOnly();

// The id of the predefined color assigned to this color.
m_hotcueColor = new ControlObject(keyForControl(i, "color_id"));
connect(m_hotcueColor, SIGNAL(valueChanged(double)),
this, SLOT(slotHotcueColorChanged(double)),
Qt::DirectConnection);

m_hotcueSet = new ControlPushButton(keyForControl(i, "set"));
connect(m_hotcueSet, &ControlObject::valueChanged,
this, &HotcueControl::slotHotcueSet,
Expand Down Expand Up @@ -1075,6 +1083,7 @@ HotcueControl::HotcueControl(QString group, int i)
HotcueControl::~HotcueControl() {
delete m_hotcuePosition;
delete m_hotcueEnabled;
delete m_hotcueColor;
delete m_hotcueSet;
delete m_hotcueGoto;
delete m_hotcueGotoAndPlay;
Expand Down Expand Up @@ -1117,6 +1126,11 @@ void HotcueControl::slotHotcuePositionChanged(double newPosition) {
emit(hotcuePositionChanged(this, newPosition));
}

void HotcueControl::slotHotcueColorChanged(double newColorId) {
m_pCue->setColor(Color::predefinedColorSet.predefinedColorFromId(newColorId));
emit(hotcueColorChanged(this, newColorId));
}

double HotcueControl::getPosition() const {
return m_hotcuePosition->get();
}
Expand All @@ -1127,7 +1141,13 @@ void HotcueControl::setCue(CuePointer pCue) {
// because we have a null check for valid data else where in the code
m_pCue = pCue;
}
PredefinedColorPointer HotcueControl::getColor() const {
return Color::predefinedColorSet.predefinedColorFromId(m_hotcueColor->get());
}

void HotcueControl::setColor(PredefinedColorPointer newColor) {
m_hotcueColor->set(static_cast<double>(newColor->m_iId));
}
void HotcueControl::resetCue() {
// clear pCue first because we have a null check for valid data else where
// in the code
Expand Down
5 changes: 5 additions & 0 deletions src/engine/controls/cuecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class HotcueControl : public QObject {
void setCue(CuePointer pCue);
void resetCue();
void setPosition(double position);
void setColor(PredefinedColorPointer newColor);
PredefinedColorPointer getColor() const;

// Used for caching the preview state of this hotcue control.
inline bool isPreviewing() {
Expand All @@ -54,6 +56,7 @@ class HotcueControl : public QObject {
void slotHotcueActivatePreview(double v);
void slotHotcueClear(double v);
void slotHotcuePositionChanged(double newPosition);
void slotHotcueColorChanged(double newColorId);

signals:
void hotcueSet(HotcueControl* pHotcue, double v);
Expand All @@ -64,6 +67,7 @@ class HotcueControl : public QObject {
void hotcueActivatePreview(HotcueControl* pHotcue, double v);
void hotcueClear(HotcueControl* pHotcue, double v);
void hotcuePositionChanged(HotcueControl* pHotcue, double newPosition);
void hotcueColorChanged(HotcueControl* pHotcue, double newColorId);
void hotcuePlay(double v);

private:
Expand All @@ -76,6 +80,7 @@ class HotcueControl : public QObject {
// Hotcue state controls
ControlObject* m_hotcuePosition;
ControlObject* m_hotcueEnabled;
ControlObject* m_hotcueColor;
// Hotcue button controls
ControlObject* m_hotcueSet;
ControlObject* m_hotcueGoto;
Expand Down
10 changes: 5 additions & 5 deletions src/library/dao/cue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#include "library/dao/cue.h"
#include "util/assert.h"
#include "util/color/color.h"

namespace {
const QColor kDefaultColor = QColor("#FF0000");
const QString kDefaultLabel = ""; // empty string, not null
}

Expand All @@ -25,13 +25,13 @@ Cue::Cue(TrackId trackId)
m_length(0.0),
m_iHotCue(-1),
m_label(kDefaultLabel),
m_color(kDefaultColor) {
m_color(Color::predefinedColorSet.noColor) {
DEBUG_ASSERT(!m_label.isNull());
}


Cue::Cue(int id, TrackId trackId, Cue::CueType type, double position, double length,
int hotCue, QString label, QColor color)
int hotCue, QString label, PredefinedColorPointer color)
: m_bDirty(false),
m_iId(id),
m_trackId(trackId),
Expand Down Expand Up @@ -138,12 +138,12 @@ void Cue::setLabel(const QString label) {
emit(updated());
}

QColor Cue::getColor() const {
PredefinedColorPointer Cue::getColor() const {
QMutexLocker lock(&m_mutex);
return m_color;
}

void Cue::setColor(const QColor color) {
void Cue::setColor(const PredefinedColorPointer color) {
QMutexLocker lock(&m_mutex);
m_color = color;
m_bDirty = true;
Expand Down
9 changes: 5 additions & 4 deletions src/library/dao/cue.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QColor>

#include "track/trackid.h"
#include "util/color/predefinedcolor.h"
#include "util/memory.h"

class CueDAO;
Expand Down Expand Up @@ -44,16 +45,16 @@ class Cue : public QObject {
QString getLabel() const;
void setLabel(QString label);

QColor getColor() const;
void setColor(QColor color);
PredefinedColorPointer getColor() const;
void setColor(PredefinedColorPointer color);

signals:
void updated();

private:
explicit Cue(TrackId trackId);
Cue(int id, TrackId trackId, CueType type, double position, double length,
int hotCue, QString label, QColor color);
int hotCue, QString label, PredefinedColorPointer color);
void setDirty(bool dirty);
void setId(int id);
void setTrackId(TrackId trackId);
Expand All @@ -68,7 +69,7 @@ class Cue : public QObject {
double m_length;
int m_iHotCue;
QString m_label;
QColor m_color;
PredefinedColorPointer m_color;

friend class Track;
friend class CueDAO;
Expand Down
9 changes: 6 additions & 3 deletions src/library/dao/cuedao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "library/queryutil.h"
#include "util/assert.h"
#include "util/performancetimer.h"
#include "util/color/color.h"
#include "util/color/predefinedcolor.h"

int CueDAO::cueCount() {
qDebug() << "CueDAO::cueCount" << QThread::currentThread() << m_database.connectionName();
Expand Down Expand Up @@ -51,7 +53,8 @@ CuePointer CueDAO::cueFromRow(const QSqlQuery& query) const {
int length = record.value(record.indexOf("length")).toInt();
int hotcue = record.value(record.indexOf("hotcue")).toInt();
QString label = record.value(record.indexOf("label")).toString();
QColor color = QColor::fromRgba(record.value(record.indexOf("color")).toInt());
int iColorId = record.value(record.indexOf("color")).toInt();
PredefinedColorPointer color = Color::predefinedColorSet.predefinedColorFromId(iColorId);
CuePointer pCue(new Cue(id, trackId, (Cue::CueType)type,
position, length, hotcue, label, color));
m_cues[id] = pCue;
Expand Down Expand Up @@ -145,7 +148,7 @@ bool CueDAO::saveCue(Cue* cue) {
query.bindValue(":length", cue->getLength());
query.bindValue(":hotcue", cue->getHotCue());
query.bindValue(":label", cue->getLabel());
query.bindValue(":color", cue->getColor().rgba());
query.bindValue(":color", cue->getColor()->m_iId);

if (query.exec()) {
int id = query.lastInsertId().toInt();
Expand Down Expand Up @@ -173,7 +176,7 @@ bool CueDAO::saveCue(Cue* cue) {
query.bindValue(":length", cue->getLength());
query.bindValue(":hotcue", cue->getHotCue());
query.bindValue(":label", cue->getLabel());
query.bindValue(":color", cue->getColor().rgba());
query.bindValue(":color", cue->getColor()->m_iId);
ferranpujolcamins marked this conversation as resolved.
Show resolved Hide resolved

if (query.exec()) {
cue->setDirty(false);
Expand Down
40 changes: 35 additions & 5 deletions src/library/dlgtrackinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <QDesktopServices>
#include <QtDebug>
#include <QStringBuilder>
#include <QComboBox>

#include "util/desktophelper.h"
#include "library/dlgtrackinfo.h"
Expand All @@ -12,9 +13,11 @@
#include "track/keyfactory.h"
#include "track/keyutils.h"
#include "util/duration.h"
#include "util/color/color.h"

const int kFilterLength = 80;
const int kMinBpm = 30;

// Maximum allowed interval between beats (calculated from kMinBpm).
const mixxx::Duration kMaxInterval = mixxx::Duration::fromMillis(1000.0 * (60.0 / kMinBpm));

Expand Down Expand Up @@ -274,7 +277,7 @@ void DlgTrackInfo::populateCues(TrackPointer pTrack) {
QListIterator<CuePointer> it(cuePoints);
while (it.hasNext()) {
CuePointer pCue = it.next();
if (pCue->getType() == Cue::CUE || pCue->getType() == Cue::LOAD) {
if (pCue->getType() == Cue::CUE) {
listPoints.push_back(pCue);
}
}
Expand Down Expand Up @@ -318,12 +321,30 @@ void DlgTrackInfo::populateCues(TrackPointer pTrack) {
// Make the duration read only
durationItem->setFlags(Qt::NoItemFlags);


QComboBox* colorComboBox = new QComboBox();
const QList<PredefinedColorPointer> predefinedColors = Color::predefinedColorSet.allColors;
for (int i = 0; i < predefinedColors.count(); i++) {
PredefinedColorPointer color = predefinedColors.at(i);
QColor defaultRgba = color->m_defaultRgba;
colorComboBox->addItem(color->m_sDisplayName, defaultRgba);
const QModelIndex idx = colorComboBox->model()->index(i, 0);
if (*color != *Color::predefinedColorSet.noColor) {
colorComboBox->model()->setData(idx, defaultRgba, Qt::BackgroundColorRole);
}
colorComboBox->setItemData(i, Color::chooseContrastColor(defaultRgba), Qt::TextColorRole);

}
PredefinedColorPointer cueColor = pCue->getColor();
colorComboBox->setCurrentIndex(Color::predefinedColorSet.predefinedColorIndex(cueColor));

m_cueMap[row] = pCue;
cueTable->insertRow(row);
cueTable->setItem(row, 0, new QTableWidgetItem(rowStr));
cueTable->setItem(row, 1, durationItem);
cueTable->setItem(row, 2, new QTableWidgetItem(hotcue));
cueTable->setItem(row, 3, new QTableWidgetItem(pCue->getLabel()));
cueTable->setCellWidget(row, 3, colorComboBox);
cueTable->setItem(row, 4, new QTableWidgetItem(pCue->getLabel()));
row += 1;
}
cueTable->setSortingEnabled(true);
Expand Down Expand Up @@ -367,10 +388,13 @@ void DlgTrackInfo::saveTrack() {
for (int row = 0; row < cueTable->rowCount(); ++row) {
QTableWidgetItem* rowItem = cueTable->item(row, 0);
QTableWidgetItem* hotcueItem = cueTable->item(row, 2);
QTableWidgetItem* labelItem = cueTable->item(row, 3);
QWidget* colorWidget = cueTable->cellWidget(row, 3);
QTableWidgetItem* labelItem = cueTable->item(row, 4);

if (!rowItem || !hotcueItem || !labelItem)
VERIFY_OR_DEBUG_ASSERT(rowItem && hotcueItem && colorWidget && labelItem) {
qWarning() << "unable to retrieve cells from cueTable row";
continue;
}

int oldRow = rowItem->data(Qt::DisplayRole).toInt();
CuePointer pCue(m_cueMap.value(oldRow, CuePointer()));
Expand All @@ -390,6 +414,13 @@ void DlgTrackInfo::saveTrack() {
pCue->setHotCue(-1);
}

auto colorComboBox = qobject_cast<QComboBox*>(colorWidget);
if (colorComboBox) {
PredefinedColorPointer color = Color::predefinedColorSet.allColors.at(colorComboBox->currentIndex());
pCue->setColor(color);
}
// do nothing for now.

QString label = labelItem->data(Qt::DisplayRole).toString();
pCue->setLabel(label);
}
Expand Down Expand Up @@ -430,7 +461,6 @@ void DlgTrackInfo::unloadTrack(bool save) {
}

void DlgTrackInfo::clear() {

disconnect(this, SLOT(updateTrackMetadata()));
m_pLoadedTrack.reset();

Expand Down
5 changes: 5 additions & 0 deletions src/library/dlgtrackinfo.ui
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,11 @@ Often results in higher quality beatgrids, but will not do well on tracks that h
<string>Hotcue</string>
</property>
</column>
<column>
<property name="text">
<string>Color</string>
</property>
</column>
<column>
<property name="text">
<string>Label</string>
Expand Down
Loading