我在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.发布于 2018-06-24 19:11:53
以下是我想做的事:
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 noteshttps://stackoverflow.com/questions/47556847
复制相似问题