Skip to content

Commit 6eed4a6

Browse files
committed
Improved lights, splitting, split colors
1 parent 668a548 commit 6eed4a6

File tree

1 file changed

+57
-30
lines changed

1 file changed

+57
-30
lines changed

app.py

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,15 @@ def set_light(self, x, y, col): # col is [1,11], 0 resets
138138
# self.send_cc(0, 22, 7) # no light
139139

140140
def reset_light(self, x, y):
141-
if not self.options.lights: return
142141
note = self.get_note_index(x, y) % 12
143-
light_col = self.options.lights[note]
142+
if self.is_split():
143+
split_chan = self.channel_from_split(self.board_h-y-1, x)
144+
if split_chan:
145+
light_col = self.options.split_lights[note]
146+
else:
147+
light_col = self.options.lights[note]
148+
else:
149+
light_col = self.options.lights[note]
144150
self.set_light(x, y, light_col)
145151
self.red_lights[y][x] = False
146152

@@ -151,7 +157,6 @@ def setup_lights(self):
151157
self.set_light(x, y, 1)
152158
else:
153159
self.reset_light(x, y)
154-
155160

156161
def reset_lights(self):
157162
for y in range(self.board_h):
@@ -188,7 +193,15 @@ def get_note(self, x, y):
188193
def get_color(self, x, y):
189194
# return NOTE_COLORS[get_note_index(x, y)]
190195
note = self.get_note_index(x, y)
191-
return COLOR_CODES[self.options.lights[note]]
196+
if self.is_split():
197+
split_chan = self.channel_from_split(self.board_h-y-1, x)
198+
if split_chan:
199+
light_col = self.options.split_lights[note]
200+
else:
201+
light_col = self.options.lights[note]
202+
else:
203+
light_col = self.options.lights[note]
204+
return COLOR_CODES[light_col]
192205

193206
def mouse_held(self):
194207
return self.mouse_midi != -1
@@ -423,26 +436,26 @@ def cb_foot(self, data, ts):
423436
high = self.options.velocity_curve_HIGH
424437
self.velocity_curve_ = low + val2*(high-low)
425438

426-
def save():
427-
self.cfg = ConfigParser(allow_no_value=True)
428-
general = self.cfg['general'] = {}
429-
if self.options.lights:
430-
general['lights'] = ','.join(map(str,self.options.lights))
431-
general['one_channel'] = self.options.one_channel
432-
general['velocity_curve'] = self.options.velocity_curve
433-
general['min_velocity'] = self.options.min_velocity
434-
general['max_velocity'] = self.options.max_velocity
435-
general['no_overlap'] = self.options.no_overlap
436-
general['hardware_split'] = self.options.hardware_split
437-
general['show_lowest_note'] = self.options.show_lowest_note
438-
general['midi_out'] = self.options.midi_out
439-
general['split_out'] = self.options.split_out
440-
general['split'] = SPLIT
441-
general['fps'] = self.options.fps
442-
general['sustain'] = SUSTAIN
443-
self.cfg['general'] = general
444-
with open('settings_temp.ini', 'w') as configfile:
445-
self.cfg.write(configfile)
439+
# def save():
440+
# self.cfg = ConfigParser(allow_no_value=True)
441+
# general = self.cfg['general'] = {}
442+
# if self.options.lights:
443+
# general['lights'] = ','.join(map(str,self.options.lights))
444+
# general['one_channel'] = self.options.one_channel
445+
# general['velocity_curve'] = self.options.velocity_curve
446+
# general['min_velocity'] = self.options.min_velocity
447+
# general['max_velocity'] = self.options.max_velocity
448+
# general['no_overlap'] = self.options.no_overlap
449+
# general['hardware_split'] = self.options.hardware_split
450+
# general['show_lowest_note'] = self.options.show_lowest_note
451+
# general['midi_out'] = self.options.midi_out
452+
# general['split_out'] = self.options.split_out
453+
# general['split'] = SPLIT
454+
# general['fps'] = self.options.fps
455+
# general['sustain'] = SUSTAIN
456+
# self.cfg['general'] = general
457+
# with open('settings_temp.ini', 'w') as configfile:
458+
# self.cfg.write(configfile)
446459

447460
def __init__(self):
448461

@@ -456,11 +469,17 @@ def __init__(self):
456469
self.options = Options()
457470

458471
default_lights = '4,7,3,7,3,3,7,3,7,3,7,3'
472+
default_split_lights = '4,7,5,7,5,5,7,5,7,5,7,5'
459473

