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

时间:2022-11-29 12:14:27

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.

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

My time is split about 50/50 between Windows and Ubuntu so something that "just works" on both platforms would be really helpful.

我的时间在Windows和Ubuntu之间分成大约50/50,因此在两个平台上“正常工作”的东西真的很有帮助。

Any suggestions?

7 个解决方案

#1


34  

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.

MIDIUtil库(在Google Code上托管)可以满足您的需求:从纯Python库中编写MIDI文件。关于它的一件好事(并且完全披露:我是作者)是你不必跟踪低级MID事件,例如音符开和音符关:它会为你处理它们。

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


10  

I was looking for a pure-Python library to generate a MIDI file, mxm's Python MIDI library is exactly that.

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

From this dzone snippet, there is a single-file version of the above library, smidi.py (gist'd here for posterity)

从这个dzone片段中,有一个上面的库的单文件版本,smidi.py(这里为后代写的)

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

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

#3


8  

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.

pyPortMidi是PortMidi的Python包装器,被描述为“用于实时MIDI控制的跨平台C库”。我自己没有用它,但它看起来非常有前景。明确提到能够实时发送MIDI数据。

#4


7  

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.

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

#5


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

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

  • the most comprehensive
  • 最全面的

  • the best tutorial
  • 最好的教程

  • easiest to install on windows
  • 最容易在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)

但至于你的简单要求,我认为这不是最简单的。但我无法让任何其他程序以健壮的方式阅读midi文件(我有各种奇怪和精彩的midi文件格式)

#6


4  

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支持(in和out)已被添加到pyGame 1.9中,虽然它主要处于开发阶段,但尚未有很好的文档记录,但它有效。

Midi support is also being developed in the pyGame successor, pgreloaded (or pygame2).

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

Also note that even though pyGame has 'game' in the title, its uses stretch far beyond just game design.

另请注意,尽管pyGame在标题中有“游戏”,但它的用途远不止游戏设计。

#7


-3  

Look at cSounds.

看看cSounds。

#1


34  

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.

MIDIUtil库(在Google Code上托管)可以满足您的需求:从纯Python库中编写MIDI文件。关于它的一件好事(并且完全披露:我是作者)是你不必跟踪低级MID事件,例如音符开和音符关:它会为你处理它们。

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


10  

I was looking for a pure-Python library to generate a MIDI file, mxm's Python MIDI library is exactly that.

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

From this dzone snippet, there is a single-file version of the above library, smidi.py (gist'd here for posterity)

从这个dzone片段中,有一个上面的库的单文件版本,smidi.py(这里为后代写的)

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

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

#3


8  

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.

pyPortMidi是PortMidi的Python包装器,被描述为“用于实时MIDI控制的跨平台C库”。我自己没有用它,但它看起来非常有前景。明确提到能够实时发送MIDI数据。

#4


7  

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.

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

#5


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

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

  • the most comprehensive
  • 最全面的

  • the best tutorial
  • 最好的教程

  • easiest to install on windows
  • 最容易在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)

但至于你的简单要求,我认为这不是最简单的。但我无法让任何其他程序以健壮的方式阅读midi文件(我有各种奇怪和精彩的midi文件格式)

#6


4  

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支持(in和out)已被添加到pyGame 1.9中,虽然它主要处于开发阶段,但尚未有很好的文档记录,但它有效。

Midi support is also being developed in the pyGame successor, pgreloaded (or pygame2).

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

Also note that even though pyGame has 'game' in the title, its uses stretch far beyond just game design.

另请注意,尽管pyGame在标题中有“游戏”,但它的用途远不止游戏设计。

#7


-3  

Look at cSounds.

看看cSounds。