tags:

views:

140

answers:

5

I want to be able to read events from a MIDI file in Python. I have looked for libraries, but can't find one that works with my MIDI file in windows. I do not need to do anything real time, and just want a simple library that gives me events and times. Would it be easier to write one for myself? Any help would be appreciated.

A: 

Your best bet might be to get a c or c++ library, and interact with it using the Python Extensions for c.

Robert Harvey
+1  A: 

the structure of a midi file is quite simple. if you can't find a ready-made library (i am not aware of any) and you only need events and time, i suggest you try parsing the file yourself.

(prepare for a lot of bit shifting: MIDI data are stored in strings of 7 bits blocks)

also, you say that you can't find a library which works with your MIDI file on Windows: MIDI file are supposed to be portable, and python too, so a un*x lib should work equally well on windows (or the developper missed the point of both MIDI and python).

Adrien Plisson
A: 

if you give jython a try... java is already able of reading and playing midi. Just start searching in the namespace:
javax.sound.midi
if you need more explanation on this, ask again

Oops
A: 

Maybe you can give a look to pygame.midi. It's portable and it contains what you asked about :)

If you don't want to use Pygame, you can study its module midi.py and try to implement by yourself.

Happy working!

Markon
A: 

I once wrote a simple library in pure C to read/write Midifiles. If you want to have a look here it is: http://code.google.com/p/middl/

It is a low level library that ease the task of dealing with midifiles but you should be familiar with the Midi file formaat to use it.

Remo.D