@@ -161,6 +161,14 @@ def reset_lights(self):
161
161
def get_octave (self , x , y ):
162
162
return self .octaves [y - self .board_h + self .flipped ][x ] + self .octave
163
163
164
+ def xy_to_midi (self , x , y ):
165
+ row = self .board_h - y
166
+ r = x % self .board_w + 25.5 + 2.5 * row
167
+ r *= 2
168
+ r = int (r )
169
+ r += (self .octave + self .octave_base ) * 12
170
+ return r
171
+
164
172
def get_note_index (self , x , y ):
165
173
y += self .flipped
166
174
x += self .transpose
@@ -396,7 +404,7 @@ def __init__(self):
396
404
397
405
self .options = Options ()
398
406
399
- default_lights = '3 ,7,5 ,7,5,8 ,7,8,2,8 ,7,8 '
407
+ default_lights = '4 ,7,3 ,7,3,3 ,7,3,7,3 ,7,3 '
400
408
401
409
# LIGHT = glm.ivec3(127)
402
410
self .options .lights = get_option (opts ,'lights' ,default_lights )
@@ -480,6 +488,9 @@ def __init__(self):
480
488
481
489
self .velocity_curve_ = self .options .velocity_curve
482
490
491
+ self .mouse_mark = glm .ivec2 (0 )
492
+ self .mouse_midi = - 1
493
+
483
494
self .init_board ()
484
495
485
496
# load midi file from command line (playiung it is not yet impl)
@@ -683,6 +694,31 @@ def quit(self):
683
694
self .reset_lights ()
684
695
self .done = True
685
696
697
+ def clear_marks (self , use_lights = False ):
698
+ for row in rows :
699
+ x = 0
700
+ for x in range (len (row )):
701
+ idx = self .get_note_index (x , y )
702
+ self .board [y + self .flipped ][x ] = state
703
+ if use_lights :
704
+ if state :
705
+ self .set_light (x , y , 1 )
706
+ else :
707
+ self .reset_light (x , y )
708
+ y += 1
709
+ self .dirty = True
710
+
711
+ def mark_xy (self , x , y , state , use_lights = False ):
712
+ idx = self .get_note_index (x , y )
713
+ octave = self .get_octave (x , y )
714
+ self .board [y + self .flipped ][x ] = state
715
+ if use_lights :
716
+ if state :
717
+ self .set_light (x , y , 1 )
718
+ else :
719
+ self .reset_light (x , y )
720
+ self .dirty = True
721
+
686
722
def mark (self , midinote , state , use_lights = False , only_row = None ):
687
723
if only_row is not None :
688
724
only_row = self .board_h - only_row - 1 - self .flipped #flip
@@ -746,6 +782,7 @@ def logic(self, dt):
746
782
n -= 12
747
783
self .mark (n + self .vis_octave * 12 , 1 , True )
748
784
data = [0x90 , n , 127 ]
785
+ # TODO: add split for mouse?
749
786
if self .midi_out :
750
787
self .midi_write (self .midi_out , data , 0 )
751
788
except KeyError :
@@ -757,9 +794,30 @@ def logic(self, dt):
757
794
self .mark (n + self .vis_octave * 12 , 0 , True )
758
795
data = [0x80 , n , 0 ]
759
796
if self .midi_out :
797
+ # TODO: add split for mouse?
760
798
self .midi_write (self .midi_out , data , 0 )
761
799
except KeyError :
762
800
pass
801
+ elif ev .type == pygame .MOUSEBUTTONDOWN :
802
+ x , y = ev .pos
803
+ y -= self .menu_sz
804
+ if y >= 0 :
805
+ x /= int (self .button_sz )
806
+ y /= int (self .button_sz )
807
+ x , y = int (x ), int (y )
808
+ self .mark_xy (x , y , True )
809
+ self .mouse_mark = glm .ivec2 (x , y )
810
+ self .mouse_midi = self .xy_to_midi (self .mouse_mark .x , self .mouse_mark .y )
811
+ data = [0x90 , self .mouse_midi , 127 ]
812
+ if self .midi_out :
813
+ self .midi_write (self .midi_out , data , 0 )
814
+ elif ev .type == pygame .MOUSEBUTTONUP :
815
+ if self .mouse_midi != - 1 :
816
+ self .mark_xy (self .mouse_mark .x , self .mouse_mark .y , False )
817
+ data = [0x80 , self .mouse_midi , 127 ]
818
+ if self .midi_out :
819
+ self .midi_write (self .midi_out , data , 0 )
820
+ self .mouse_midi = - 1
763
821
elif ev .type == pygame_gui .UI_BUTTON_PRESSED :
764
822
if ev .ui_element == self .btn_octave_down :
765
823
self .octave -= 1
@@ -797,7 +855,7 @@ def logic(self, dt):
797
855
self .dirty = self .dirty_lights = True
798
856
elif ev .ui_element == self .btn_split :
799
857
self .split_state = not self .split_state
800
- self .btn_split .set_text ("SPLIT: " + ("ON" if SPLIT else "OFF" ))
858
+ self .btn_split .set_text ("SPLIT: " + ("ON" if self . split_state else "OFF" ))
801
859
self .dirty = True
802
860
# elif ev.type == pygame_gui.UI_HORIZONTAL_SLIDER_MOVED:
803
861
# if ev.ui_element == self.slider_velocity:
0 commit comments