Skip to content
Merged
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
7 changes: 2 additions & 5 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
# C0114: missing-module-docstring
# C0115: missing-class-docstring
# C0116: missing-function-docstring
# C0304: missing-final-newline
# E1135: unsupported-membership-test
# R1732: consider-using-with
# E1101: no-member
# W0718: broad-exception-caught
# W1113: keyword-arg-before-vararg
disable=C0103, C0114, C0115, C0116, C0304, E1135, R1732, W0718, W1113
disable=C0103, C0114, C0115, C0116, E1101, W0718

# Maximum line length for the code
max-line-length=120
2 changes: 1 addition & 1 deletion api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ async def startup_event():
@app.on_event("shutdown")
async def shutdown_event():
lp.clear()
lp.disconnect()
lp.disconnect()
5 changes: 3 additions & 2 deletions api/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

response = requests.post(
"http://127.0.0.1:8000/command",
json={"command": "solid", "args": ["3"]}
json={"command": "solid", "args": ["3"]},
timeout=5
)
print(response.json())
print(response.json())
4 changes: 2 additions & 2 deletions launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def disconnect(self):
def set_mode(self, mode_name):
if not mode_name or mode_name not in MODES:
print(f"❌ Usage: mode <{'|'.join(MODES.keys())}>")
return
return None
if mode_name == self.current_mode:
return
return mode_name
if self.current_mode:
self.midi_out.send_message(HEADER + [0x0B, MODES[self.current_mode]["note"], 0, 0, 0, 0xF7])
self.midi_out.send_message(HEADER + [0x22, MODES[mode_name]["layout"], 0xF7])
Expand Down
89 changes: 52 additions & 37 deletions misc/lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,56 +36,71 @@ def send_palette(midi_out, note, color):
midi_out.send_message(HEADER + [0x0E, color, 0xF7])


def main():
midi_out = setup_midi()
note_input = input("Enter note number(s) to light (comma separated, blank for all): ").strip()
color_input = input("Enter RGB values (e.g. 63 0 63) or a single palette value (0-127: ").strip()
def parse_notes(note_input):
if not note_input:
return ALL_NOTES
try:
return [int(n) for n in note_input.split(",") if n.strip()]
except ValueError:
print("❌ Invalid note number(s).")
return None


def parse_color(color_input):
rgb_parts = color_input.split()
use_rgb = False
if len(rgb_parts) == 3:
try:
r, g, b = map(int, rgb_parts)
if all(0 <= v <= 63 for v in (r, g, b)):
use_rgb = True
else:
raise ValueError
except ValueError:
print("❌ Invalid RGB values. Please enter three numbers between 0 and 63.")
midi_out.close_port()
return
else:
try:
color = int(color_input, 16) if color_input.lower().startswith("0x") else int(color_input)
if not 0 <= color <= 127:
raise ValueError
except ValueError:
print("❌ Invalid palette value. Enter a number 0-127 or hex 0x00-0x7F.")
midi_out.close_port()
return

if not note_input:
notes = ALL_NOTES
else:
try:
notes = [int(n) for n in note_input.split(",") if n.strip()]
return ("rgb", (r, g, b))
except ValueError:
print("❌ Invalid note number(s).")
midi_out.close_port()
return

if use_rgb:
pass
print("❌ Invalid RGB values. Please enter three numbers between 0 and 63.")
return None
try:
color = int(color_input, 16) if color_input.lower().startswith("0x") else int(color_input)
if 0 <= color <= 127:
return ("palette", color)
except ValueError:
pass
print("❌ Invalid palette value. Enter a number 0-127 or hex 0x00-0x7F.")
return None


def light_notes(midi_out, notes, color_type, color_value):
if color_type == "rgb":
r, g, b = color_value
for note in notes:
send_rgb(midi_out, note, r, g, b)
else:
elif color_type == "palette":
if notes == ALL_NOTES:
send_palette(midi_out, 0, color)
send_palette(midi_out, 0, color_value)
else:
for note in notes:
send_palette(midi_out, note, color)
send_palette(midi_out, note, color_value)


def main():
midi_out = setup_midi()
try:
note_input = input("Enter note number(s) to light (comma separated, blank for all): ").strip()
color_input = input("Enter RGB values (e.g. 63 0 63) or a single palette value (0-127): ").strip()

notes = parse_notes(note_input)
if notes is None:
midi_out.close_port()
return

color = parse_color(color_input)
if color is None:
midi_out.close_port()
return

midi_out.close_port()
color_type, color_value = color
light_notes(midi_out, notes, color_type, color_value)
finally:
midi_out.close_port()


if __name__ == "__main__":
main()
main()
2 changes: 1 addition & 1 deletion misc/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ def main():


if __name__ == "__main__":
main()
main()