SpotlightKid / python-rtmidi

Python bindings for the cross-platform MIDI I/O library RtMidi
https://spotlightkid.github.io/python-rtmidi/
Other
349 stars 65 forks source link

get_ports() returns the empty list #131

Closed davidedelvento closed 1 year ago

davidedelvento commented 1 year ago

This is not strictly a python-rtmidi question, but I hope you can point me in the right direction.

I connect my phone via USB on my Linux desktop box, select MIDI on the phone and everything works fine. In particular, the following shows the phone name:

midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()

I do the same on an embedded platform (Odroid XU4), where I really need to do this (the Desktop is only for development/debugging) and it returns the empty list. The phone still thinks it is connected to a midi device. I suspect I am missing something (perhaps a kernel module?) but I don't know what. Ideas on what it might be?

Thanks in advance!

SpotlightKid commented 1 year ago

The underlying MIDI framework of the OS needs to support the device. What are you running on the Odroid? If it's Linux/ALSA, check whether the device is listed with amidi -l and/or aplay -l, if you're using JACK, check with jack_lsp.

davidedelvento commented 1 year ago

Thanks @SpotlightKid Yes, it's Linux/ALSA. The amidi -l correctly returns the phone as a MIDI device (the way I want to utilize it), and aplay doesn't.

$ amidi -l
Dir Device    Name
IO  hw:1,0,0  SAMSUNG_Android MIDI 1

Kernel modules are identical to the ones in my desktop:

$ lsmod | grep -i mid
snd_seq_midi           16384  0
snd_seq_midi_event     16384  1 snd_seq_midi
snd_seq                57344  2 snd_seq_midi_event,snd_seq_midi
snd_usbmidi_lib        28672  1 snd_usb_audio
snd_rawmidi            28672  2 snd_seq_midi,snd_usbmidi_lib
snd_seq_device         16384  3 snd_seq,snd_rawmidi,snd_seq_midi

Still, empty list from get_ports()

SpotlightKid commented 1 year ago

aplay is for audio. Check aplaymidi -l whether the ALSA sequencer output ports are there.

davidedelvento commented 1 year ago

aplay is for audio. Check aplaymidi -l whether the ALSA sequencer output ports are there.

Yes it is

$ aplaymidi -l
 Port    Client name                      Port name
 14:0    Midi Through                     Midi Through Port-0
 20:0    SAMSUNG_Android                  SAMSUNG_Android MIDI 1
SpotlightKid commented 1 year ago

What does this return?

import rtmidi
rtmidi.get_compiled_api()
davidedelvento commented 1 year ago

What does this return?

import rtmidi
rtmidi.get_compiled_api()

Just [5]

SpotlightKid commented 1 year ago

Then ALSA support was not compiled in. Please check the install instructions in the docs. Make sure you have the ALSA headers/libs installed. If the distro is debian-based, you need to install a special ALSA dev package. Then recompile/-install.

davidedelvento commented 1 year ago

Awesome, that was it. It's now working perfectly. I greatly appreciate your quick response and your patience, @SpotlightKid you are the best!

For others who may land on this issue and wonder about the nitty gritty details, installing the dev package for my distro and recompile rtmidi is a simple matter of

apt install libasound2-dev
pip uninstall python-rtmidi
pip install --no-cache-dir python-rtmidi