Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.
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
46 changes: 46 additions & 0 deletions animations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import time
import math
from random import choice
from lpfx.constants import COLOR_RAINBOW

def wave_effect(controller, direction="horizontal", speed=0.1, duration=5):
start = time.time()
while time.time() - start < duration and controller.running:
for phase in range(8):
for row in range(8):
for col in range(8):
if direction == "horizontal":
val = int(4.5 + 3.5 * math.sin((col + phase) * math.pi / 4))
lit = (7 - row) == val
else:
val = int(4.5 + 3.5 * math.sin((row + phase) * math.pi / 4))
lit = (7 - col) == val
note = row * 16 + col
controller.send_note(note, choice(COLOR_RAINBOW) if lit else 0)
time.sleep(speed)
controller.clear_grid()

def sweep_effect(controller, direction="left", speed=0.05, duration=5):
steps = 8
if direction == "left":
cols = range(8)
elif direction == "right":
cols = reversed(range(8))
elif direction == "up":
rows = reversed(range(8))
else:
rows = range(8)

start = time.time()
while time.time() - start < duration and controller.running:
for step in range(steps):
for row in range(8):
for col in range(8):
note = row * 16 + col
if direction in ["left", "right"]:
lit = col == step
else:
lit = row == step
controller.send_note(note, choice(COLOR_RAINBOW) if lit else 0)
time.sleep(speed)
controller.clear_grid()
25 changes: 25 additions & 0 deletions audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import numpy as np
import sounddevice as sd
import time
from lpfx.constants import COLOR_RAINBOW

def audio_effect(controller):
def callback(indata, frames, time_info, status):
if not controller.running or controller.current_effect != "audio":
raise sd.CallbackStop()

samples = indata[:, 0]
fft = np.abs(np.fft.rfft(samples))
bins = np.array_split(fft, 8)
levels = [min(int(np.mean(b) * 10), 8) for b in bins]

for col in range(8):
for row in range(8):
note = (7 - row) * 16 + col
val = COLOR_RAINBOW[col % len(COLOR_RAINBOW)] if row < levels[col] else 0
controller.send_note(note, val)

with sd.InputStream(callback=callback):
while controller.running and controller.current_effect == "audio":
time.sleep(0.05)
controller.clear_grid()
31 changes: 31 additions & 0 deletions buttons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import threading
import time

def listen_buttons(controller):
mode_buttons = {108: 'audio', 109: 'system', 110: 'scroll', 111: 'party', 104: 'wave', 105: 'sweep'}
color_buttons = {106: -1, 107: 1}
debounce_time = 0.2
last_pressed = {}

while controller.running:
msg = controller.inport.poll()
if msg and msg.type == 'control_change':
ctrl, val = msg.control, msg.value
now = time.time()

if val > 0 and (ctrl not in last_pressed or now - last_pressed[ctrl] > debounce_time):
last_pressed[ctrl] = now

if ctrl in mode_buttons:
controller.current_effect = mode_buttons[ctrl]
threading.Thread(target=controller.run_loop, daemon=True).start()
print(f"Mode changed to {controller.current_effect}")

elif ctrl in color_buttons:
colors = controller.color_profile.get('grid_colors', [15, 31, 47, 63, 79, 95, 111, 127])
current = controller.color_profile['grid']
idx = colors.index(current)
controller.color_profile['grid'] = colors[(idx + color_buttons[ctrl]) % len(colors)]
print(f"Color profile changed to {controller.color_profile['grid']}")

time.sleep(0.01)
18 changes: 18 additions & 0 deletions gimmicks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import random
from charset import CHARSET

def render_sprite(controller, pattern, duration=1.5, color=127):
import time
start = time.time()
while time.time() - start < duration and controller.running:
for row in range(8):
for col in range(8):
pixel = (ord(pattern[row][col]) != ord(" "))
note = row * 16 + col
controller.send_note(note, color if pixel else 0)
time.sleep(0.1)
controller.clear_grid()

def show_random_gimmick(controller):
pattern = random.choice([CHARSET["PACMAN"], CHARSET["GHOST"], CHARSET["SMILEY"]])
render_sprite(controller, pattern)