music21:从一个平谱中获得midi声音的声音/程序/乐器



我有一个简单的脚本,它使用music21来处理midi文件中的音符:

import music21
score = music21.converter.parse('www.vgmusic.com/music/console/nintendo/nes/zanac1a.mid')
for i in score.flat.notes:

print(i.offset, i.quarterLength, i.pitch.midi)

有没有一种方法也可以使用统一的分数来获得音符的voicing/midi程序?任何建议都将不胜感激!

MIDI通道和程序存储在Instrument实例上,因此使用getContextByClass(instrument.Instrument)在流中查找最近的乐器,然后访问其.midProgram.

小心:

  • .midiChannel.midiProgram是0索引的,因此MIDI通道10在music21等中将是9,(我们将在下一版本中讨论更改此行为(
  • 如果你没有运行出血边缘版本(我们昨天合并了一个关于这个主题的补丁(,一些信息可能会丢失,所以我建议从git:pip install git+https://github.com/cuthbertLab/music21
  • 不过,如果文件是多音轨的,.flat会杀死你的。如果你听从我的建议,你只会在每首曲目上找到最后一个乐器。90%的时候,做.flat的人实际上想要.recurse()

最新更新