-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencode_notes.py
More file actions
34 lines (28 loc) · 817 Bytes
/
encode_notes.py
File metadata and controls
34 lines (28 loc) · 817 Bytes
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
import sys
import re
notes = []
length_dict = {
"FN": 16,
"HN": 8,
"QND": 6,
"QN": 4,
"END": 3,
"EN": 2,
"SN": 1,
}
with open(sys.argv[1]) as f:
for line in f:
res = re.search(r"""ENCODE_NOTE\s*\(\s*([A-GR])\s*,\s*([-0-9]+)\s*,\s*([-0-9]+)\s*,\s*([A-Z]+)\s*\)""", line)
if res is not None:
note = ord(res.group(1)) - ord('A')
if note==17:
note = 7
octave = int(res.group(2))
accidental = int(res.group(3))
length = length_dict[res.group(4)]
notes.append(note | (octave << 3) | ((accidental+1)<<7) | (length << 8))
print 'int champions[] = {'
for n in notes[:-1]:
print ' %d,' % n
print ' %d' % notes[-1]
print '};'