-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.py
46 lines (41 loc) · 1.06 KB
/
dump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import midi
def printdelay(ticks, resolution, bpm):
if ticks != 0:
print("delay 1/", resolution*bpm/ticks, " minutes", sep="")
pattern = midi.read_midifile("example.mid")
print("Format", pattern.format, "MIDI file")
resolution = pattern.resolution
print("Resolution:", resolution)
n = 0
track = pattern[n]
time_signature = [4, 2, 24, 8]
bpm = 120
while True:
print("Track", n)
#print(track)
m = 0
event = track[m]
ticks = 0
while True:
ticks += event.tick
if event.statusmsg == 0x90:
if event.get_velocity() != 0:
printdelay(ticks, resolution, bpm)
ticks = 0
print("note", event.get_pitch(), "velocity", event.get_velocity())
else:
printdelay(ticks, resolution, bpm)
ticks = 0
print(event)
m += 1
try:
event = track[m]
except IndexError:
break
n += 1
if pattern.format == 0:
break
try:
track = pattern[n]
except IndexError:
break