import pygame.midi as md import os md.init() minput = md.Input(1) #outfile = open('mtc3hrs25.txt', 'w') outfile = open('mtcmeasure.txt', 'w') length = 0 loc = 0 while length < 10000: while minput.poll(): msg = minput.read(1) if loc == 0: loc = msg[0][1] length = msg[0][1] - loc outfile.writelines(str(msg) + os.linesep) outfile.close() try: minput.close() except: pass