3 # musedata = musedata.stanford.edu
4 # musedata = COBOL for musicians.
11 f = open (sys.argv[1])
15 return re.sub ('[\r\n \t]+$','', x)
17 lines = map (chomp, lines)
19 default_header_dict = {
20 'tagline' :'automatically converted from Musedata',
21 'copyright' : 'all rights reserved -- free for noncommercial use'
24 # Jezus, wat een ranzig formaat. (2am)
25 def parse_header (lines):
26 d = default_header_dict
27 enter = string.split (lines[3], ' ')
28 d['enteredby'] = string.join (enter[1:])
29 d['enteredon'] = enter[0]
31 d['source'] = lines[5]
33 d['subtitle'] = lines[7]
34 d['instrument']= lines[8]
35 d['musedatamisc'] =lines[9]
36 d['musedatagroups'] =lines[10]
37 d['musedatagroupnumber']=lines[11]
49 return '\\clef "%s";\n' % clef_dict [string.atoi (s)]
51 def get_mudela_notename (p, ac):
54 s = chr (p + ord ('c'))
70 return '\\time %s;\n' % s
74 def get_divisions_per_quarter (s):
75 divisions = string.atoi (s)
78 def get_directive (s):
81 def get_transposing (s):
84 def get_num_instruments (s):
91 'Q' : get_divisions_per_quarter,
93 'X' : get_transposing,
94 'I': get_num_instruments,
97 def parse_musical_attributes (l):
100 atts = re.split('[ \t]+', l)
104 m = re.search ('(.):(.*)', a)
106 print 'Huh, unknown attr `%s\'' % a
109 s = s + attr_dict[m.group(1)](m.group (2))
113 def get_mudela_pitch (n, a, o):
119 return get_mudela_notename (n,a) + '%s' % c * o
121 def dump_header (h, out):
122 out.write ('\\header {\n')
123 for tup in h.items ():
124 out.write ('\t%s = \"%s\";\n' % tup)
127 header_dict = parse_header (lines[0:12])
128 dump_header (header_dict, sys.stdout)
134 def parse_line_comment (l):
135 return re.sub ('@' , '%' , l)
137 def parse_note_line (l):
138 pitch = ((ord (l[0]) -ord('A')) + 5) % 7
151 if l[0] in '0123456789':
152 oct = string.atoi (l[0]) - 4
159 print get_mudela_pitch (pitch,acc,oct), parse_duration(l[:2])
165 def parse_duration (l):
167 while l[0] in '0123456789':
171 num = string.atoi (s)
179 if num % multiplier == 0 and den % f == 0:
180 num = num / multiplier
182 current_dots = current_dots + d
185 sys.stderr.write ('huh. Durations left')
186 return '%s%s' % (den, '.' * current_dots)
191 comment_switch = not comment_switch
205 print parse_musical_attributes (l)
207 parse_line_comment (l)
209 elif l[0] in 'ABCDEFG':