Skip to content

Commit 76680c4

Browse files
committed
led light experiment
1 parent 5d7941d commit 76680c4

File tree

7 files changed

+336
-27
lines changed

7 files changed

+336
-27
lines changed

midimech.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232
try:
3333
import launchpad
3434
except ImportError:
35-
error("The project dependencies have changed! Run the requirements setup command again!")
35+
print("The project dependencies have changed! Run the requirements setup command again!")
3636

3737
try:
3838
import yaml
3939
except ImportError:
40-
error("The project dependencies have changed! Run the requirements setup command again!")
40+
print("The project dependencies have changed! Run the requirements setup command again!")
4141

4242
# import mido
4343

4444
try:
4545
import musicpy as mp
4646
except ImportError:
47-
error("The project dependencies have changed! Run the requirements setup command again!")
47+
print("The project dependencies have changed! Run the requirements setup command again!")
4848

4949

5050
def main():

requirements.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
pygame-ce
2-
pygame_gui
3-
pyglm
4-
rtmidi2
5-
launchpad-py
1+
dataclasses==0.6
2+
launchpad_py==0.9.1
3+
mido_fix==1.2.12
64
musicpy
7-
pyyaml
8-
webcolors
5+
pygame-ce==2.5.2
6+
pygame_gui==0.6.13
7+
pyglm==2.8.0
8+
python-i18n==0.3.9
9+
PyYAML==6.0.2
10+
rtmidi2==1.4.0
11+
webcolors==24.11.1

settings.ini.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ size=128
66
;velocity_curve=1.0
77
;lights=1,9,9,2,2,3,3,5,8,8,11,11
88
;split_lights=4,7,5,7,5,5,7,5,7,5,7,5
9-
;colors=red,darkred,orange,goldenrod,yellow,green,darkolivegreen,blue,darkslateblue,indigo,darkorchid,pink
9+
colors=red,darkred,orange,goldenrod,yellow,green,darkolivegreen,blue,darkslateblue,indigo,darkorchid,pink
1010
;split_colors=cyan,blue,blue,blue,blue,blue,blue,blue,blue,blue,blue,blue
1111
;mark_light=1
1212
;mark_color=red

src/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
GRAY = ivec3(16 * BRIGHTNESS)
1414
BORDER_COLOR = ivec3(48)
1515
DARK = ivec3(0)
16+
BLACK = ivec3(0)
1617
BASE_OFFSET = -4 # linnstrument
1718
# CHORD_ANALYZER = get_option(opts,'chord_analyzer',False)
1819
EPSILON = 0.0001

src/core.py

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from dataclasses import dataclass
88
from glm import ivec2, vec2, ivec3, vec3
99
import time
10+
import colorsys
1011

1112
from src.util import *
1213
from src.constants import *
@@ -1419,19 +1420,29 @@ def __init__(self):
14191420
self.options.octave_separation = get_option(opts, "octave_separation", DEFAULT_OPTIONS.octave_separation)
14201421
self.options.octave_split = get_option(opts, "octave_split", DEFAULT_OPTIONS.octave_split)
14211422

1423+
self.options.width = get_option(opts, "width", 0)
1424+
self.options.height = get_option(opts, "height", 0)
1425+
1426+
self.split_point = None
1427+
14221428
hardware_split = False
1423-
self.options.size = get_option(opts, "size", DEFAULT_OPTIONS.size)
1424-
if self.options.size == 128:
1425-
self.options.width = 16
1426-
self.split_point = None
1427-
elif self.options.size == 200:
1428-
self.options.width = 25
1429-
self.split_point = 11
1430-
hardware_split = True
1431-
elif self.options.size < 0: # test hardware split
1432-
self.options.width = 16
1433-
self.split_point = -self.options.size
1434-
hardware_split = True
1429+
self.split_point = 11
1430+
if self.options.width<=0 or self.options.height<=0:
1431+
self.options.size = get_option(opts, "size", DEFAULT_OPTIONS.size)
1432+
if self.options.size == 200:
1433+
self.options.width = 25
1434+
self.options.height = 8
1435+
self.split_point = 11
1436+
hardware_split = False
1437+
elif self.options.size < 0: # test hardware split
1438+
self.options.width = 16
1439+
self.options.height = 8
1440+
self.split_point = -self.options.size
1441+
hardware_split = True
1442+
else: # if self.options.size == 128:
1443+
self.options.width = 16
1444+
self.options.height = 8
1445+
self.split_point = None
14351446

