feat(patterns): align manual and auto behaviour
Unify manual/auto timing semantics for key patterns, add preset background support, and improve runtime observability while keeping the driver responsive under beat-triggered selects. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,6 +12,7 @@ class Preset:
|
||||
self.n4 = 0
|
||||
self.n5 = 0
|
||||
self.n6 = 0
|
||||
self.bg = (0, 0, 0)
|
||||
|
||||
# Override defaults with provided data
|
||||
self.edit(data)
|
||||
@@ -25,9 +26,10 @@ class Preset:
|
||||
"delay": "d",
|
||||
"brightness": "b",
|
||||
"auto": "a",
|
||||
"background": "bg",
|
||||
}
|
||||
int_fields = {"d", "b", "n1", "n2", "n3", "n4", "n5", "n6"}
|
||||
allowed_fields = {"p", "c", "d", "b", "a", "n1", "n2", "n3", "n4", "n5", "n6"}
|
||||
allowed_fields = {"p", "c", "d", "b", "a", "bg", "n1", "n2", "n3", "n4", "n5", "n6"}
|
||||
for key, value in data.items():
|
||||
key = aliases.get(key, key)
|
||||
if key not in allowed_fields:
|
||||
@@ -56,6 +58,21 @@ class Preset:
|
||||
elif key == "c":
|
||||
if isinstance(value, (list, tuple)):
|
||||
self.c = value
|
||||
elif key == "bg":
|
||||
if isinstance(value, str) and value.startswith("#") and len(value) == 7:
|
||||
try:
|
||||
self.bg = (
|
||||
int(value[1:3], 16),
|
||||
int(value[3:5], 16),
|
||||
int(value[5:7], 16),
|
||||
)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
elif isinstance(value, (list, tuple)) and len(value) == 3:
|
||||
try:
|
||||
self.bg = tuple(max(0, min(255, int(x))) for x in value)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
else:
|
||||
setattr(self, key, value)
|
||||
return True
|
||||
@@ -101,6 +118,12 @@ class Preset:
|
||||
self.a = value
|
||||
|
||||
def background_or(self, colors=None, default=(0, 0, 0)):
|
||||
bg = getattr(self, "bg", None)
|
||||
if isinstance(bg, (list, tuple)) and len(bg) == 3:
|
||||
try:
|
||||
return tuple(max(0, min(255, int(x))) for x in bg)
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
return default
|
||||
|
||||
def to_dict(self):
|
||||
@@ -110,6 +133,7 @@ class Preset:
|
||||
"b": self.b,
|
||||
"c": self.c,
|
||||
"a": self.a,
|
||||
"bg": self.bg,
|
||||
"n1": self.n1,
|
||||
"n2": self.n2,
|
||||
"n3": self.n3,
|
||||
|
||||
Reference in New Issue
Block a user