Python Forum

Full Version: mido MIDI-file; how to distinguis tracks?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I did already some code which prints all midi messages in a dict using mido. This is the result of a test midi-file:

{'type': 'time_signature', 'numerator': 4, 'denominator': 4, 'clocks_per_click': 24, 'notated_32nd_notes_per_beat': 8, 'time': 0}
{'type': 'set_tempo', 'tempo': 500000, 'time': 0}
{'type': 'track_name', 'name': 'Tempo Track', 'time': 0}
{'type': 'track_name', 'name': 'Right', 'time': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 60, 'velocity': 100}
{'type': 'track_name', 'name': 'Left', 'time': 0}
{'type': 'note_on', 'time': 0, 'channel': 1, 'note': 48, 'velocity': 100}
{'type': 'note_off', 'time': 0.5, 'channel': 0, 'note': 60, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 67, 'velocity': 100}
{'type': 'note_off', 'time': 0.25, 'channel': 0, 'note': 67, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 65, 'velocity': 100}
{'type': 'note_off', 'time': 0, 'channel': 1, 'note': 48, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 1, 'note': 50, 'velocity': 100}
{'type': 'note_off', 'time': 0.25, 'channel': 0, 'note': 65, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 64, 'velocity': 100}
{'type': 'note_off', 'time': 0, 'channel': 1, 'note': 50, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 1, 'note': 52, 'velocity': 100}
{'type': 'note_off', 'time': 0.5, 'channel': 0, 'note': 64, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 62, 'velocity': 100}
{'type': 'note_off', 'time': 0, 'channel': 1, 'note': 52, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 1, 'note': 55, 'velocity': 100}
{'type': 'note_off', 'time': 0.25, 'channel': 0, 'note': 62, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 60, 'velocity': 100}
{'type': 'set_tempo', 'tempo': 600000, 'time': 0.25}
{'type': 'note_off', 'time': 0, 'channel': 0, 'note': 60, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 62, 'velocity': 100}
{'type': 'note_off', 'time': 0, 'channel': 1, 'note': 55, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 1, 'note': 53, 'velocity': 100}
{'type': 'note_off', 'time': 0.6, 'channel': 0, 'note': 62, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 57, 'velocity': 100}
{'type': 'note_off', 'time': 0.6, 'channel': 1, 'note': 53, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 1, 'note': 55, 'velocity': 100}
{'type': 'note_off', 'time': 0.6, 'channel': 1, 'note': 55, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 1, 'note': 53, 'velocity': 100}
{'type': 'note_off', 'time': 0.3, 'channel': 1, 'note': 53, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 1, 'note': 52, 'velocity': 100}
{'type': 'time_signature', 'numerator': 3, 'denominator': 8, 'clocks_per_click': 24, 'notated_32nd_notes_per_beat': 8, 'time': 0.3}
{'type': 'note_off', 'time': 0, 'channel': 0, 'note': 57, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 57, 'velocity': 100}
{'type': 'note_off', 'time': 0, 'channel': 1, 'note': 52, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 1, 'note': 50, 'velocity': 100}
{'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 57, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 65, 'velocity': 100}
{'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 65, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 64, 'velocity': 100}
{'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 64, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 62, 'velocity': 100}
{'type': 'note_off', 'time': 0, 'channel': 1, 'note': 50, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 1, 'note': 55, 'velocity': 100}
{'type': 'note_on', 'time': 0.3, 'channel': 0, 'note': 60, 'velocity': 100}
{'type': 'note_off', 'time': 0, 'channel': 0, 'note': 62, 'velocity': 0}
{'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 60, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 62, 'velocity': 100}
{'type': 'time_signature', 'numerator': 4, 'denominator': 4, 'clocks_per_click': 24, 'notated_32nd_notes_per_beat': 8, 'time': 0.3}
{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 64, 'velocity': 100}
{'type': 'note_off', 'time': 0, 'channel': 0, 'note': 62, 'velocity': 0}
{'type': 'note_off', 'time': 0, 'channel': 1, 'note': 55, 'velocity': 0}
{'type': 'note_on', 'time': 0, 'channel': 1, 'note': 48, 'velocity': 100}
{'type': 'note_off', 'time': 2.4, 'channel': 0, 'note': 64, 'velocity': 0}
{'type': 'note_off', 'time': 0, 'channel': 1, 'note': 48, 'velocity': 0}
{'type': 'end_of_track', 'time': 0}

I made the file in midieditor and made two tracks:
  • Right
  • Left
Question: How do I know to which track the note_on or note_off belongs?

because the order of messages is in delta times and the note_on/note_off messages do not contain information about the track. In midieditor it can somehow read to which track the note belongs; I want to understand how this works. please give me a explenation Huh
Type 0 or Type 1 midi file? Type 0 midi files are single track, type 1 is multi track with a track per channel.
(Dec-10-2021, 05:01 PM)jefsummers Wrote: [ -> ]Type 0 or Type 1 midi file? Type 0 midi files are single track, type 1 is multi track with a track per channel.
It is type 1. But the strange thing is that midieditor can recognize even notes that are on the same channel and are on different tracks.