13 origstr
= '<%s>' % str
14 if re
.search (r
'\\\\', str):
17 if re
.search (r
'\\property', str):
20 if re
.match (r
'^\s*\)?\s*\\[a-zA-Z]+', str):
25 durs
.append(m
.group(2))
28 str = re
.sub ("([a-z]+[,'!? ]*)([0-9.]+)", sub_durs
, str)
35 return '<%s>' % m
.group (1)
42 while last_str
<> str:
46 return ' ' + m
.group(2)
48 str = re
.sub (r
'(\\!)\s*([a-z]+)', sub_dyn_end
, str)
50 if '-)' not in slur_strs
:
51 slur_strs
.append ( '-)')
54 if '-\)' not in slur_strs
:
55 slur_strs
.append ( '-\)')
57 str = re
.sub (r
"\)[ ]*([a-z]+)", sub_slurs
, str)
58 str = re
.sub (r
"\\\)[ ]*([a-z]+)", sub_p_slurs
, str)
59 def sub_begin_slurs(m
):
60 if '-(' not in slur_strs
:
61 slur_strs
.append ( '-(')
63 str = re
.sub (r
"([a-z]+[,'!?0-9 ]*)\(", sub_begin_slurs
, str)
64 def sub_begin_p_slurs(m
):
65 if '-\(' not in slur_strs
:
66 slur_strs
.append ( '-\(')
69 str = re
.sub (r
"([a-z]+[,'!?0-9 ]*)\\\(", sub_begin_p_slurs
, str)
73 if s
== '@STARTCRESC@':
74 slur_strs
.append ("-\\<")
75 elif s
== '@STARTDECRESC@':
76 slur_strs
.append ("-\\>")
78 slur_strs
.append ('-\\!')
81 str = re
.sub (r
'@STARTCRESC@', sub_dyns
, str)
82 str = re
.sub (r
'-?\\!', sub_dyns
, str)
84 def sub_articulations (m
):
86 if a
not in slur_strs
:
90 str = re
.sub (r
"([_^-]\@ACCENT\@)", sub_articulations
, str)
91 str = re
.sub (r
"([_^-]\\[a-z]+)", sub_articulations
, str)
92 str = re
.sub (r
"([_^-][>_.+|^-])", sub_articulations
, str)
95 slur_strs
.append ( ' -\\)')
97 str = re
.sub (r
"\\\)[ ]*([a-z]+)", sub_pslurs
, str)
99 suffix
= string
.join (slur_strs
, '') + string
.join (pslur_strs
, '') \
100 + string
.join (dyns
, '')
102 return '@STARTCHORD@%s@ENDCHORD@%s%s' % (str , dur_str
, suffix
)
108 simstart
= "\n\\simultaneous {"
121 marker_str
= '%% new-chords-done %%'
123 def sub_chords (str):
124 if re
.search (marker_str
,str):
127 str= re
.sub (r
'\\<', '@STARTCRESC@', str)
128 str= re
.sub (r
'\\>', '@STARTDECRESC@', str)
129 str= re
.sub (r
'([_^-])>', r
'\1@ACCENT@', str)
130 str = re
.sub ('<([^<>{}]+)>', sub_chord
, str)
132 str = re
.sub ('<([^?])', r
'%s\1' % simstart
, str)
133 str = re
.sub ('>([^?])', r
'%s\1' % simend
, str)
134 str = re
.sub ('@STARTCRESC@', r
'\\<', str)
135 str = re
.sub ('@STARTDECRESC@', r
'\\>' ,str)
136 str = re
.sub (r
'\\context *Voice *@STARTCHORD@', '@STARTCHORD@', str)
137 str = re
.sub ('@STARTCHORD@', chordstart
, str)
138 str = re
.sub ('@ENDCHORD@', chordend
, str)
139 str = re
.sub (r
'@ACCENT@', '>', str)
142 (opts
, files
)= getopt
.getopt( sys
.argv
[1:], 'e',['edit'])
145 if o
== '-e' or o
== '--edit':
149 str = open (a
).read()
150 if re
.search (marker_str
, str):
153 sys
.stderr
.write ("processing %s\n" %a
)
155 str = sub_chords (str) + marker_str
+ '\n'
158 open (a
+ '.NEW', 'w').write (str)
159 os
.rename (a
, a
+ '~')
160 os
.rename (a
+ '.NEW', a
)