-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes-to-short-rolls.py
executable file
·68 lines (52 loc) · 1.55 KB
/
notes-to-short-rolls.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import sys
import pysm
def get_row(notes, tick):
measure_number = tick // 192
try:
measure = notes.value.measures[measure_number]
except IndexError:
return None
return measure.notes[tick % 192]
def irows(notes):
for measure in notes.value.measures:
for tick in range(192):
yield measure.notes[tick]
def fix_chart(chart):
for tick, row in enumerate(irows(chart)):
for col, note in enumerate(row):
if note != '1':
continue
row[col] = '4'
next_note = 0
for i in range(1, 16):
next_row = get_row(chart, tick + i)
if next_row is None or next_row[col] != '0':
next_note = i
break
else:
next_note = 16
assert next_note >= 2
if next_note >= 16:
tail = 12
elif next_note >= 10:
tail = 6
elif next_note >= 8:
tail = 4
elif next_note >= 6:
tail = 3
elif next_note >= 4:
tail = 2
else:
tail = 1
get_row(chart, tick + tail)[col] = '3'
if __name__ == '__main__':
with open(sys.argv[1], 'r') as f:
data = f.read()
simfile = pysm.loads(data)
for h in simfile.headers:
if h.name == pysm.Invalid:
raise ValueError()
for chart in simfile.notes:
fix_chart(chart)
print(simfile, end='')