简体   繁体   English

用Python读取MIDI文件

[英]Reading a MIDI file in Python

I want to be able to read events from a MIDI file in Python. 我希望能够从Python中读取MIDI文件中的事件。 I have looked for libraries, but can't find one that works with my MIDI file in windows. 我已经找了库,但是在Windows中找不到与我的MIDI文件一起使用的库。 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. 任何帮助,将不胜感激。

the structure of a midi file is quite simple. midi文件的结构非常简单。 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) (准备大量的位移:MIDI数据存储在7位块的字符串中)

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). 另外,你说你找不到一个可以在Windows上使用你的MIDI文件的库:MIDI文件应该是可移植的,而python也是如此,所以un * x lib在windows上同样运行良好(或者缺少开发者) MIDI和python的重点)。

Check out this python library on github, it seems to do exactly what you need: 看看github上的这个python库,它似乎完全符合你的需要:

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

有一个名为mido的库,适合阅读这些文件: https ://pypi.python.org/pypi/mido/1.1.11

I once wrote a simple library in pure C to read/write Midifiles. 我曾经用纯C编写了一个简单的库来读/写Midifiles。 If you want to have a look here it is: http://code.google.com/p/middl/ 如果您想查看此处,请访问: 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. 它是一个低级库,可以简化处理midifiles的任务,但是你应该熟悉Midi文件格式来使用它。

您最好的选择可能是获取ac或c ++库,并使用Python Extensions for c进行交互

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM