Python and MIDI

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
^rooker
Site Admin
Posts: 1484
Joined: Fri Aug 29, 2003 8:39 pm

Python and MIDI

Post by ^rooker »

I'm currently trying to add MIDI support to serial-pyio, but I couldn't find any "this is *the* one" MIDI module that is OS independent.

The closest one seems to be "PySndObj" (a Python wrapper for SndObj)

Currently, only v1.02 seems to be available for all platforms. I learned that the hard way, because for v1.3, the sourceforge download page offers 3 files - but the one with "Linux" in its name is actually for Linux on PPC (!!).

Here's what you get if you accidentially try to run that version on i386 hardware:
_sndobj.so: ELF file data encoding not little-endian
User avatar
^rooker
Site Admin
Posts: 1484
Joined: Fri Aug 29, 2003 8:39 pm

PySndObj is a dead end - long live "PyPortMidi"?

Post by ^rooker »

Unfortunately, PySndObj was a dead end for realtime MIDI input/output handling - it seems to have only 2 objects for MIDI at all:
MidiMap and MidiIn.

I needed something like "MidiOut". :x

However, I found "PyPortMidi" which might be able to do what I want.

Unfortunately, it won't compile with Python 2.5, exiting with the following error:
pypm.pyx:357:21: Type 'PmError' not acceptable as a boolean
Here's info for a patch, lucky-me found in gmane.comp.python.pygame archive:
Yeah. To make Pyrex compatible with C++ enumerations are no longer treated as integers, though assignment of an enumeration to an integer
is still allowd. Not accepting an enumeration as a boolean value may be a bug. I would have to check. But then again it makes some sense. Just edit line 357 to be:

while(Pm_Poll(self.midi) != pmNoError):
User avatar
^rooker
Site Admin
Posts: 1484
Joined: Fri Aug 29, 2003 8:39 pm

Debian package!

Post by ^rooker »

I've created a proper Debian package for pyPortMidi:
python-pyportmidi_0.0.3.1-1_i386.deb

Built on Ubuntu Hardy, 32bit.
It contains binaries for Python 2.4 and 2.5

It should work on any Debian based system, as long as the version requirements of its dependencies are met. I've (again) learned a lot about Debian packaging, since Python packags are different - and even a bit more complicated when it's an extension.
User avatar
^rooker
Site Admin
Posts: 1484
Joined: Fri Aug 29, 2003 8:39 pm

pyPortMidi problems

Post by ^rooker »

(Py)PortMidi errors I've encountered - and possible solutions:
PortMidi call failed...
PortMidi: `Bad pointer'
type ENTER...
Double-assigning a midi port led to this error:

Code: Select all

import pypm
pypm.Initialize()
MidiIn1 = pypm.Input(1)
MidiIn2 = pypm.Input(1)
This means that calling a function for assigning a port will fail when run twice with the same device:

Code: Select all

def setMidiInput(device):
   MidiIn = pypm.Input(device)
This case can be avoided by freeing previous references:

Code: Select all

def setMidiInput(device):
   MidiIn = None # <- This calls the deconstructor of the previous assignment.
   MidiIn = pypm.Input(device)
Post Reply