You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created a test case which calls the quit() and init() functions before get_count() and then the number of ports is updated correctly. However, open MIDI connections are closed which is a problem for my application design.
Testcase:
importpygameimportpygame.midiimporttimedefget_mini_ports():
# Hack to re-initialize MIDI to return updated `get_count()`# Open MIDI connections are closed!pygame.midi.quit()
pygame.midi.init()
midi_ports= []
foriinrange(pygame.midi.get_count()):
(midi_interface, midi_name, midi_input, midi_output, opened) =pygame.midi.get_device_info(i)
midi_interface=midi_interface.decode('utf-8')
midi_name=midi_name.decode('utf-8')
midi_ports.append({
'ID': i,
# 'midi_interface': midi_interface,'midi_name': midi_name,
'midi_input': midi_input,
'midi_output': midi_output,
'opened': opened
})
returnmidi_portsdefprint_mini_ports(portout):
# Send some Sysex dataportout.write_sys_ex(pygame.midi.time(), [0xf0, 0x00, 0x00, 0x00, 0x00, 0xf7])
print('Write before MIDI quit()/init(): OK')
print('MIDI ports: ')
forportinget_mini_ports():
print(' {}'.format(port))
# Send some Sysex dataportout.write_sys_ex(pygame.midi.time(), [0xf0, 0x00, 0x00, 0x00, 0x00, 0xf7])
print('Write after MIDI quit()/init(): OK')
if__name__=='__main__':
# Initialize Pygamepygame.init()
pygame.fastevent.init()
pygame.midi.init()
# Open MIDI portportout=pygame.midi.Output(1)
whileTrue:
print_mini_ports(portout)
time.sleep(1)
I don't think the portmidi backend has hotplugging support, see: mixxxdj/portmidi#8 issuecomment-933869739
Thanks for your confirmation.
It looks like correctly handled by Python https://github.com/mido/mido package, but need to investigate further:
You're right, I used the mido API with backend python-rtmidi. After some additional investigation, I found a bug in python-rtmidi: Incorrect MIDI port names. I reported the bug in mido/mido#381, SpotlightKid/python-rtmidi#111.
So I'll continue with Pygame and implement a workaround where the MIDI ports are not updated after init and connect/disconnect. In this case the user should always disconnect an open MIDI port, then the MIDI ports are updated correctly as you suggested.
The text was updated successfully, but these errors were encountered:
Issue №3301 opened by Erriez at 2022-07-13 19:56:02
Environment:
Current behavior:
The function
pygame.midi.get_count()
always returns the same number of MIDI ports after startup, even after a MIDI device connect/disconnect.Application background: When clicking on a drop-down box, it should update new connected/disconnected MIDI ports.
Expected behavior:
Update number of MIDI ports after connect/disconnect.
Screenshots
N.A.
Test code
Output for example: 2 MIDI ports.
Stack trace/error output/other error logs
N.A.
Comments
# # Starbuck5 commented at 2022-07-14 07:13:49
Would it work if you quit and re init the midi module?
I don't think the portmidi backend has hotplugging support, see: mixxxdj/portmidi#8 issuecomment-933869739
# # Erriez commented at 2022-07-14 11:20:38
I created a test case which calls the
quit()
andinit()
functions beforeget_count()
and then the number of ports is updated correctly. However, open MIDI connections are closed which is a problem for my application design.Testcase:
Thanks for your confirmation.
It looks like correctly handled by Python https://github.com/mido/mido package, but need to investigate further:
# # Starbuck5 commented at 2022-07-15 01:02:54
See, it's funny you say that, since mido says it has three backends:
# # Erriez commented at 2022-07-15 17:31:19
You're right, I used the mido API with backend
python-rtmidi
. After some additional investigation, I found a bug inpython-rtmidi
: Incorrect MIDI port names. I reported the bug in mido/mido#381, SpotlightKid/python-rtmidi#111.So I'll continue with Pygame and implement a workaround where the MIDI ports are not updated after init and connect/disconnect. In this case the user should always disconnect an open MIDI port, then the MIDI ports are updated correctly as you suggested.
The text was updated successfully, but these errors were encountered: