3 # musedata = musedata.stanford.edu
13 return re.sub ('[\r\n \t]+$','', x)
15 lines = map (chomp, lines)
17 default_header_dict = {
18 'tagline' :'automatically converted from Musedata',
19 'copyright' : 'all rights reserved -- free for noncommercial use'
22 # Jezus, wat een ranzig formaat. (2am)
23 def parse_header (lines):
24 d = default_header_dict
25 enter = string.split (lines[3], ' ')
26 d['enteredby'] = string.join (enter[1:])
27 d['enteredon'] = enter[0]
29 d['source'] = lines[5]
31 d['subtitle'] = lines[7]
32 d['instrument']= lines[8]
33 d['musedatamisc'] =lines[9]
34 d['musedatagroups'] =lines[10]
35 d['musedatagroupnumber']=lines[11]
47 return '\\clef "%s";\n' % clef_dict [string.atoi (s)]
49 def get_mudela_notename (p, ac):
52 s = chr (p + ord ('c'))
68 return '\\time %s;\n' % s
72 def get_divisions_per_quarter (s):
73 divisions = string.atoi (s)
76 def get_directive (s):
79 def get_transposing (s):
82 def get_num_instruments (s):
89 'Q' : get_divisions_per_quarter,
91 'X' : get_transposing,
92 'I': get_num_instruments,
95 def parse_musical_attributes (l):
98 atts = re.split('[ \t]+', l)
102 m = re.search ('(.):(.*)', a)
104 print 'Huh, unknown attr `%s\'' % a
107 s = s + attr_dict[m.group(1)](m.group (2))
111 def get_mudela_pitch (n, a, o):
117 return get_mudela_notename (n,a) + '%s' % c * o
119 def dump_header (h, out):
120 out.write ('\\header {\n')
121 for tup in h.items ():
122 out.write ('\t%s = \"%s\";\n' % tup)
125 header_dict = parse_header (lines[0:12])
126 dump_header (header_dict, sys.stdout)
132 def parse_line_comment (l):
133 return re.sub ('@' , '%' , l)
135 def parse_note_line (l):
136 pitch = ((ord (l[0]) -ord('A')) + 5) % 7
149 if l[0] in '0123456789':
150 oct = string.atoi (l[0]) - 4
157 print get_mudela_pitch (pitch,acc,oct), parse_duration(l[:2])
163 def parse_duration (l):
165 while l[0] in '0123456789':
169 num = string.atoi (s)
177 if num % multiplier == 0 and den % f == 0:
178 num = num / multiplier
180 current_dots = current_dots + d
183 sys.stderr.write ('huh. Durations left')
184 return '%s%s' % (den, '.' * current_dots)
189 comment_switch = not comment_switch
203 print parse_musical_attributes (l)
205 parse_line_comment (l)
207 elif l[0] in 'ABCDEFG':