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

[WIP] Allow for a user to choose a custom active color and state #61

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 20 additions & 8 deletions lp_colors.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
curr_colors = [[[0,0,0] for y in range(9)] for x in range(9)]
curr_colors = [[[0, 0, 0] for y in range(9)] for x in range(9)]
# color modes are solid, flash and pulse
color_modes = [["solid" for y in range(9)] for x in range(9)]

import lp_events, scripts, window
import colorsys

lp_object = None


def init(lp_object_in):
global lp_object
lp_object = lp_object_in


def code_to_RGB(code):
# Used to convert old layouts to the new format only
RGB = {0: "#000",
Expand Down Expand Up @@ -49,10 +52,11 @@ def code_to_RGB(code):
rgb.append(int(val + val, 16))
return rgb


def RGB_to_RG(rgb):
if rgb[2] != 0:
color = list(colorsys.rgb_to_hsv(rgb[0], rgb[1], rgb[2]))
color[0] = color[0] * (106/330)
color[0] = color[0] * (106 / 330)
color = list(colorsys.hsv_to_rgb(color[0], color[1], color[2]))
color = [round(x) for x in color]
for x in range(2):
Expand All @@ -61,12 +65,15 @@ def RGB_to_RG(rgb):
else:
return rgb


def setXY(x, y, color):
curr_colors[x][y] = color


def getXY(x, y):
return curr_colors[x][y]


def list_RGB_to_string(color):
color_texts = [hex(c)[2:] for c in color]
color_string = "#"
Expand All @@ -76,13 +83,16 @@ def list_RGB_to_string(color):
color_string += c
return color_string


def getXY_RGB(x, y):
color = getXY(x, y)
color_string = list_RGB_to_string(color)
return color_string


def luminance(r, g, b):
return ((0.299 * r) + (0.587 * g) + (0.114 * b)) / 255.0
return ((0.299 * r) + (0.587 * g) + (0.114 * b)) / 255.0


def updateXY(x, y):
if window.lp_connected:
Expand All @@ -94,7 +104,7 @@ def updateXY(x, y):

is_func_key = ((y == 0) or (x == 8))

#print("Update colors for (" + str(x) + ", " + str(y) + "), is_running = " + str(is_running))
# print("Update colors for (" + str(x) + ", " + str(y) + "), is_running = " + str(is_running))

if is_running:
set_color = scripts.COLOR_PRIMED
Expand All @@ -112,12 +122,12 @@ def updateXY(x, y):
if window.lp_mode == "Mk1":
if type(set_color) is int:
set_color = code_to_RGB(set_color)
lp_object.LedCtrlXY(x, y, set_color[0]//64, set_color[1]//64)
lp_object.LedCtrlXY(x, y, set_color[0] // 64, set_color[1] // 64)
else:
if (color_modes[x][y] == "solid") or is_func_key:
#pulse and flash only work on main grid
# pulse and flash only work on main grid
if type(set_color) is list:
lp_object.LedCtrlXYByRGB(x, y, [c//4 for c in set_color])
lp_object.LedCtrlXYByRGB(x, y, [c // 4 for c in set_color])
else:
lp_object.LedCtrlXYByCode(x, y, set_color)
elif color_modes[x][y] == "pulse":
Expand All @@ -127,12 +137,13 @@ def updateXY(x, y):
lp_object.LedCtrlFlashXYByCode(x, y, set_color)
else:
if type(set_color) is list:
lp_object.LedCtrlXYByRGB(x, y, [c//4 for c in set_color])
lp_object.LedCtrlXYByRGB(x, y, [c // 4 for c in set_color])
else:
lp_object.LedCtrlXYByCode(x, y, set_color)
else:
print("[lp_colors] (" + str(x) + ", " + str(y) + ") Launchpad is disconnected, cannot update.")


def update_all():
if window.lp_connected:
for x in range(9):
Expand All @@ -141,6 +152,7 @@ def update_all():
else:
print("[lp_colors] Launchpad is disconnected, cannot update.")


def raw_clear():
for x in range(9):
for y in range(9):
Expand Down
Loading