Python:MIDI写/读.txt文件

时间:2016-08-02 16:01:36

标签: python midi

我正在尝试将MIDI消息写入.txt文件,然后在程序修改.txt文件后从.txt重新创建MIDI文件。我似乎无法在python-midimido中找到任何方法来从纯文本创建新的MIDI文件。

如果我有下面的代码会给我打印这些MIDI信息,我已将其存储在另一个函数的.txt文件中。

import midi
myFile = midi.read_midifile("song.mid")
print myFile

...

$ python2 test.py 
midi.Pattern(format=1, resolution=480, tracks=\
[midi.Track(\
  [midi.TrackNameEvent(tick=0, text='Espana Op. 165', data=[69, 115, 112, 97, 110, 97, 32, 79, 112, 46, 32, 49, 54, 53]),
   midi.TrackNameEvent(tick=0, text='Prelude', data=[80, 114, 101, 108, 117, 100, 101]),
   midi.CopyrightMetaEvent(tick=0, text='Copyright \xa9 2001 by Bernd Krueger', data=[67, 111, 112, 121, 114, 105, 103, 104, 116, 32, 169, 32, 50, 48, 48, 49, 32, 98, 121, 32, 66, 101, 114, 110, 100, 32, 75, 114, 117, 101, 103, 101, 114]),
   midi.TextMetaEvent(tick=0, text='Isaac Albeniz', data=[73, 115, 97, 97, 99, 32, 65, 108, 98, 101, 110, 105, 122]),
   midi.TextMetaEvent(tick=0, text='Andantino', data=[65, 110, 100, 97, 110, 116, 105, 110, 111]),
   midi.TextMetaEvent(tick=0, text='Fertiggestellt  27.01.2001\n', data=[70, 101, 114, 116, 105, 103, 103, 101, 115, 116, 101, 108, 108, 116, 32, 32, 50, 55, 46, 48, 49, 46, 50, 48, 48, 49, 10]),
   midi.TextMetaEvent(tick=0, text='Update: 18.03.2001\n', data=[85, 112, 100, 97, 116, 101, 58, 32, 49, 56, 46, 48, 51, 46, 50, 48, 48, 49, 10]),
   midi.TextMetaEvent(tick=0, text='Normierung: 23.12.2002\n', data=[78, 111, 114, 109, 105, 101, 114, 117, 110, 103, 58, 32, 50, 51, 46, 49, 50, 46, 50, 48, 48, 50, 10]),
   midi.TextMetaEvent(tick=0, text='Update am 28.10.2010\n', data=[85, 112, 100, 97, 116, 101, 32, 97, 109, 32, 50, 56, 46, 49, 48, 46, 50, 48, 49, 48, 10]),
   midi.TextMetaEvent(tick=0, text='Dauer: 1:36 Minuten\n', data=[68, 97, 117, 101, 114, 58, 32, 49, 58, 51, 54, 32, 77, 105, 110, 117, 116, 101, 110, 10]),
   midi.SmpteOffsetEvent(tick=0, data=[96, 0, 3, 0, 0]),
   midi.TimeSignatureEvent(tick=0, data=[3, 2, 24, 8]),
   midi.KeySignatureEvent(tick=0, data=[255, 0]),
   midi.SetTempoEvent(tick=0, data=[9, 204, 144]),
   midi.SetTempoEvent(tick=480, data=[9, 109, 192]),
   midi.SetTempoEvent(tick=960, data=[8, 152, 180]),
   midi.SetTempoEvent(tick=480, data=[8, 35, 85]),
   midi.SetTempoEvent(tick=240, data=[8, 54, 5]),
   midi.SetTempoEvent(tick=40, data=[7, 254, 241])......... etc.

我现在如何从.txt创建一个新的MIDI文件?

它肯定适用于编写midi.write_midifile("newsong.mid", myFile)但仅因为myFile是midi.Pattern()对象而不是纯文本。

提前致谢!

0 个答案:

没有答案