Jul-06-2019, 11:39 AM
I am trying to manipulate a midi file using python. For now, I would be happy if I could simply increase one note by one increment.
I know this is a very basic python problem but I do not know exactly how to search for an answer here. I can import a midi file, I can print a midi file, I can create a midi file from scratch but I cannot seem to make changes to the file. There are many online tutorials that show how to change variables but I cannot seem to parse apart the midi file in order to edit it. I am currently using Google Colab notebooks.
I am using mido to get the file into python
I know this is a very basic python problem but I do not know exactly how to search for an answer here. I can import a midi file, I can print a midi file, I can create a midi file from scratch but I cannot seem to make changes to the file. There are many online tutorials that show how to change variables but I cannot seem to parse apart the midi file in order to edit it. I am currently using Google Colab notebooks.
I am using mido to get the file into python
from mido import MidiFile mid = MidiFile('test.mid')Print it:
for i, track in enumerate(mid.tracks): print('Track {}: {}'.format(i, track.name)) for msg in track: print(msg)I get something like this:
Output:Track 0: �
<meta message track_name name=u'\x00' time=0>
<meta message time_signature numerator=4 denominator=4 clocks_per_click=36 notated_32nd_notes_per_beat=8 time=0>
<meta message time_signature numerator=4 denominator=4 clocks_per_click=36 notated_32nd_notes_per_beat=8 time=0>
note_on channel=0 note=36 velocity=100 time=0
note_off channel=0 note=36 velocity=64 time=96
note_on channel=0 note=40 velocity=100 time=0
note_off channel=0 note=40 velocity=64 time=96
note_on channel=0 note=43 velocity=100 time=0
note_off channel=0 note=43 velocity=64 time=96
note_on channel=0 note=45 velocity=100 time=0
note_off channel=0 note=45 velocity=64 time=96
<meta message end_of_track time=0>
I would love to know how to manipulate this. Initially to simply to increase one of the notes by 1 increment.