Last active
August 18, 2017 22:41
-
-
Save psidex/e002fb096e2bf04ea3bf9385c9674935 to your computer and use it in GitHub Desktop.
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
from mido import MidiFile | |
from time import sleep | |
import pygame, sys | |
count = 0 | |
playback_gui = " "*10 | |
print("Press CTRL+C to quit") | |
if len(sys.argv) < 2: | |
mid_file = input(".mid file path: ") | |
else: | |
mid_file = " ".join(sys.argv[1:]) | |
print(mid_file) | |
try: | |
mid = MidiFile(mid_file) | |
except FileNotFoundError: | |
print("{} not found".format(mid_file)) | |
sys.exit() | |
print("") | |
for i, track in enumerate(mid.tracks): | |
print("Track {}: {}".format(i, track.name)) | |
playback_time = int(mid.length) | |
one_tenth = int(playback_time/10) | |
pygame.mixer.init(4410, -16, 2, 1024) | |
pygame.mixer.music.load(mid_file) | |
print ("\nFile {} loaded\nPlayback time: {}\n".format(mid_file, playback_time)) | |
pygame.mixer.music.play() | |
while pygame.mixer.music.get_busy(): | |
print(count, "["+playback_gui+"]", end="\r") | |
count += 1 | |
if count % one_tenth == 0: | |
playback_gui = "#"+playback_gui[:-1] | |
sleep(1) | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment