Skip to content

Instantly share code, notes, and snippets.

@bzamecnik
Created October 11, 2017 12:34
Show Gist options
  • Save bzamecnik/8f8ca3c0bbfeb40f0c3bd54996b90660 to your computer and use it in GitHub Desktop.
Save bzamecnik/8f8ca3c0bbfeb40f0c3bd54996b90660 to your computer and use it in GitHub Desktop.
Prints a list of messages from a MIDI file using the `mido` library
=== Track 0
<message note_on channel=0 note=69 velocity=100 time=0>
<message note_off channel=0 note=69 velocity=0 time=522>
<message note_on channel=0 note=71 velocity=100 time=27>
<message note_off channel=0 note=71 velocity=0 time=27>
<message note_on channel=0 note=69 velocity=100 time=27>
<message note_off channel=0 note=69 velocity=0 time=27>
<message note_on channel=0 note=71 velocity=100 time=27>
<message note_off channel=0 note=71 velocity=0 time=137>
<message note_on channel=0 note=72 velocity=100 time=27>
<message note_off channel=0 note=72 velocity=0 time=27>
<message note_on channel=0 note=74 velocity=100 time=27>
<message note_off channel=0 note=74 velocity=0 time=82>
<message note_on channel=0 note=71 velocity=100 time=27>
<message note_off channel=0 note=71 velocity=0 time=82>
<message note_on channel=0 note=72 velocity=100 time=27>
<message note_off channel=0 note=72 velocity=0 time=192>
<meta message end_of_track time=1>
=== Track 1
<message note_on channel=0 note=46 velocity=100 time=0>
<message note_off channel=0 note=46 velocity=0 time=27>
<message note_on channel=0 note=66 velocity=100 time=0>
<message note_off channel=0 note=66 velocity=0 time=55>
<message note_on channel=0 note=55 velocity=100 time=27>
<message note_off channel=0 note=55 velocity=0 time=82>
<message note_on channel=0 note=57 velocity=100 time=27>
<message note_off channel=0 note=57 velocity=0 time=412>
<message note_on channel=0 note=56 velocity=100 time=137>
<message note_off channel=0 note=56 velocity=0 time=27>
<message note_on channel=0 note=60 velocity=100 time=27>
<message note_off channel=0 note=60 velocity=0 time=27>
<message note_on channel=0 note=59 velocity=100 time=27>
<message note_off channel=0 note=59 velocity=0 time=27>
<message note_on channel=0 note=62 velocity=100 time=27>
<message note_off channel=0 note=62 velocity=0 time=27>
<message note_on channel=0 note=52 velocity=100 time=27>
<message note_off channel=0 note=52 velocity=0 time=27>
<message note_on channel=0 note=53 velocity=100 time=27>
<message note_off channel=0 note=53 velocity=0 time=27>
<message note_on channel=0 note=52 velocity=100 time=27>
<message note_off channel=0 note=52 velocity=0 time=82>
<message note_on channel=0 note=52 velocity=100 time=27>
<message note_off channel=0 note=52 velocity=0 time=82>
<message note_on channel=0 note=40 velocity=100 time=27>
<message note_off channel=0 note=40 velocity=0 time=192>
<message note_on channel=0 note=45 velocity=100 time=82>
<message note_off channel=0 note=45 velocity=0 time=27>
<message note_on channel=0 note=47 velocity=100 time=27>
<message note_off channel=0 note=47 velocity=0 time=27>
<message note_on channel=0 note=48 velocity=100 time=27>
<message note_off channel=0 note=48 velocity=0 time=27>
<meta message end_of_track time=1>
=== Track 2
<message note_on channel=0 note=40 velocity=100 time=0>
<message note_off channel=0 note=40 velocity=0 time=27>
<message note_on channel=0 note=76 velocity=100 time=0>
<message note_off channel=0 note=76 velocity=0 time=55>
<message note_on channel=0 note=73 velocity=100 time=27>
<message note_off channel=0 note=73 velocity=0 time=82>
<message note_on channel=0 note=74 velocity=100 time=27>
<message note_off channel=0 note=74 velocity=0 time=82>
<message note_on channel=0 note=74 velocity=100 time=27>
<message note_off channel=0 note=74 velocity=0 time=27>
<message note_on channel=0 note=73 velocity=100 time=27>
<message note_off channel=0 note=73 velocity=0 time=27>
<message note_on channel=0 note=74 velocity=100 time=27>
<message note_off channel=0 note=74 velocity=0 time=27>
<message note_on channel=0 note=69 velocity=100 time=467>
<message note_off channel=0 note=69 velocity=0 time=55>
<message note_on channel=0 note=72 velocity=100 time=0>
<message note_off channel=0 note=72 velocity=0 time=192>
<message note_on channel=0 note=72 velocity=100 time=27>
<message note_off channel=0 note=72 velocity=0 time=27>
<message note_on channel=0 note=72 velocity=100 time=27>
<message note_off channel=0 note=72 velocity=0 time=27>
<message note_on channel=0 note=71 velocity=100 time=27>
<message note_off channel=0 note=71 velocity=0 time=27>
<message note_on channel=0 note=72 velocity=100 time=27>
<message note_off channel=0 note=72 velocity=0 time=27>
<message note_on channel=0 note=70 velocity=100 time=27>
<message note_off channel=0 note=70 velocity=0 time=27>
<meta message end_of_track time=1>
=== Track 3
<message note_on channel=0 note=61 velocity=100 time=0>
<message note_off channel=0 note=61 velocity=0 time=55>
<message note_on channel=0 note=54 velocity=100 time=0>
<message note_off channel=0 note=54 velocity=0 time=220>
<message note_on channel=0 note=55 velocity=100 time=0>
<message note_off channel=0 note=55 velocity=0 time=165>
<message note_on channel=0 note=54 velocity=100 time=27>
<message note_off channel=0 note=54 velocity=0 time=220>
<message note_on channel=0 note=56 velocity=100 time=27>
<message note_off channel=0 note=56 velocity=0 time=137>
<message note_on channel=0 note=56 velocity=100 time=27>
<message note_off channel=0 note=56 velocity=0 time=55>
<message note_on channel=0 note=57 velocity=100 time=0>
<message note_off channel=0 note=57 velocity=0 time=137>
<message note_on channel=0 note=56 velocity=100 time=27>
<message note_off channel=0 note=56 velocity=0 time=55>
<message note_on channel=0 note=57 velocity=100 time=0>
<message note_off channel=0 note=57 velocity=0 time=27>
<message note_on channel=0 note=56 velocity=100 time=27>
<message note_off channel=0 note=56 velocity=0 time=27>
<message note_on channel=0 note=54 velocity=100 time=27>
<message note_off channel=0 note=54 velocity=0 time=27>
<message note_on channel=0 note=56 velocity=100 time=27>
<message note_off channel=0 note=56 velocity=0 time=82>
<message note_on channel=0 note=54 velocity=100 time=27>
<message note_off channel=0 note=54 velocity=0 time=27>
<message note_on channel=0 note=56 velocity=100 time=27>
<message note_off channel=0 note=56 velocity=0 time=27>
<message note_on channel=0 note=57 velocity=100 time=27>
<meta message end_of_track time=1>
"""
Prints a list of messages from a MIDI file.
Requirements: mido, Python 2/3
Usage: python print_midi.py foo.mid
"""
import argparse
import mido
def print_midi(midi_file):
mid = mido.MidiFile(midi_file)
mid.print_tracks()
def parse_args():
parser = argparse.ArgumentParser(description='Print messages in a MIDI file.')
parser.add_argument('midi_file')
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
print_midi(args.midi_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment