Last active
August 13, 2022 18:34
-
-
Save albedozero/c74fa7411a9659ae3e27883fef34ef86 to your computer and use it in GitHub Desktop.
A command-line python script that prints info about a midi file. Requires mido (https://pypi.org/project/mido/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from sys import argv | |
from mido import MidiFile | |
if len(argv) < 2: | |
exit("Usage: midifile [filename]") | |
mid = MidiFile(argv[1]) | |
channels = set() | |
for track in mid.tracks: | |
for event in track: | |
if hasattr(event, 'channel'): | |
channels.add(event.channel) | |
midichannels = ', '.join([str(x + 1) for x in sorted(channels)]) | |
length = None | |
if mid.type != 2: | |
length = mid.length | |
print(f"File: {mid.filename}") | |
print(f"Type: {mid.type}") | |
print(f"No. of tracks: {len(mid.tracks)}") | |
print(f"Used channels: {midichannels}") | |
if length != None: | |
print(f"Length: {length:.1f} seconds") | |
print(f"Ticks per beat: {mid.ticks_per_beat}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment