Skip to content

Commit

Permalink
fix for midi devices on rpi
Browse files Browse the repository at this point in the history
  • Loading branch information
misko committed Oct 13, 2024
1 parent ba1d643 commit 8bf4379
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion hudes/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ def __init__(self, use_midi=False):

pg.key.set_repeat(100)
if use_midi:
self.midi_input_id = pygame.midi.get_default_input_id()
device_count = pygame.midi.get_count()
logging.info(f"Number of MIDI devices found: {device_count}")
# List available MIDI devices
for device_id in range(device_count):
device_info = pygame.midi.get_device_info(device_id)
# device_info returns a tuple (interface, name, input, output, opened)
interface, name, is_input, is_output, opened = device_info
if is_input:
name = name.decode("utf-8")
logging.info(f"Device ID {device_id}: {name}")
if "x-touch" in name.lower() or "xtouch" in name.lower():
self.midi_input_id = device_id
logging.info(f"using input_id :{self.midi_input_id}:")
self.midi_input = pygame.midi.Input(self.midi_input_id)

Expand Down

0 comments on commit 8bf4379

Please sign in to comment.