Reading a MIDI file in Python

给你一囗甜甜゛ 提交于 2019-12-07 00:18:15

问题


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.


回答1:


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).




回答2:


Check out this python library on github, it seems to do exactly what you need:

https://github.com/vishnubob/python-midi




回答3:


There is a library called mido which is good for reading these files: https://pypi.python.org/pypi/mido/1.1.11




回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/2933938/reading-a-midi-file-in-python

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