Simple, Cross Platform MIDI Library for Python [closed]

感情迁移 提交于 2019-12-17 08:48:07

问题


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?


回答1:


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




回答2:


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




回答3:


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.




回答4:


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.




回答5:


I tried eight packages listed on the wiki http://wiki.python.org/moin/PythonInMusic. I found that the one that music21 (http://web.mit.edu/music21/) was

  • the most comprehensive
  • the best tutorial
  • easiest to install on windows

but as to your request for simplicity, I think it's not the simplest one. But I couldn't get any of the other programs to read midi files in a robust way (I have a variety of weird and wonderful midi file formats hanging around)




回答6:


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.




回答7:


Look at cSounds.



来源:https://stackoverflow.com/questions/569321/simple-cross-platform-midi-library-for-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!