-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_mido_usb.py
More file actions
50 lines (43 loc) · 1.69 KB
/
python_mido_usb.py
File metadata and controls
50 lines (43 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import time
import mido
import ctypes
import sys
import os
import ctypes
import com_ports # to get all com's
import keyboard_translate # to draw gui
import cv2 # to show gui in live mode
def script_path():
currentPath = os.path.realpath(os.path.dirname(sys.argv[0]))
os.chdir(currentPath)
return currentPath
if __name__ == "__main__":
script_path()
names = mido.get_input_names() # search for all ports
outport = mido.open_output() # port to play sound
# outport = mido.open_output('loop1', virtual=True) # you can try with using it and midi_loop app, to create virtual port
print(names)
# *********** GUI part ***********
combinedTop = keyboard_translate.combine_keys_positions(top=True)
combinedBottom = keyboard_translate.combine_keys_positions(top=False)
image = keyboard_translate.create_blank_image(750, 1350)
image = keyboard_translate.draw_around_keyboard(image)
codes = []
with mido.open_input(names[0], virtual=False) as inport:
while True:
msg = inport.receive()
outport.send(msg) # make sound
print(msg)
'''
# get msg code
if msg.type == 'note_on':
codes.append(msg.note)
elif msg.type == 'note_off':
codes.remove(msg.note)
out = keyboard_translate.draw_over_image(image, combinedTop, codes)
out = keyboard_translate.draw_over_image(image, combinedBottom, codes)
cv2.imshow('out', out)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
'''
#cv2.destroyAllWindows()