4040 (160 , 128 , 224 ),
4141 (192 , 128 , 192 ),
4242 (224 , 128 , 160 )
43- ], dtype = np .int )
43+ ], dtype = np .int32 )
4444
4545def prepare_midi_ins ():
4646 pygame .midi .init ()
@@ -169,11 +169,11 @@ def main():
169169 if midi_event [0 ][0 ] % 16 != 9 : # ignore ch 10
170170 midi_event_type = midi_event [0 ][0 ] // 16
171171
172- if midi_event_type == 9 : # note on
172+ if midi_event_type == 9 and midi_event [ 0 ][ 2 ] > 0 : # note on
173173 keyboard [midi_event [0 ][1 ]].key_on = True
174174 keyboard [midi_event [0 ][1 ]].attack = 1.0
175175 keyboard [midi_event [0 ][1 ]].db = max (math .log (midi_event [0 ][2 ] / 127 ) / math .log (2.0 ) * 6.0 + 96.0 , keyboard [midi_event [0 ][1 ]].db )
176- elif midi_event_type == 8 : # note off
176+ elif midi_event_type == 8 or ( midi_event_type == 9 and midi_event [ 0 ][ 2 ] == 0 ) : # note off
177177 keyboard [midi_event [0 ][1 ]].key_on = False
178178 elif midi_event_type == 11 :
179179 cc_no = midi_event [0 ][1 ]
@@ -225,11 +225,11 @@ def main():
225225
226226 # draw white keybed
227227 for key in [key for key in keyboard [21 :109 ] if not key .black_key ]:
228- screen .fill ((255 , 255 , 255 ) if not key .note_on else tone_color [key .note_no % 12 ], Rect (key .x - white_key_width // 2 , keyboard_top , white_key_width , white_key_height - (base_size // 3 if key .attack > 0.0 else 0 )))
228+ screen .fill ((255 , 255 , 255 ) if not key .key_on else tone_color [key .note_no % 12 ], Rect (key .x - white_key_width // 2 , keyboard_top , white_key_width , white_key_height - (base_size // 3 if key .attack > 0.0 else 0 )))
229229 # draw black keybed
230230 for key in [key for key in keyboard [21 :109 ] if key .black_key ]:
231231 screen .fill ((0 , 0 , 0 ), Rect (key .x - black_key_width // 2 , keyboard_top , black_key_width , black_key_height ))
232- if key .note_on :
232+ if key .key_on :
233233 screen .fill (tone_color [key .note_no % 12 ], Rect (key .x - black_key_width / 2 + line_width , keyboard_top , black_key_width - line_width * 2 , black_key_height - line_width - (base_size // 3 if key .attack > 0.0 else 0 )))
234234
235235 # draw harmony volume
@@ -244,7 +244,7 @@ def main():
244244 overtone_note_no = note_no + math .log (overtone_index ) / math .log (2.0 ) * 12
245245 x2 = note_no_to_x (overtone_note_no )
246246 height = base_size * 4 + math .log (overtone_index ) / math .log (2.0 ) * base_size * 20
247- color = (tone_color [note_no % 12 ] * brightness / 36 ).astype (np .int )
247+ color = (tone_color [note_no % 12 ] * brightness / 36 ).astype (np .int32 )
248248
249249 point = []
250250 resolution = int (x2 - x1 ) // 6
@@ -306,4 +306,4 @@ def main():
306306
307307
308308if __name__ == "__main__" :
309- main ()
309+ main ()
0 commit comments