无法在Midi文件中写入“其余”对象

时间:2019-05-12 19:54:45

标签: python deep-learning music21

我有一个包含几个'notes','chords'和'rest'对象的列表,并试图将它们写入midi文件。我正在尝试以下代码

midi_stream = stream.Stream(output_notes)
midi_stream.write('midi', fp='test_output.mid')

在读取创建的midi文件时,我发现没有'rest'对象附加在midi文件中。

output_notes变量的内容为:

 <music21.note.Rest rest> <music21.chord.Chord A1 E2>
 <music21.chord.Chord A1 E2> <music21.chord.Chord A1 E2>
 <music21.note.Rest rest> <music21.chord.Chord A1 E2>
 <music21.note.Rest rest> <music21.note.Rest rest>
 <music21.chord.Chord A1 E2> <music21.chord.Chord A1 E2>
 <music21.note.Rest rest> <music21.note.Rest rest>
 <music21.note.Rest rest> <music21.note.Note A> <music21.note.Rest rest>
 <music21.note.Rest rest> <music21.note.Note A> <music21.note.Rest rest>
 <music21.note.Rest rest> <music21.note.Rest rest> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Rest rest> <music21.note.Rest rest>
 <music21.note.Rest rest> <music21.chord.Chord A4 C#5 F5>
 <music21.note.Rest rest> <music21.note.Rest rest>
 <music21.chord.Chord A4 C#5 F5> <music21.note.Note B>
 <music21.note.Rest rest> <music21.note.Rest rest>
 <music21.note.Rest rest> <music21.note.Rest rest>
 <music21.chord.Chord A4 C#5 F5> <music21.note.Rest rest>
 <music21.chord.Chord A4 C#5 F5> <music21.note.Rest rest>
 <music21.chord.Chord A4 C#5 F5> <music21.note.Rest rest>
 <music21.note.Rest rest> <music21.chord.Chord G4 B4 D5>
 <music21.chord.Chord F#4 B4 D5> <music21.chord.Chord F#4 B4 D5>
 <music21.chord.Chord F#4 B4 D5> <music21.chord.Chord F#4 B4 D5>
 <music21.note.Note C#> <music21.note.Rest rest> <music21.note.Rest rest>
 <music21.chord.Chord F#4 B4 D5> <music21.note.Rest rest>
 <music21.note.Rest rest> <music21.chord.Chord E3 A3>
 <music21.note.Rest rest> <music21.note.Note C> <music21.note.Rest rest>
 <music21.note.Rest rest> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.chord.Chord C3 G3>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.chord.Chord C3 G3> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Rest rest> <music21.note.Note G>
 <music21.chord.Chord C3 G3> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.chord.Chord C3 G3> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.chord.Chord C3 G3>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.chord.Chord C3 G3> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.chord.Chord C3 G3>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.chord.Chord C3 G3> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.chord.Chord C3 G3>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.chord.Chord C3 G3>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G>]

创建的midi文件中的内容为:

[<music21.chord.Chord A1 E2> <music21.chord.Chord A1 E2>
 <music21.chord.Chord A1 E2> <music21.chord.Chord A1 E2>
 <music21.chord.Chord A1 E2> <music21.note.Note A> <music21.note.Note G>
 <music21.note.Note G> <music21.chord.Chord A4 C#5 F5>
 <music21.note.Note B> <music21.chord.Chord A4 C#5 F5>
 <music21.chord.Chord A4 C#5 F5> <music21.note.Note G>
 <music21.chord.Chord B4 D5> <music21.note.Note F#>
 <music21.chord.Chord B4 D5> <music21.note.Note F#>
 <music21.chord.Chord B4 D5> <music21.note.Note C#>
 <music21.chord.Chord F#4 B4 D5> <music21.chord.Chord E3 A3>
 <music21.note.Note C> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.chord.Chord C3 G3> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.chord.Chord C3 G3>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.chord.Chord C3 G3>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.chord.Chord C3 G3> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.chord.Chord C3 G3>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.chord.Chord C3 G3>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.chord.Chord C3 G3> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.chord.Chord C3 G3> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.chord.Chord C3 G3> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.chord.Chord C3 G3> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G> <music21.note.Note G> <music21.note.Note G>
 <music21.note.Note G>]

1 个答案:

答案 0 :(得分:0)

您要做的是获取一个music21流,将其转换为MIDI,然后将其转换回music21流,您会惊讶地发现往返过程并没有给您将获得与原始输入相同的输出。

但是,如果您要将Excel电子表格转换为.csv然后返回,我想您不会感到惊讶。

您所做的假设是music21和MIDI是两个等效的符号。他们不是。 music21面向分数分析。它了解音符,休止符,小节,键签名和谱号(以及更多)。

另一方面,

MIDI是面向合成器的播放指令集。想一想您会在某些合成器程序中看到的钢琴卷符号,例如: piano-roll notation

黑色水平条纹表示所演奏的音符。但是其余在哪里?没有任何区别,因为对整个乐段而言无声的音符与在酒吧中因小腿/四分音符的长度而被静音打断的音符之间没有区别。这就是为什么我在评论中说MIDI实际上没有任何休息的原因。休息仅是为了向玩家显示不在酒吧弹奏音符的位置。但是MIDI对小节一无所知(如果您在MIDI文件中看到小节,它们本质上就是注释),因此也不需要休息。当music21从MIDI导入时,它会尽力而为,但是猜测没有音符应该在哪里休息是非常棘手的,如果music21不这样做,您也不会感到惊讶随心所欲。

MIDI是一种非常不丰富的音乐表达媒介,因为它用对人类有意义的符号代替了对目标乐器的直接原始控制。如果您所要做的只是在邮件的备注编号中添加2(或1,具体取决于上下文),则不需要双重清晰度符号。这就是为什么从music21转换为MIDI并转换回MIDI的原因有点像将电子表格写为.csv然后读回来。许多信息丢失了。

实际上,不存在与应用程序无关的音乐符号标准,它当然不是MIDI。 MusicXML试图做到这一点,但并不能涵盖所有内容,因为您会发现是否使用它在musci21,Sibelius和Dorico之间进行转换。实际上,Dorico会忽略MusicXML中的一些空格符号,因为它认为自己可以做得更好。

对MIDI文件中是否没有休息的真实测试是播放MIDI文件,而不是将其转换为其他表示法并将其视为MIDI中内容的代理文件。您能听到文件中没有休息吗?演奏的输出声音是否与原始声音不同(忽略乐器,音色,速度和类似音色等非音符属性)?