tags:

views:

2028

answers:

6

I want to do build a small app that creates MIDI sounds. I've never dealt with sound in programming so I'd like to start with something that's basic and has good documentation. I want to stick with Python since I'm the most comfortable with it and don't want to overwhelm myself, initially.

My time is split about 50/50 between Windows and Ubuntu so something that "just works" on both platforms would be really helpful.

Any suggestions?

+2  A: 

pyPortMidi is a Python wrapper of PortMidi, which is described as a "a cross-platform C library for realtime MIDI control". I haven't used it myself, but it looks very promising. Explicit mention of being able to send MIDI data in realtime.

unwind
A: 

Look at cSounds.

S.Lott
+1  A: 

Midi support (in and out) has been added to pyGame 1.9, though it's mainly in the development stage and isn't very well documented yet, but it works.

Midi support is also being developed in the pyGame successor, pgreloaded (or pygame2).

Also note that even though pyGame has 'game' in the title, its uses stretch far beyond just game design.

Aaron
+2  A: 

I was looking for a pure-Python library to generate a MIDI file, mxm's Python MIDI library is exactly that.

From this dzone snippet, there is a single-file version of the above library, smidi.py (gist'd here for posterity)

Usage is quite simple:

>>> import smidi
>>> m = smidi.MidiOutFile('out.mid')
>>> m.header()
>>> m.start_of_track()
>>> m.update_time(0)
>>> m.note_on(note=0x40)  # single note
>>> m.update_time(192)
>>> m.note_off(note=0x40) # stop it after 192
>>> m.update_time(0)
>>> m.end_of_track()
>>> m.eof()

Presumably works on Windows (as the original example uses C:\out.mid as the output filename), and I've tested it on OS X

dbr
+3  A: 

The MIDIUtil Library (hosted here at Google Code) does what you want: write MIDI Files from a pure Python library. Once nice thing about it (and full disclosure: I'm the author) is that you don't have to keep track of lower-level MID events such as note-on and note-off: it handles them for you.

As an example to write a note, you would do something like:

MyMIDI = MIDIFile(1)
track = 0
channel = 0
pitch = 60
time = 0
duration = 1
volume = 100
MyMIDI.addNote(track,channel,pitch,time,duration,volume)

Hope this helps

Mark
A: 

If you only need to generate Midi or process midi files, try mingus, It's a great package and it also allows much higher abstractions such as chords, chord progressions, scales and so on.

fccoelho