460474
# LIGHT = glm.ivec3(127)
461475
self.options.lights = get_option(opts,'lights',default_lights)
462476
if self.options.lights:
463477
self.options.lights = list(map(lambda x: int(x), self.options.lights.split(',')))
478+
479+
self.options.split_lights = get_option(opts,'lights',default_split_lights)
480+
if self.options.split_lights:
481+
self.options.split_lights = list(map(lambda x: int(x), self.options.split_lights.split(',')))
482+
464483
self.options.one_channel = get_option(opts,'one_channel',False)
465484

466485
# bend the velocity curve, examples: 0.5=sqrt, 1.0=default, 2.0=squared
@@ -746,14 +765,14 @@ def quit(self):
746765
self.done = True
747766

748767
def clear_marks(self, use_lights=False):
749-
for row in rows:
768+
y = 0
769+
for row in self.board:
750770
x = 0
751771
for x in range(len(row)):
752772
idx = self.get_note_index(x, y)
753773
try:
754-
self.board[y+self.flipped][x] = state
774+
self.board[y][x] = False
755775
except IndexError:
756-
print("clear_marks: Out of range")
757776
pass
758777
if use_lights:
759778
if state:
@@ -815,7 +834,7 @@ def resize(self):
815834
self.dirty_lights = True
816835

817836
def channel_from_split(self, row, col):
818-
if not self.options.split:
837+
if not self.is_split():
819838
return 0
820839
w = self.board_w
821840
col += 1 # move start point from C to A#
@@ -825,7 +844,7 @@ def channel_from_split(self, row, col):
825844

826845
def is_split(self):
827846
# TODO: make this work with hardware overlap (non-mpe)
828-
return self.options.no_overlap and self.options.split and self.split_out
847+
return self.options.no_overlap and self.split_state and self.split_out
829848

830849
def logic(self, dt):
831850

@@ -841,6 +860,7 @@ def logic(self, dt):
841860
try:
842861
n = self.keys[ev.key]
843862
n -= 12
863+
n += self.octave * 12
844864
self.mark(n + self.vis_octave * 12, 1, True)
845865
data = [0x90, n, 127]
846866
# TODO: add split for mouse?
@@ -852,6 +872,7 @@ def logic(self, dt):
852872
try:
853873
n = self.keys[ev.key]
854874
n -= 12
875+
n += self.octave * 12
855876
self.mark(n + self.vis_octave * 12, 0, True)
856877
data = [0x80, n, 0]
857878
if self.midi_out:
@@ -874,15 +895,19 @@ def logic(self, dt):
874895
if ev.ui_element == self.btn_octave_down:
875896
self.octave -= 1
876897
self.dirty = self.dirty_lights = True
898+
self.clear_marks(use_lights=False)
877899
elif ev.ui_element == self.btn_octave_up:
878900
self.octave += 1
879901
self.dirty = self.dirty_lights = True
902+
self.clear_marks(use_lights=False)
880903
elif ev.ui_element == self.btn_transpose_down:
881904
self.transpose_board(-1)
882905
self.dirty = self.dirty_lights = True
906+
self.clear_marks(use_lights=False)
883907
elif ev.ui_element == self.btn_transpose_up:
884908
self.transpose_board(1)
885909
self.dirty = self.dirty_lights = True
910+
self.clear_marks(use_lights=False)
886911
# elif ev.ui_element == self.btn_mode:
887912
# # TODO: toggle mode
888913
# self.dirty = True
@@ -901,14 +926,16 @@ def logic(self, dt):
901926
else:
902927
self.transpose -= 3
903928
self.rotated = True
929+
self.clear_marks(use_lights=False)
904930
self.dirty = self.dirty_lights = True
905931
elif ev.ui_element == self.btn_flip:
906932
self.flipped = not self.flipped
933+
self.clear_marks(use_lights=False)
907934
self.dirty = self.dirty_lights = True
908935
elif ev.ui_element == self.btn_split:
909936
self.split_state = not self.split_state
910937
self.btn_split.set_text("SPLIT: " + ("ON" if self.split_state else "OFF"))
911-
self.dirty = True
938+
self.dirty = self.dirty_lights = True
912939
# elif ev.type == pygame_gui.UI_HORIZONTAL_SLIDER_MOVED:
913940
# if ev.ui_element == self.slider_velocity:
914941
# global self.options.velocity_curve

0 commit comments

Comments
 (0)