在midi文件中以不同的声音同时发现音符

时间:2014-04-29 11:37:23

标签: midi music21

我有一个由两部分组成的midi文件。现在我需要打印出第0部分(包括休止符)中的每个音符,它们在第1部分中同时发出声音(以及进行此处的音符)。

我可以通过music21查看第0部分中的所有注释,但是如何在第1部分中找到当时的注释。我是否需要使用结束时间?或者有这个功能吗?

for thisNote in s.parts[0].notes:
    print thisNote.ps

1 个答案:

答案 0 :(得分:1)

这是一个非常有趣的功能,让我解决这个问题:

secondPart = s.parts[1]

for thisNote in s.parts[0].notes:


   sys.stdout.write('at ' + str(thisNote.offset) + ' toppitch: ' + str(thisNote.ps))  

   soundingNotes = secondPart.getElementsByOffset(thisNote.offset,  mustFinishInSpan=False, mustBeginInSpan=False)


   try:
     if soundingNotes > 0:
       basslength = len(soundingNotes)

   except: 
     basslength = 0

   if basslength > 1:
     print "oh ow, more then one note sounding in the bass."

   if basslength > 0:
     if soundingNotes[0].isRest:
       sys.stdout.write(' bottompitch: R')
     else:
       sys.stdout.write(' bottompitch: ' + str(soundingNotes[0].ps)) # + ' from ' + str(soundingNotes[0].offset))

     # print the previous note

     soundingNotes2 = secondPart.getElementsByOffset(thisNote.offset-1,  mustFinishInSpan=False, mustBeginInSpan=False)
相关问题