I'm currently working on a project that has some midi processing. For my processing I needed to separate percussive instruments from pitched ones. After I did my processing (transposing the pitched instruments to another key) I need to merge the two back together.
My drums and pitched instruments are saved as midi files. My code is:
pitch_midi = music21.converter.parse(pitch)
drums_midi = music21.converter.parse(drums)
transposed_pitch = pitch_midi.transpose(semitones) # Int Variable
transposed_pitch.append(drums_midi)
transposed_pitch.write('midi', 'Transposed.mid')
The code runs just fine but the saved midi file doesn't include the drum tracks. The type of drums_midi is "<class 'music21.stream.base.Score'> " and the type of the transposed_pitch is "<music21.stream.Score 0x155ad892af0> " and I suspect that this is the problem.
If I do
transposed_midi = transposed_pitch.append(drums_midi)
I get an AttributeError: 'NoneType' object has no attribute 'write'. Which is makes sense since the type of transposed_midi is NoneType.
Any ideas how to overcome that?