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 all 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
2 changes: 2 additions & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ def sources(self, build):
"src/controllers/midi/midioutputhandler.cpp",
"src/controllers/softtakeover.cpp",
"src/controllers/keyboard/keyboardeventfilter.cpp",
"src/controllers/colorjsproxy.cpp",

"src/main.cpp",
"src/mixxx.cpp",
Expand Down Expand Up @@ -1225,6 +1226,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
36 changes: 36 additions & 0 deletions src/controllers/colorjsproxy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "controllers/colorjsproxy.h"

ColorJSProxy::ColorJSProxy(QScriptEngine* pScriptEngine)
: m_pScriptEngine(pScriptEngine),
m_predefinedColorsList(makePredefinedColorsList(pScriptEngine)){};

ColorJSProxy::~ColorJSProxy() {};

QScriptValue ColorJSProxy::predefinedColorFromId(int iId) {
PredefinedColorPointer color(Color::predefinedColorSet.predefinedColorFromId(iId));
return jsColorFrom(color);
};

Q_INVOKABLE QScriptValue ColorJSProxy::predefinedColorsList() {
return m_predefinedColorsList;
}

QScriptValue ColorJSProxy::jsColorFrom(PredefinedColorPointer predefinedColor) {
QScriptValue jsColor = m_pScriptEngine->newObject();
jsColor.setProperty("red", predefinedColor->m_defaultRgba.red());
jsColor.setProperty("green", predefinedColor->m_defaultRgba.green());
jsColor.setProperty("blue", predefinedColor->m_defaultRgba.blue());
jsColor.setProperty("alpha", predefinedColor->m_defaultRgba.alpha());
jsColor.setProperty("id", predefinedColor->m_iId);
return jsColor;
}

QScriptValue ColorJSProxy::makePredefinedColorsList(QScriptEngine* pScriptEngine) {
int numColors = Color::predefinedColorSet.allColors.length();
QScriptValue colorList = pScriptEngine->newArray(numColors);
for (int i = 0; i < numColors; ++i) {
PredefinedColorPointer color = Color::predefinedColorSet.allColors.at(i);
colorList.setProperty(i, jsColorFrom(color));
}
return colorList;
}
27 changes: 27 additions & 0 deletions src/controllers/colorjsproxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef COLORJSPROXY_H
#define COLORJSPROXY_H

#include <QObject>
#include <QScriptEngine>
#include <QScriptValue>

#include "util/color/color.h"

class ColorJSProxy: public QObject {
Q_OBJECT
public:
ColorJSProxy(QScriptEngine* pScriptEngine);

virtual ~ColorJSProxy();

Q_INVOKABLE QScriptValue predefinedColorFromId(int iId);
Q_INVOKABLE QScriptValue predefinedColorsList();

private:
QScriptValue jsColorFrom(PredefinedColorPointer predefinedColor);
QScriptValue makePredefinedColorsList(QScriptEngine* pScriptEngine);
QScriptEngine* m_pScriptEngine;
QScriptValue m_predefinedColorsList;
};

#endif /* COLORJSPROXY_H */
4 changes: 4 additions & 0 deletions src/controllers/controllerengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ void ControllerEngine::gracefulShutdown() {
++it;
}

m_pColorJSProxy.reset();
delete m_pBaClass;
m_pBaClass = nullptr;
}
Expand Down Expand Up @@ -212,6 +213,9 @@ void ControllerEngine::initializeScriptEngine() {
engineGlobalObject.setProperty("midi", m_pEngine->newQObject(m_pController));
}

m_pColorJSProxy = std::make_unique<ColorJSProxy>(m_pEngine);
engineGlobalObject.setProperty("color", m_pEngine->newQObject(m_pColorJSProxy.get()));

m_pBaClass = new ByteArrayClass(m_pEngine);
engineGlobalObject.setProperty("ByteArray", m_pBaClass->constructor());
}
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/controllerengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#include "bytearrayclass.h"
#include "preferences/usersettings.h"
#include "controllers/controllerpreset.h"
#include "controllers/colorjsproxy.h"
#include "controllers/softtakeover.h"
#include "util/alphabetafilter.h"
#include "util/duration.h"
#include "util/memory.h"

// Forward declaration(s)
class Controller;
Expand Down Expand Up @@ -204,6 +206,7 @@ class ControllerEngine : public QObject {
QHash<int, TimerInfo> m_timers;
SoftTakeoverCtrl m_st;
ByteArrayClass* m_pBaClass;
std::unique_ptr<ColorJSProxy> m_pColorJSProxy;
// 256 (default) available virtual decks is enough I would think.
// If more are needed at run-time, these will move to the heap automatically
QVarLengthArray<int> m_intervalAccumulator;
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
Loading