Find a device by name
from rtmidi import MidiIn, MidiOut
from time import sleep
midiin = MidiIn()
for i in range(midiin.get_port_count()):
name = midiin.get_port_name(i)
in_name_to_number = { midiin.get_port_name(i):i for i in range(midiin.get_port_count()) }
in_matches = lambda t: [ x for x in in_name_to_number if t.lower() in x.lower() ]
in_matches_idx = lambda t: [ midiin_name_to_number[x] for x in in_matches(t) ]
in_ports = in_matches("midi mix")
print(in_ports)
def callback(msg,*xs):
msg, ts = msg
print(f"{msg=} {ts=}")
midiin.set_callback(callback)
if len(in_ports) > 0:
midiin.open_port(in_name_to_number[in_ports[0]])
try:
while True:
sleep(1)
except KeyboardInterrupt:
print(f"Ctrl-C")
exit(0)