3 # musedata = musedata.stanford.edu
4 # musedata = COBOL for musicians.
10 f = open (sys.argv[1])
14 return re.sub ('[\r\n \t]+$','', x)
16 lines = map (chomp, lines)
18 default_header_dict = {
19 'tagline' :'automatically converted from Musedata',
20 'copyright' : 'all rights reserved -- free for noncommercial use'
23 # Jezus, wat een ranzig formaat. (2am)
24 def parse_header (lines):
25 d = default_header_dict
26 enter = string.split (lines[3], ' ')
27 d['enteredby'] = string.join (enter[1:])
28 d['enteredon'] = enter[0]
30 d['source'] = lines[5]
32 d['subtitle'] = lines[7]
33 d['instrument']= lines[8]
34 d['musedatamisc'] =lines[9]
35 d['musedatagroups'] =lines[10]
36 d['musedatagroupnumber']=lines[11]
48 return '\\clef "%s";\n' % clef_dict [string.atoi (s)]
50 def get_mudela_notename (p, ac):
53 s = chr (p + ord ('c'))
69 return '\\time %s;\n' % s
73 def get_divisions_per_quarter (s):
74 divisions = string.atoi (s)
77 def get_directive (s):
80 def get_transposing (s):
83 def get_num_instruments (s):
90 'Q' : get_divisions_per_quarter,
92 'X' : get_transposing,
93 'I': get_num_instruments,
96 def parse_musical_attributes (l):
99 atts = re.split('[ \t]+', l)
103 m = re.search ('(.):(.*)', a)
105 print 'Huh, unknown attr `%s\'' % a
108 s = s + attr_dict[m.group(1)](m.group (2))
112 def get_mudela_pitch (n, a, o):
118 return get_mudela_notename (n,a) + '%s' % c * o
120 def dump_header (h, out):
121 out.write ('\\header {\n')
122 for tup in h.items ():
123 out.write ('\t%s = \"%s\";\n' % tup)
126 header_dict = parse_header (lines[0:12])
127 dump_header (header_dict, sys.stdout)
133 def parse_line_comment (l):
134 return re.sub ('@' , '%' , l)
136 def parse_note_line (l):
137 pitch = ((ord (l[0]) -ord('A')) + 5) % 7
150 if l[0] in '0123456789':
151 oct = string.atoi (l[0]) - 4
158 print get_mudela_pitch (pitch,acc,oct), parse_duration(l[:2])
164 def parse_duration (l):
166 while l[0] in '0123456789':
170 num = string.atoi (s)
178 if num % multiplier == 0 and den % f == 0:
179 num = num / multiplier
181 current_dots = current_dots + d
184 sys.stderr.write ('huh. Durations left')
185 return '%s%s' % (den, '.' * current_dots)
190 comment_switch = not comment_switch
204 print parse_musical_attributes (l)
206 parse_line_comment (l)
208 elif l[0] in 'ABCDEFG':