从python中文件提取每个乐器的注释

时间:2019-11-19 17:32:46

标签: python midi

我正在尝试通过乐器从中间文件中提取所有音符。 有人问了这个问题:“ Music21: Get all Notes per Instrument from a MIDI File”,但是答案不对。缺少一些笔记。

在我的中间文件中,使用了日语的“尺八”,但是在执行以下代码时什么也没打印:

PATH_FILE = 'my_file.mid'
piece = converter.parse(PATH_FILE)

s2 = instrument.partitionByInstrument(piece)
if s2 is not None:
   for i in s2.recurse().parts:
       if i.partName == "Shakuhachi":
           iNotes = i.notesAndRests.stream()
           for note in iNotes:
               print(note)

midi文件中使用了6种乐器,但是我只能从Piano乐器中提取音符。 代码是否有问题,或者是否有其他技术可以在给定乐器的情况下提取音符?

![Here is a view from the software Logic Pro X, showing that the Shakuhashi is used : ] 1

0 个答案:

没有答案