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

Find nearest color JS #2356

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a1a96d5
Create HotcueColorPalette class
ferranpujolcamins Oct 27, 2019
9af324c
Add methods to store QColor in the config
ferranpujolcamins Oct 27, 2019
39d8624
Add class to store HotcueColorPalette in userconfig
ferranpujolcamins Oct 27, 2019
a25b3a8
Add tests for color config methods
ferranpujolcamins Nov 1, 2019
547a1f7
Merge branch 'master' into new_colors_impl
ferranpujolcamins Nov 1, 2019
f4c29b2
Make Cue related code use QColor
ferranpujolcamins Nov 2, 2019
ece9385
Migrate hotcue color id to RGBA in DB
ferranpujolcamins Nov 2, 2019
ae4907e
Remove PredefinedColorRepresentation
ferranpujolcamins Nov 2, 2019
4367fe3
Make UserSettings available in ControllerEngine
ferranpujolcamins Nov 3, 2019
bfe25a3
Remove PredefinedColors from controller scripts
ferranpujolcamins Nov 3, 2019
e99e1a8
Remove PredefinedColor
ferranpujolcamins Nov 3, 2019
223911e
Update midi-components library
ferranpujolcamins Nov 3, 2019
150cddf
Avoid constructing HotcueColorPaletteSettings every time its used
ferranpujolcamins Nov 3, 2019
44ffe5d
Change test names
ferranpujolcamins Nov 4, 2019
89927fe
Reorder constructor parameters
ferranpujolcamins Nov 4, 2019
91067eb
Rename member variable
ferranpujolcamins Nov 4, 2019
3233dc3
Rename some color related classes
ferranpujolcamins Nov 4, 2019
768c306
Remove cues tab on TrackInfo
ferranpujolcamins Nov 4, 2019
03b4f06
Add QColorDialog to ColorMenu
ferranpujolcamins Nov 4, 2019
a16a290
Merge branch 'master' into new_colors_impl
ferranpujolcamins Nov 11, 2019
5f22b90
Set hotcue color to the first predefined color
ferranpujolcamins Nov 11, 2019
1bc6c77
Set hotcue color CO to -1 when no hotcue is loaded
ferranpujolcamins Nov 11, 2019
fc22b25
Make hotcue skin buttons use the cue color
ferranpujolcamins Nov 11, 2019
85a3762
Pass UserSettings to Controller constructor
ferranpujolcamins Nov 11, 2019
3027abd
Format code
ferranpujolcamins Nov 11, 2019
53a0877
Rename members
ferranpujolcamins Nov 11, 2019
83892d2
Change string literal
ferranpujolcamins Nov 11, 2019
b858137
Allow skins to configure text color depending on background
ferranpujolcamins Nov 11, 2019
bde2fa8
Highlight hotcue buttons when hovered
ferranpujolcamins Nov 11, 2019
c35de30
Fix Shade hotcue buttons color
ferranpujolcamins Nov 12, 2019
7930270
Make hotcue button hover highlighting configurable
ferranpujolcamins Nov 12, 2019
efda2b1
Merge branch 'master' into new_colors_impl
ferranpujolcamins Nov 12, 2019
318025e
src/controllers/colorjsproxy: Add nearestColorMidiCode function
Holzhaus Nov 14, 2019
77b3f55
res/controllers/midi-components: Update HotcueButton to use new API
Holzhaus Nov 14, 2019
ad38a40
Roland DJ-505: Update controller script for new color API
Holzhaus Nov 14, 2019
b873ca2
src/controllers/colorjsproxy: Fix indentation in colorDistance function
Holzhaus Nov 15, 2019
1d05858
src/controllers/colorjsproxy: Add comment to colorDistance algorithm
Holzhaus Nov 15, 2019
2b61025
src/controllers: Add ColorMapper class for controller scripts
Holzhaus Nov 16, 2019
a24b22a
res/controllers/midi-components: Add support for ColorMapper class
Holzhaus Nov 16, 2019
3f42532
Roland DJ-505: Add support for ColorMapper class
Holzhaus Nov 16, 2019
efde9e4
controllers/colormapperjsproxy: Add separate getNearestValue method
Holzhaus Nov 19, 2019
b94a72f
Roland DJ-505: Switch to ControllerMapper::getNearestValue
Holzhaus Nov 19, 2019
73de6dc
midi-components: Remove default value for HotcueButton.colors
Holzhaus Nov 19, 2019
d4cda18
controllers/midi-components: Rename HotcueButton.colors to .colorMapper
Holzhaus Nov 19, 2019
c6c467b
Roland DJ-505: Rename Component.colors to .colorMapper
Holzhaus Nov 19, 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
7 changes: 5 additions & 2 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ def sources(self, build):
"src/preferences/effectsettingsmodel.cpp",
"src/preferences/broadcastprofile.cpp",
"src/preferences/upgrade.cpp",
"src/preferences/hotcuecolorpalettesettings.cpp",
"src/preferences/dlgpreferencepage.cpp",

