-
Notifications
You must be signed in to change notification settings - Fork 0
/
convertformat.py
72 lines (55 loc) · 1.32 KB
/
convertformat.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
69
70
71
72
import cPickle
f = open('glyph_list_sorted.txt')
c = f.readlines()[0].strip()
output = {}
contents = eval(c)
glyph_fields = [
'snum',
'oset_x',
'oset_y',
'note',
'lnum',
'gkind',
'gform',
'gchar',
'updown',
'ncols',
'nrows'
]
old_staff = None
# unique staff numbers.
snums = set([p[0] for p in contents])
for num in snums:
staff = {}
if num == '':
output[None] = {}
output[None]['content'] = []
else:
output[num] = {}
output[num]['content'] = []
for line in contents:
glyph = dict(zip(glyph_fields, line))
if glyph['gchar'][0] != '':
glyph['gchar'].insert(0, glyph['gform'])
else:
glyph['gchar'][0] = glyph['gform']
if glyph['snum'] == '':
staff_key = None
else:
staff_key = glyph['snum']
output[staff_key]['content'].append({
'type': glyph['gkind'],
'form': glyph['gchar'],
'coord': [glyph['oset_x'], glyph['oset_y'], glyph['ncols'], glyph['nrows']],
'strt_pos': glyph['lnum'],
'strt_pitch': glyph['note'],
'direction': glyph['updown']
})
f = open('datastream.pickle', 'wb')
cPickle.dump(output, f)
f.close()
# check to see if it loads
f = open('datastream.pickle', 'rb')
l = cPickle.load(f)
f.close()
print l