MIDI in Python / PyGame, Ubuntu 12.04

Trying to get a MIDI interface to work with pygame on Ubuntu 12.04. I know that the keyboard works because it can control vkeybd and work with PyGame on OSX, so there is a MIDI problem in python.

$ python -m pygame.examples.midi --list Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/usr/lib/python2.7/dist-packages/pygame/examples/midi.py", line 820, in <module> print_device_info() File "/usr/lib/python2.7/dist-packages/pygame/examples/midi.py", line 25, in print_device_info pygame.midi.init() File "/usr/lib/python2.7/dist-packages/pygame/midi.py", line 71, in init import pygame.pypm ImportError: /usr/lib/libportmidi.so.0: undefined symbol: snd_seq_event_input_pending 

python-pygame is installed through the package manager, just like python-pm.

Any ideas? :)

+6
source share
3 answers

Although this will not answer your question exactly, it can help you debug the problem yourself.

Error:

 ImportError: /usr/lib/libportmidi.so.0: undefined symbol: snd_seq_event_input_pending 

undefined symbol is a dynamic linker refusal to find the code needed for the snd_seq_event_input_pending function.

In the example of the Oneiric 32-bit system, we can do this to look at some symbols of libportmidi.so.0 .

 nm -DC /usr/lib/libportmidi.so.0 | grep snd_seq_event_input_pending U snd_seq_event_input_pending 

This tells us that the libportmidi library requires code for snd_seq_event_input_pending , but the character is undefined. Therefore, for the libportmidi function libportmidi it must also load an additional library that contains this function.

In Oneiric, I found that this symbol is defined in libasound2.so.2 .

 nm -DC /usr/lib/i386-linux-gnu/libasound.so.2 | grep snd_seq_event_input_pending 000a0fa0 T snd_seq_event_input_pending 

T indicates that the function exists and is in the text (code) segment.

The linking of linked libraries is usually automatic, since libasound.so.2 should be referenced by libportmidi . In the same system.

 ldd /usr/lib/libportmidi.so.0 .... libasound.so.2 => /usr/lib/i386-linux-gnu/libasound.so.2 (0x00e35000) 

which shows that libmidi dependent on libasound . There is no link to libasound in the comments list of ldd in your comments, and therefore it will not try to automatically link libasound.so.2 when it is loaded, which will lead to an error.

There are several reasons why this error may occur:

  • The libportmidi related libportmidi may vary from Oneiric to Precise. for example, libportmidi might try to find its own dependencies for libasound . (Unlikely).
  • There is an error in the libportmidi package where it does not reference libasound.so.2 as follows. This may be platform specific (for example, only an error on 64-bit systems).

I suggest you try finding a library on your system that contains the snd_seq_event_input_pending function, and then working back to try and determine why it was not related to libportmidi .

The following bash command will help you find libraries that implement snd_seq_event_input_pending . If you did not find anything, there is a problem with the libraries installed on your computer.

 find /lib /usr/lib -name "lib*.so.*" | while read f; do if nm -DC "$f" | grep -q 'T snd_seq_event_input_pending'; then echo "$f" fi done 
+4
source

I have exactly the same problem (on Ubuntu 12.04.1), using for example the MIDI playback tool in Frescobaldi (which is a Python application). This works well, but no longer works.

This is a rather explicitly unusual portmidi package that was pushed out on 2013-01-25, see https://launchpad.net/ubuntu/+source/portmidi/1:200-0ubuntu1.12.04.1 . Switching to the previous package 1: 200-0ubuntu1 solved the problem for me.

I guess the correct course of action would be to file a bug report in version 1: 200-0ubuntu1.12.04.1 on Launchpad at https://bugs.launchpad.net/ubuntu/+source/portmidi/+bugs . If it is not fixed, we can also ask falkTX if he wants to provide a working package in his KXStudio PPAs.

Just for the record, here is what ldd gives for 1: 200-0ubuntu1 libportmidi on my system:

 linux-vdso.so.1 => (0x00007fffe9bff000) libasound.so.2 => /usr/lib/x86_64-linux-gnu/libasound.so.2 (0x00007f26264cb000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f26262ae000) libporttime.so.0 => /usr/lib/libporttime.so.0 (0x00007f26260ab000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2625cec000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f26259f0000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f26257eb000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f26255e3000) /lib64/ld-linux-x86-64.so.2 (0x00007f26269f4000) 

And the broken version 1: 200-0ubuntu1.12.04.1:

 linux-vdso.so.1 => (0x00007fff9e3ff000) libporttime.so.0 => /usr/lib/libporttime.so.0 (0x00007fb84ac71000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb84a8b2000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb84a694000) /lib64/ld-linux-x86-64.so.2 (0x00007fb84b0af000) 

Thus, any application that does not communicate with libasound2 in itself will be closed. In particular, this is similar to the Python portmidi module. (This error is also exacerbated by the fact that, at least since Ubuntu 12.04, gcc uses the -as-required linker flag by default. I am sure that there are still several packages in the Ubuntu repositories because of this.)

+1
source

If you want to fix this now, you can check the latest version of portmidi and build the library as follows (assuming you checked out or unpacked portmidi in the portmidi directory):

 cd portmidi make -f pm_linux/Makefile 

The default installation does not create a dynamic version of the library, so you need to build it like this:

 gcc -shared -Wl,-soname,libportmidi.so.0 -o pm_linux/libportmidi.so.0 pm_common/pmutil.o pm_linux/pmlinuxalsa.o pm_linux/pmlinux.o pm_common/portmidi.o -lasound 

Then you can make a copy of the old library (just in case), and then copy it to its place:

 sudo cp /usr/lib/libportmidi.so.0 /usr/lib/libportmidi.so.0.orig sudo cp pm_linux/libportmidi.so.0 /usr/lib/libportmidi.so.0 

Your applications should now work ...

+1
source

All Articles