"src/effects/effectmanifest.cpp",
Expand Down Expand Up @@ -912,6 +913,8 @@ def sources(self, build):
"src/controllers/softtakeover.cpp",
"src/controllers/keyboard/keyboardeventfilter.cpp",
"src/controllers/colorjsproxy.cpp",
"src/controllers/colormapper.cpp",
"src/controllers/colormapperjsproxy.cpp",

"src/main.cpp",
"src/mixxx.cpp",
Expand Down Expand Up @@ -1254,6 +1257,7 @@ def sources(self, build):
"src/util/movinginterquartilemean.cpp",
"src/util/console.cpp",
"src/util/color/color.cpp",
"src/util/color/colorpalette.cpp",
"src/util/db/dbconnection.cpp",
"src/util/db/dbconnectionpool.cpp",
"src/util/db/dbconnectionpooler.cpp",
Expand All @@ -1280,8 +1284,7 @@ def sources(self, build):
"src/util/desktophelper.cpp",
"src/util/widgetrendertimer.cpp",
"src/util/workerthread.cpp",
"src/util/workerthreadscheduler.cpp",
"src/util/color/predefinedcolor.cpp"
"src/util/workerthreadscheduler.cpp"
]

proto_args = {
Expand Down
53 changes: 30 additions & 23 deletions res/controllers/Roland_DJ-505-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,17 +941,24 @@ DJ505.PadColor = {
DIM_MODIFIER: 0x10,
};

DJ505.PadColorMap = [
DJ505.PadColor.OFF,
DJ505.PadColor.RED,
DJ505.PadColor.GREEN,
DJ505.PadColor.BLUE,
DJ505.PadColor.YELLOW,
DJ505.PadColor.CELESTE,
DJ505.PadColor.PURPLE,
DJ505.PadColor.APRICOT,
DJ505.PadColor.WHITE,
];
DJ505.PadColorMap = {
'#FFCC0000': DJ505.PadColor.RED,
'#FFCC4400': DJ505.PadColor.CORAL,
'#FFCC8800': DJ505.PadColor.ORANGE,
'#FFCCCC00': DJ505.PadColor.YELLOW,
'#FF88CC00': DJ505.PadColor.GREEN,
'#FF00CC00': DJ505.PadColor.APPLEGREEN,
'#FF00CC88': DJ505.PadColor.AQUAMARINE,
'#FF00CCCC': DJ505.PadColor.TURQUOISE,
'#FF0088CC': DJ505.PadColor.CELESTE,
'#FF0000CC': DJ505.PadColor.BLUE,
'#FF4400CC': DJ505.PadColor.AZURE,
'#FF8800CC': DJ505.PadColor.PURPLE,
'#FFCC00CC': DJ505.PadColor.MAGENTA,
'#FFCC0044': DJ505.PadColor.RED,
'#FFFFCCCC': DJ505.PadColor.APRICOT,
'#FFFFFFFF': DJ505.PadColor.WHITE,
};

DJ505.PadSection = function (deck, offset) {
// TODO: Add support for missing modes (flip, slicer, slicerloop)
Expand Down Expand Up @@ -1190,7 +1197,7 @@ DJ505.HotcueMode = function (deck, offset) {
this.ledControl = DJ505.PadMode.HOTCUE;
this.color = DJ505.PadColor.WHITE;

var hotcueColors = [this.color].concat(DJ505.PadColorMap.slice(1));
var hotcueColors = DJ505.PadColorMap;
this.pads = new components.ComponentContainer();
for (var i = 0; i <= 7; i++) {
this.pads[i] = new components.HotcueButton({
Expand Down Expand Up @@ -1226,7 +1233,7 @@ DJ505.CueLoopMode = function (deck, offset) {
this.ledControl = DJ505.PadMode.HOTCUE;
this.color = DJ505.PadColor.BLUE;

var cueloopColors = [this.color].concat(DJ505.PadColorMap.slice(1));
var cueloopColors = DJ505.PadColorMap;
this.PerformancePad = function(n) {
this.midi = [0x94 + offset, 0x14 + n];
this.number = n + 1;
Expand Down Expand Up @@ -1492,14 +1499,14 @@ DJ505.PitchPlayMode = function (deck, offset) {
this.color = DJ505.PadColor.GREEN;
this.cuepoint = 1;
this.range = PitchPlayRange.MID;
var pitchplayColors = [this.color].concat(DJ505.PadColorMap.slice(1));
var pitchplayColors = DJ505.PadColorMap;

this.PerformancePad = function(n) {
this.midi = [0x94 + offset, 0x14 + n];
this.number = n + 1;
this.on = this.color + DJ505.PadColor.DIM_MODIFIER;
this.colors = pitchplayColors;
this.colorIdKey = 'hotcue_' + this.number + '_color_id';
this.colorKey = 'hotcue_' + this.number + '_color';
components.Button.call(this);
};
this.PerformancePad.prototype = new components.Button({
Expand All @@ -1510,10 +1517,10 @@ DJ505.PitchPlayMode = function (deck, offset) {
mode: this,
outConnect: false,
off: DJ505.PadColor.OFF,
outputColor: function(id) {
outputColor: function(colorCode) {
// For colored hotcues (shifted only)
var color = this.colors[id];
this.send((this.mode.cuepoint === this.number) ? color : (color + DJ505.PadColor.DIM_MODIFIER));
var midiColor = color.nearestColorMidiCode(colorCode, this.colors)
this.send((this.mode.cuepoint === this.number) ? midiColor : (midiColor + DJ505.PadColor.DIM_MODIFIER));
},
unshift: function() {
this.outKey = "pitch_adjust";
Expand Down Expand Up @@ -1561,8 +1568,8 @@ DJ505.PitchPlayMode = function (deck, offset) {
this.outKey = "hotcue_" + this.number + "_enabled";
this.output = function (value, group, control) {
var outval = this.outValueScale(value);
if (this.colorIdKey !== undefined && outval !== this.off) {
this.outputColor(engine.getValue(this.group, this.colorIdKey));
if (this.colorKey !== undefined && outval !== this.off) {
this.outputColor(engine.getValue(this.group, this.colorKey));
} else {
this.send(DJ505.PadColor.OFF);
}
Expand All @@ -1572,13 +1579,13 @@ DJ505.PitchPlayMode = function (deck, offset) {
var previous_cuepoint = this.mode.cuepoint;
this.mode.cuepoint = this.number;
this.mode.pads[previous_cuepoint - 1].trigger();
this.outputColor(engine.getValue(this.group, this.colorIdKey));
this.outputColor(engine.getValue(this.group, this.colorKey));
}
};
this.connect = function() {
components.Button.prototype.connect.call(this); // call parent connect
if (undefined !== this.group && this.colorIdKey !== undefined) {
this.connections[1] = engine.makeConnection(this.group, this.colorIdKey, function (id) {
if (undefined !== this.group && this.colorKey !== undefined) {
this.connections[1] = engine.makeConnection(this.group, this.colorKey, function (id) {
if (engine.getValue(this.group, this.outKey)) {
this.outputColor(id);
}
Expand Down
33 changes: 15 additions & 18 deletions res/controllers/midi-components-0.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@
return;
}
if (options.colors !== undefined || options.sendRGB !== undefined) {
this.colorIdKey = 'hotcue_' + options.number + '_color_id';
this.colorKey = 'hotcue_' + options.number + '_color';
if (options.colors === undefined) {
options.colors = color.predefinedColorsList();
options.colors = color.hotcueColorPalette();
}
}
this.number = options.number;
Expand All @@ -312,8 +312,8 @@
this.inKey = 'hotcue_' + this.number + '_clear';
},
getColor: function() {
if (this.colorIdKey !== undefined) {
return color.predefinedColorFromId(engine.getValue(this.group,this.colorIdKey));
if (this.colorKey !== undefined) {
return color.colorFromHexCode(engine.getValue(this.group,this.colorKey));
} else {
return null;
}
Expand All @@ -324,32 +324,29 @@
// and there is no hotcueColor for turning the LED
// off. So the `send()` function is responsible for turning the
// actual LED off.
if (this.colorIdKey !== undefined && outval !== this.off) {
this.outputColor(engine.getValue(this.group, this.colorIdKey));
if (this.colorKey !== undefined && outval !== this.off) {
this.outputColor(engine.getValue(this.group, this.colorKey));
} else {
this.send(outval);
}
},
outputColor: function (id) {
var color = this.colors[id];
if (color instanceof Array) {
if (color.length !== 3) {
print("ERROR: invalid color array for id: " + id);
return;
}
outputColor: function (colorCode) {
if (this.colors !== undefined) {
var nearestColor = color.nearestColorMidiCode(colorCode, this.colors);
print("COLOR = "+nearestColor);
this.send(nearestColor);
} else {
if (this.sendRGB === undefined) {
print("ERROR: no function defined for sending RGB colors");
return;
}
this.sendRGB(color);
} else if (typeof color === 'number') {
this.send(color);
this.sendRGB(color.colorFromHexCode(colorCode));
}
},
connect: function() {
Button.prototype.connect.call(this); // call parent connect
if (undefined !== this.group && this.colorIdKey !== undefined) {
this.connections[1] = engine.makeConnection(this.group, this.colorIdKey, function (id) {
if (undefined !== this.group && this.colorKey !== undefined) {
this.connections[1] = engine.makeConnection(this.group, this.colorKey, function (id) {
if (engine.getValue(this.group,this.outKey)) {
this.outputColor(id);
}
Expand Down
27 changes: 26 additions & 1 deletion res/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -480,5 +480,30 @@ METADATA
position INTEGER
);
</sql>
</revision>
</revision>
<revision version="31" min_compatible="3">
<description>
Convert the PredefinedColor id to the actual RGBA value.
</description>
<sql>
<!-- No Color becomes black-->
UPDATE cues SET color=4278190080 WHERE color=0;
<!-- Red -->
UPDATE cues SET color=4291103240 WHERE color=1;
<!-- Green -->
UPDATE cues SET color=4281515588 WHERE color=2;
<!-- Blue -->
UPDATE cues SET color=4278207743 WHERE color=3;
<!-- Yellow -->
UPDATE cues SET color=4294496768 WHERE color=4;
<!-- Celeste -->
UPDATE cues SET color=4282569972 WHERE color=5;
<!-- Magenta -->
UPDATE cues SET color=4289659084 WHERE color=6;
<!-- Pink -->
UPDATE cues SET color=4294747863 WHERE color=7;
<!-- White -->
UPDATE cues SET color=4294111999 WHERE color=8;
</sql>
</revision>
</schema>
4 changes: 2 additions & 2 deletions res/skins/Deere/hotcue_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<ConnectValueFromWidget>false</ConnectValueFromWidget>
</Connection>
<Connection>
<ConfigKey><Variable name="group"/>,hotcue_<Variable name="hotcue"/>_color_id</ConfigKey>
<BindProperty>highlight</BindProperty>
<ConfigKey><Variable name="group"/>,hotcue_<Variable name="hotcue"/>_color</ConfigKey>
<BindProperty>backgroundColorRgba</BindProperty>
</Connection>
</PushButton>
</Template>
Loading