适用于 Python 的简单跨平台 MIDI 库

发布于 2024-07-13 21:09:32 字数 197 浏览 9 评论 0原文

我想构建一个创建 MIDI 声音的小应用程序。 我从来没有在编程中处理过声音,所以我想从一些基本的并且有良好文档的东西开始。 我想坚持使用 Python,因为我对它最熟悉,并且一开始不想让自己不知所措。

我的时间在 Windows 和 Ubuntu 上各占一半,所以在这两个平台上“都能正常工作”的东西会非常有帮助。

有什么建议么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

是你 2024-07-20 21:09:32

MIDIUtil 库(托管在 Google 代码此处)可实现您想要的功能:从纯Python库。 它的一个好处(并且完全公开:我是作者)是您不必跟踪较低级别的 MID 事件,例如音符打开和音符关闭:它会为您处理它们。

作为写注释的示例,您可以执行以下操作:

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

希望这有帮助

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

还不是爱你 2024-07-20 21:09:32

我正在寻找一个纯Python库来生成MIDI文件,mxm的Python MIDI库正是如此。

这个 dzone 片段 中,有一个上述库的单文件版本,smidi.py (gist'd here 供后代使用)

用法非常简单:

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

大概适用于 Windows(因为原始示例使用 C:\out.mid 作为输出文件名) ,我已经在 OS X 上测试过了

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

尝蛊 2024-07-20 21:09:32

pyPortMidi 是 PortMidi 的 Python 包装器,它被描述为“一个交叉- 用于实时 MIDI 控制的平台 C 库”。 我自己还没有使用过它,但它看起来很有前途。 明确提到能够实时发送 MIDI 数据。

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.

清风不识月 2024-07-20 21:09:32

如果您只需要生成 Midi 或处理 midi 文件,请尝试 mingus
这是一个很棒的软件包,它还允许更高的抽象,例如和弦、和弦进行、音阶等等。

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.

浸婚纱 2024-07-20 21:09:32

我尝试了 wiki http://wiki.python.org/moin/PythonInMusic 上列出的八个软件包。
我发现 music21 (http://web.mit.edu/music21/) 是

  • 最全面、
  • 最好的教程,
  • 最容易在 Windows 上安装

,但就您对简单性的要求而言,我认为这不是最简单的。 但我无法让任何其他程序以可靠的方式读取 MIDI 文件(我有各种奇怪而美妙的 MIDI 文件格式)

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)

很酷又爱笑 2024-07-20 21:09:32

pyGame 1.9 中添加了 Midi 支持(输入和输出),尽管它主要处于开发阶段并且尚未有很好的文档记录,但它确实有效。

pyGame 的后继者 pgreloaded(或 pygame2)也正在开发 Midi 支持。

另请注意,尽管 pyGame 的标题中有“游戏”,但它的用途远远超出了游戏设计的范围。

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.

暗喜 2024-07-20 21:09:32

查看 cSounds

Look at cSounds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文