14361447
# Note: The default below is what is determined by size above.
14371448
# Overriding hardware_split is only useful for 128 user testing 200 behavior
@@ -1477,10 +1488,11 @@ def __init__(self):
14771488
self.scale = vec2(64.0)
14781489

14791490
self.board_w = self.options.width
1491+
self.board_h = self.options.height
14801492
self.board_sz = ivec2(self.board_w, self.board_h)
14811493
self.screen_w = self.board_w * self.scale.x
14821494
self.screen_h = self.board_h * self.scale.y + self.menu_sz + self.status_sz
1483-
self.button_sz = self.screen_w / self.board_w
1495+
self.button_sz = 64
14841496
self.screen_sz = ivec2(self.screen_w, self.screen_h)
14851497

14861498
self.lowest_note = None # x,y location of lowest note currently pressed
@@ -1823,6 +1835,14 @@ def __init__(self):
18231835
self.setup_rpn()
18241836
# self.test()
18251837

1838+
self.leds = None
1839+
# try:
1840+
# from src.leds import LEDGridInterface
1841+
# self.leds = LEDGridInterface()
1842+
# print("LEDs initialized")
1843+
# except Exception as e:
1844+
# print("LEDs not initialized: ", e)
1845+
18261846
def midi_mode_rpn(self, on=True):
18271847
if on:
18281848
self.rpn(0, 1 if self.is_mpe() else 0)
@@ -2357,6 +2377,10 @@ def render(self):
23572377
sz = self.screen_w / self.board_w
23582378
y = 0
23592379
rad = int(sz // 2 - 8)
2380+
T = pygame.time.get_ticks()/1000
2381+
2382+
if self.leds:
2383+
self.leds.clear(BLACK)
23602384

23612385
for row in self.board:
23622386
x = 0
@@ -2376,12 +2400,36 @@ def render(self):
23762400
# else:
23772401
# col = self.get_color(x, y)
23782402
lit_col = ivec3(255, 0, 0)
2379-
unlit_col = copy.copy(self.get_color(x, y) or ivec3(0))
2403+
col = self.get_color(x, y) or ivec3(0)
2404+
unlit_col = copy.copy(col)
23802405
black = unlit_col == ivec3(0)
23812406
inner_col = copy.copy(unlit_col)
23822407
for i in range(len(unlit_col)):
23832408
unlit_col[i] = min(255, unlit_col[i] * 1.5)
23842409

2410+
if self.leds:
2411+
if cell:
2412+
lit = glm.vec3(1,1,1)
2413+
self.leds.put(lit, x, y)
2414+
# self.leds.put(red, x*2+1, y*2)
2415+
# self.leds.put(red, x*2+1, y*2+1)
2416+
# self.leds.put(red, x*2, y*2+1)
2417+
else:
2418+
colf = glm.vec3(col.x / 255, col.y / 255, col.z / 255)
2419+
# # change saturation
2420+
# r, g, b = colf.x, colf.y, colf.z
2421+
# h, s, v = colorsys.rgb_to_hsv(r, g, b)
2422+
# # if v > 0.1:
2423+
# # h = (h + T * 0.1) % 1.0
2424+
# # h, s, v = color_grade_hsv((h, s, v))
2425+
# r, g, b = colorsys.hsv_to_rgb(h, s, v)
2426+
# colf = glm.vec3(r, g, b)
2427+
2428+
self.leds.put(colf, x, y)
2429+
# self.leds.put(colf, x*2+1, y*2)
2430+
# self.leds.put(colf / 2, x*2+1, y*2+1)
2431+
# self.leds.put(colf / 2, x*2, y*2+1)
2432+
23852433
ry = y + self.menu_sz # real y
23862434
# pygame.gfxdraw.box(self.screen.surface, [x*sz + b, self.menu_sz + y*sz + b, sz - b, sz - b], unlit_col)
23872435
rect = [x * sz + b, self.menu_sz + y * sz + b, sz - b, sz - b]
@@ -2476,6 +2524,9 @@ def render(self):
24762524
x += 1
24772525
y += 1
24782526

2527+
if self.leds:
2528+
self.leds.draw()
2529+
24792530
# if self.gamepad:
24802531
# pos = self.gamepad.positions()
24812532
# # gp_pos.y = self.board_h - y - 1

0 commit comments

Comments
 (0)