实时获取MIDI设备输入(Python)
我有一个触发手指(MIDI平板),我想实时读取它的输入,然后让Python根据按下的键执行相应的操作。
我需要这个功能在Windows上运行,最好是能和Python 2.5及以上版本兼容。
谢谢!
1 个回答
12
PyGame 自带一个 MIDI模块,可以在Linux、Windows和MacOS上使用,而且支持得很好。
比如,这里有关于 pygame.midi.Input 的文档:
Input is used to get midi input from midi devices.
Input(device_id)
Input(device_id, buffer_size)
Input.close - closes a midi stream, flushing any pending buffers. closes a midi stream, flushing any pending buffers.
Input.poll - returns true if there's data, or false if not. returns true if there's data, or false if not.
Input.read - reads num_events midi events from the buffer. reads num_events midi events from the buffer.
如果你想找其他的选择,可以看看 PythonInMusic,这是Python的一个维基页面。
那里有很多与MIDI输入和输出相关的项目,有些也适用于Windows。(点击每个项目后面的小 > 符号,可以跳转到项目主页)
我个人没有使用过这些项目,但我相信它们能帮助你入门。