音乐21:操作特定乐器

3
我正在使用Python中的Music21读取MIDI文件,并希望只处理使用特定乐器的轨道。 例如,如果我的MIDI文件中有两个使用钢琴的轨道,我希望能够打印音符、更改乐器等。
目前我有一个包含多个轨道(鼓、小号等)的文件,并试图用另一个替代某个特定乐器。然而,当我这样做时,我会收到错误提示并且一些轨道会被完全删除,尽管成功更改了乐器(假设它不是被删除的之一)。
以下是我的当前代码:
from music21 import converter, instrument
s = converter.parse('smells.mid')

s = instrument.partitionByInstrument(s)

s.parts[2].insert(0, instrument.Vocalist())


s.write('midi', 'newfilename.mid')

这是我遇到的错误:

midi.base.py: WARNING: Conversion error for <MidiEvent PROGRAM_CHANGE, t=0, track=1, channel=1>: Got incorrect data for <MidiEvent PROGRAM_CHANGE, t=0, track=1, channel=1> in .data: None,cannot parse Program Change; ignored.

你找到解决方法了吗? - rafaelvalle
@rafaelvalle,我刚刚发布了一个答案,请告诉我它是否有帮助! :) - FatUglyProud
1个回答

1
这是我试图做的事情:
def printInstrument(self, strm, inst):
    s2 = instrument.partitionByInstrument(strm)
    if s2 is not None:
    #print all the notes the instrument plays
        for i in s2.recurse().parts:
            if i.partName == inst:
                iNotes = i.notesAndRests.stream()
                for j in iNotes.elements:
                    if type(j) == chord.Chord:
                        #handle chords
                    elif j.name == "rest":
                        #handle rests
                    else:
                        #handle notes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接