]> git.donarmstrong.com Git - lilypond.git/blob - python/convertrules.py
028efef4dd33c924e6c38a50aa1af8e636ddbc33
[lilypond.git] / python / convertrules.py
1 import string
2 import re
3 import sys
4 import lilylib
5
6 _ = lilylib._
7
8
9 NOT_SMART = _ ("Not smart enough to convert %s")
10 UPDATE_MANUALLY = _ ("Please refer to the manual for details, and update manually.")
11 FROM_TO = _ ( "%s has been replaced by %s")
12
13
14 class FatalConversionError:
15         pass
16
17 conversions = []
18 error_file = sys.stderr 
19
20 def conv(str):
21         if re.search ('\\\\multi', str):
22                 error_file.write ('\n')
23                 error_file.write (NOT_SMART % "\\multi")
24                 error_file.write ('\n')
25         return str
26
27 conversions.append (((0,1,9), conv, '\\header { key = concat + with + operator }'))
28
29
30 def conv (str):
31         if re.search ('\\\\octave', str):
32                 error_file.write ('\n')
33                 error_file.write (NOT_SMART % "\\octave")
34                 error_file.write ('\n')
35                 error_file.write (UPDATE_MANUALLY)
36                 error_file.write ('\n')
37         #       raise FatalConversionError ()
38
39         return str
40
41 conversions.append ((
42         ((0,1,19), conv, 'deprecated \\octave; cannot convert automatically')))
43
44
45
46 def conv (str):
47         str = re.sub ('\\\\textstyle([^;]+);',
48                                  '\\\\property Lyrics . textstyle = \\1', str)
49         # harmful to current .lys
50         # str = re.sub ('\\\\key([^;]+);', '\\\\accidentals \\1;', str)
51
52         return str
53
54 conversions.append ((
55         ((0,1,20), conv, 'deprecated \\textstyle, new \\key syntax')))
56
57
58
59 def conv (str):
60         str = re.sub ('\\\\musical_pitch', '\\\\musicalpitch',str)
61         str = re.sub ('\\\\meter', '\\\\time',str)
62
63         return str
64
65 conversions.append ((
66         ((0,1,21), conv, '\\musical_pitch -> \\musicalpitch, '+
67          '\\meter -> \\time')))
68
69
70 def conv (str):
71         return str
72
73 conversions.append ((
74         ((1,0,0), conv, '0.1.21 -> 1.0.0 ')))
75
76
77
78 def conv (str):
79         str = re.sub ('\\\\accidentals', '\\\\keysignature',str)
80         str = re.sub ('specialaccidentals *= *1', 'keyoctaviation = 0',str)
81         str = re.sub ('specialaccidentals *= *0', 'keyoctaviation = 1',str)
82
83         return str
84
85 conversions.append ((
86         ((1,0,1), conv, '\\accidentals -> \\keysignature, ' +
87          'specialaccidentals -> keyoctaviation')))
88
89
90 def conv(str):
91         if re.search ('\\\\header', str):
92                 error_file.write ('\n')
93                 error_file.write (NOT_SMART % "new \\header format")
94                 error_file.write ('\n')
95         return str
96
97 conversions.append (((1,0,2), conv, '\\header { key = concat + with + operator }'))
98
99
100 def conv(str):
101         str =  re.sub ('\\\\melodic([^a-zA-Z])', '\\\\notes\\1',str)
102         return str
103
104 conversions.append (((1,0,3), conv, '\\melodic -> \\notes'))
105
106
107 def conv(str):
108         str =  re.sub ('default_paper *=', '',str)
109         str =  re.sub ('default_midi *=', '',str)
110         return str
111
112 conversions.append (((1,0,4), conv, 'default_{paper,midi}'))
113
114
115 def conv(str):
116         str =  re.sub ('ChoireStaff', 'ChoirStaff',str)
117         str =  re.sub ('\\\\output', 'output = ',str)
118
119         return str
120
121 conversions.append (((1,0,5), conv, 'ChoireStaff -> ChoirStaff'))
122
123
124 def conv(str):
125         if re.search ('[a-zA-Z]+ = *\\translator',str):
126                 error_file.write ('\n')
127                 error_file.write (NOT_SMART % "\\translator syntax")
128                 error_file.write ('\n')
129         #       raise FatalConversionError ()
130         return str
131
132 conversions.append (((1,0,6), conv, 'foo = \\translator {\\type .. } ->\\translator {\\type ..; foo; }'))
133
134
135
136 def conv(str):
137         str =  re.sub ('\\\\lyrics*', '\\\\lyrics',str)
138
139         return str
140
141 conversions.append (((1,0,7), conv, '\\lyric -> \\lyrics'))
142
143
144 def conv(str):
145         str =  re.sub ('\\\\\\[/3+', '\\\\times 2/3 { ',str)
146         str =  re.sub ('\\[/3+', '\\\\times 2/3 { [',str)
147         str =  re.sub ('\\\\\\[([0-9/]+)', '\\\\times \\1 {',str)
148         str =  re.sub ('\\[([0-9/]+)', '\\\\times \\1 { [',str)
149         str =  re.sub ('\\\\\\]([0-9/]+)', '}', str)
150         str =  re.sub ('\\\\\\]', '}',str)
151         str =  re.sub ('\\]([0-9/]+)', '] }', str)
152         return str
153
154 conversions.append (((1,0,10), conv, '[2/3 ]1/1 -> \\times 2/3 '))
155
156
157 def conv(str):
158         return str
159 conversions.append (((1,0,12), conv, 'Chord syntax stuff'))
160
161
162
163 def conv(str):
164
165
166         str =  re.sub ('<([^>~]+)~([^>]*)>','<\\1 \\2> ~', str)
167
168         return str
169
170 conversions.append (((1,0,13), conv, '<a ~ b> c -> <a b> ~ c'))
171
172
173 def conv(str):
174         str =  re.sub ('<\\[','[<', str)
175         str =  re.sub ('\\]>','>]', str)
176
177         return str
178
179 conversions.append (((1,0,14), conv, '<[a b> <a b]>c -> [<a b> <a b>]'))
180
181
182
183 def conv(str):
184         str =  re.sub ('\\\\type([^\n]*engraver)','\\\\TYPE\\1', str)
185         str =  re.sub ('\\\\type([^\n]*performer)','\\\\TYPE\\1', str)
186         str =  re.sub ('\\\\type','\\\\context', str)
187         str =  re.sub ('\\\\TYPE','\\\\type', str)
188         str =  re.sub ('textstyle','textStyle', str)
189
190         return str
191
192 conversions.append (((1,0,16), conv, '\\type -> \\context, textstyle -> textStyle'))
193
194
195
196 def conv(str):
197         if re.search ('\\\\repeat',str):
198                 error_file.write ('\n')
199                 error_file.write (NOT_SMART % "\\repeat")
200                 error_file.write ('\n')
201         #       raise FatalConversionError ()
202         return str
203
204 conversions.append (((1,0,18), conv,
205                      '\\repeat NUM Music Alternative -> \\repeat FOLDSTR Music Alternative'))
206
207
208 def conv(str):
209         str =  re.sub ('SkipBars','skipBars', str)
210         str =  re.sub ('fontsize','fontSize', str)
211         str =  re.sub ('midi_instrument','midiInstrument', str)
212
213         return str
214
215 conversions.append (((1,0,19), conv,
216                      'fontsize -> fontSize, midi_instrument -> midiInstrument, SkipBars -> skipBars'))
217
218
219
220 def conv(str):
221         str =  re.sub ('tieydirection','tieVerticalDirection', str)
222         str =  re.sub ('slurydirection','slurVerticalDirection', str)
223         str =  re.sub ('ydirection','verticalDirection', str)
224
225         return str
226
227 conversions.append (((1,0,20), conv,
228         '{,tie,slur}ydirection -> {v,tieV,slurV}erticalDirection'))
229
230
231
232 def conv(str):
233         str =  re.sub ('hshift','horizontalNoteShift', str)
234
235         return str
236
237 conversions.append (((1,0,21), conv,
238         'hshift -> horizontalNoteShift'))
239
240
241
242 def conv(str):
243         str =  re.sub ('\\\\grouping[^;]*;','', str)
244
245         return str
246
247 conversions.append (((1,1,52), conv,
248         'deprecate \\grouping'))
249
250
251
252 def conv(str):
253         str =  re.sub ('\\\\wheel','\\\\coda', str)
254
255         return str
256
257 conversions.append (((1,1,55), conv,
258         '\\wheel -> \\coda'))
259
260
261 def conv(str):
262         str =  re.sub ('keyoctaviation','keyOctaviation', str)
263         str =  re.sub ('slurdash','slurDash', str)
264
265         return str
266
267 conversions.append (((1,1,65), conv,
268         'slurdash -> slurDash, keyoctaviation -> keyOctaviation'))
269
270
271 def conv(str):
272         str =  re.sub ('\\\\repeat *\"?semi\"?','\\\\repeat "volta"', str)
273
274         return str
275
276 conversions.append (((1,1,66), conv,
277         'semi -> volta'))
278
279
280
281 def conv(str):
282         str =  re.sub ('\"?beamAuto\"? *= *\"?0?\"?','noAutoBeaming = "1"', str)
283
284         return str
285
286 conversions.append (((1,1,67), conv,
287         'beamAuto -> noAutoBeaming'))
288
289
290 def conv(str):
291         str =  re.sub ('automaticMelismas', 'automaticMelismata', str)
292
293         return str
294
295 conversions.append (((1,2,0), conv,
296         'automaticMelismas -> automaticMelismata'))
297
298
299 def conv(str):
300         str =  re.sub ('dynamicDir\\b', 'dynamicDirection', str)
301
302         return str
303
304 conversions.append (((1,2,1), conv,
305         'dynamicDir -> dynamicDirection'))
306
307
308 def conv(str):
309         str =  re.sub ('\\\\cadenza *0 *;', '\\\\cadenzaOff', str)
310         str =  re.sub ('\\\\cadenza *1 *;', '\\\\cadenzaOn', str)
311
312         return str
313
314 conversions.append (((1,3,4), conv,
315         '\\cadenza -> \\cadenza{On|Off}'))
316
317
318 def conv (str):
319         str = re.sub ('"?beamAuto([^"=]+)"? *= *"([0-9]+)/([0-9]+)" *;*',
320                       'beamAuto\\1 = #(make-moment \\2 \\3)',
321                       str)
322         return str
323
324 conversions.append (((1,3,5), conv, 'beamAuto moment properties'))
325
326
327 def conv (str):
328         str = re.sub ('stemStyle',
329                       'flagStyle',
330                       str)
331         return str
332
333 conversions.append (((1,3,17), conv, 'stemStyle -> flagStyle'))
334
335
336 def conv (str):
337         str = re.sub ('staffLineLeading',
338                       'staffSpace',
339                       str)
340         return str
341
342 conversions.append (((1,3,18), conv, 'staffLineLeading -> staffSpace'))
343
344
345
346 def conv(str):
347         if re.search ('\\\\repetitions',str):
348                 error_file.write ('\n')
349                 error_file.write (NOT_SMART % "\\repetitions")
350                 error_file.write ('\n')
351         #       raise FatalConversionError ()
352         return str
353
354 conversions.append (((1,3,23), conv,
355         '\\\\repetitions feature dropped'))
356
357
358
359 def conv (str):
360         str = re.sub ('textEmptyDimension *= *##t',
361                       'textNonEmpty = ##f',
362                       str)
363         str = re.sub ('textEmptyDimension *= *##f',
364                       'textNonEmpty = ##t',
365                       str)
366         return str
367
368 conversions.append (((1,3,35), conv, 'textEmptyDimension -> textNonEmpty'))
369
370
371 def conv (str):
372         str = re.sub ("([a-z]+)[ \t]*=[ \t]*\\\\musicalpitch *{([- 0-9]+)} *\n",
373                       "(\\1 . (\\2))\n", str)
374         str = re.sub ("\\\\musicalpitch *{([0-9 -]+)}",
375                       "\\\\musicalpitch #'(\\1)", str)
376         if re.search ('\\\\notenames',str):
377                 error_file.write ('\n')
378                 error_file.write (NOT_SMART % "new \\notenames format")
379                 error_file.write ('\n')
380         return str
381
382 conversions.append (((1,3,38), conv, '\musicalpitch { a b c } -> #\'(a b c)'))
383
384
385 def conv (str):
386         def replace (match):
387                 return '\\key %s;' % string.lower (match.group (1))
388
389         str = re.sub ("\\\\key ([^;]+);",  replace, str)
390         return str
391
392 conversions.append (((1,3,39), conv, '\\key A ;  ->\\key a;'))
393
394
395 def conv (str):
396         if re.search ('\\[:',str):
397                 error_file.write ('\n')
398                 error_file.write (NOT_SMART % "new tremolo format")
399                 error_file.write ('\n')
400         return str
401
402 conversions.append (((1,3,41), conv,
403         '[:16 c4 d4 ] -> \\repeat "tremolo" 2 { c16 d16 }'))
404
405
406 def conv (str):
407         str = re.sub ('Staff_margin_engraver' , 'Instrument_name_engraver', str)
408         return str
409
410 conversions.append (((1,3,42), conv,
411         'Staff_margin_engraver deprecated, use Instrument_name_engraver'))
412
413
414 def conv (str):
415         str = re.sub ('note[hH]eadStyle\\s*=\\s*"?(\\w+)"?' , "noteHeadStyle = #'\\1", str)
416         return str
417
418 conversions.append (((1,3,49), conv,
419         'noteHeadStyle value: string -> symbol'))
420
421
422 def conv (str):
423         if re.search ('\\\\keysignature', str):
424                 error_file.write ('\n')
425                 error_file.write (NOT_SMART % "new tremolo format")
426                 error_file.write ('\n')
427         return str
428
429
430 conversions.append (((1,3,58), conv,
431         'noteHeadStyle value: string -> symbol'))
432
433
434 def conv (str):
435         str = re.sub (r"""\\key *([a-z]+) *;""", r"""\\key \1 \major;""",str);
436         return str
437 conversions.append (((1,3,59), conv,
438         '\key X ; -> \key X major; '))
439
440
441 def conv (str):
442         str = re.sub (r'latexheaders *= *"\\\\input ',
443                       'latexheaders = "',
444                       str)
445         return str
446 conversions.append (((1,3,68), conv, 'latexheaders = "\\input global" -> latexheaders = "global"'))
447
448
449
450
451 # TODO: lots of other syntax change should be done here as well
452
453 def conv (str):
454         str = re.sub ('basicCollisionProperties', 'NoteCollision', str)
455         str = re.sub ('basicVoltaSpannerProperties' , "VoltaBracket", str)
456         str = re.sub ('basicKeyProperties' , "KeySignature", str)
457
458         str = re.sub ('basicClefItemProperties' ,"Clef", str)
459
460
461         str = re.sub ('basicLocalKeyProperties' ,"Accidentals", str)
462         str = re.sub ('basicMarkProperties' ,"Accidentals", str)
463         str = re.sub ('basic([A-Za-z_]+)Properties', '\\1', str)
464
465         str = re.sub ('Repeat_engraver' ,'Volta_engraver', str)
466         return str
467
468 conversions.append (((1,3,92), conv, 'basicXXXProperties -> XXX, Repeat_engraver -> Volta_engraver'))
469
470
471 def conv (str):
472         # Ugh, but meaning of \stemup changed too
473         # maybe we should do \stemup -> \stemUp\slurUp\tieUp ?
474         str = re.sub ('\\\\stemup', '\\\\stemUp', str)
475         str = re.sub ('\\\\stemdown', '\\\\stemDown', str)
476         str = re.sub ('\\\\stemboth', '\\\\stemBoth', str)
477
478         str = re.sub ('\\\\slurup', '\\\\slurUp', str)
479         str = re.sub ('\\\\slurboth', '\\\\slurBoth', str)
480         str = re.sub ('\\\\slurdown', '\\\\slurDown', str)
481         str = re.sub ('\\\\slurdotted', '\\\\slurDotted', str)
482         str = re.sub ('\\\\slurnormal', '\\\\slurNoDots', str)
483
484         str = re.sub ('\\\\shiftoff', '\\\\shiftOff', str)
485         str = re.sub ('\\\\shifton', '\\\\shiftOn', str)
486         str = re.sub ('\\\\shiftonn', '\\\\shiftOnn', str)
487         str = re.sub ('\\\\shiftonnn', '\\\\shiftOnnn', str)
488
489         str = re.sub ('\\\\onevoice', '\\\\oneVoice', str)
490         str = re.sub ('\\\\voiceone', '\\\\voiceOne', str)
491         str = re.sub ('\\\\voicetwo', '\\\\voiceTwo', str)
492         str = re.sub ('\\\\voicethree', '\\\\voiceThree', str)
493         str = re.sub ('\\\\voicefour', '\\\\voiceFour', str)
494
495         # I don't know exactly when these happened...
496         # ugh, we loose context setting here...
497         str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\stemUp\\\\slurUp\\\\tieUp', str)
498         str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\stemDown\\\\slurDown\\\\tieDown', str)
499         str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\stemBoth\\\\slurBoth\\\\tieBoth', str)
500
501         str = re.sub ('verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #1', str)
502         str = re.sub ('verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #-1', str)
503         str = re.sub ('verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #0', str)
504
505         str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\\\1Up', str)
506         str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\\\1Down', str)
507         str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\\\1Both', str)
508
509         # (lacks capitalisation slur -> Slur)
510         str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\1 \\\\override #\'direction = #1', str)
511         str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\1 \\override #\'direction = #-1', str)
512         str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\1 \\\\override #\'direction = #0', str)
513
514         ## dynamic..
515         str = re.sub ('\\\\property *[^ .]*[.]?dynamicDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\dynamicUp', str)
516         str = re.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\dynamicDown', str)
517         str = re.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?(0|(\\\\center))"?', '\\\\dynamicBoth', str)
518
519         str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?(0|(""))"?', '\\\\\\1NoDots', str)
520         str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?([1-9]+)"?', '\\\\\\1Dotted', str)
521
522         str = re.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?(0|(""))"?', '\\\\autoBeamOn', str)
523         str = re.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?([1-9]+)"?', '\\\\autoBeamOff', str)
524
525
526
527         return str
528
529 conversions.append (((1,3,93), conv,
530         'property definiton case (eg. onevoice -> oneVoice)'))
531
532
533
534 def conv (str):
535         str = re.sub ('ChordNames*', 'ChordNames', str)
536         if re.search ('\\\\textscript "[^"]* *"[^"]*"', str):
537                 error_file.write ('\n')
538                 error_file.write (NOT_SMART % "new \\textscript markup text")
539                 error_file.write ('\n')
540
541         str = re.sub ('\\textscript +("[^"]*")', '\\textscript #\\1', str)
542
543         return str
544
545 conversions.append (((1,3,97), conv, 'ChordName -> ChordNames'))
546
547
548 # TODO: add lots of these
549
550
551 def conv (str):
552         str = re.sub ('\\\\property *"?Voice"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Voice.TextScript \\\\set #\'font-style = #\'\\1', str)
553         str = re.sub ('\\\\property *"?Lyrics"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Lyrics.LyricText \\\\set #\'font-style = #\'\\1', str)
554
555         str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?timeSignatureStyle"? *= *"([^"]*)"', '\\\\property \\1.TimeSignature \\\\override #\'style = #\'\\2', str)
556
557         str = re.sub ('"?timeSignatureStyle"? *= *#?""', 'TimeSignature \\\\override #\'style = ##f', str)
558
559         str = re.sub ('"?timeSignatureStyle"? *= *#?"([^"]*)"', 'TimeSignature \\\\override #\'style = #\'\\1', str)
560
561         str = re.sub ('#\'style *= #*"([^"])"', '#\'style = #\'\\1', str)
562
563         str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?horizontalNoteShift"? *= *"?#?([-0-9]+)"?', '\\\\property \\1.NoteColumn \\\\override #\'horizontal-shift = #\\2', str)
564
565         # ugh
566         str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *""', '\\\\property \\1.Stem \\\\override #\'flag-style = ##f', str)
567
568         str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *"([^"]*)"', '\\\\property \\1.Stem \\\\override #\'flag-style = #\'\\2', str)
569         return str
570
571 conversions.append (((1,3,98), conv, 'CONTEXT.textStyle -> GROB.#font-style '))
572
573
574 def conv (str):
575         str = re.sub ('"?beamAutoEnd_([0-9]*)"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end 1 \\1 * *) = \\2', str)
576         str = re.sub ('"?beamAutoBegin_([0-9]*)"? *= *(#\\([^)]*\))', 'autoBeamSettings \\push #\'(begin 1 \\1 * *) = \\2', str)
577         str = re.sub ('"?beamAutoEnd"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end * * * *) = \\1', str)
578         str = re.sub ('"?beamAutoBegin"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(begin * * * *) = \\1', str)
579
580
581         return str
582
583 conversions.append (((1,3,102), conv, 'beamAutoEnd -> autoBeamSettings \\push (end * * * *)'))
584
585
586
587 def conv (str):
588         str = re.sub ('\\\\push', '\\\\override', str)
589         str = re.sub ('\\\\pop', '\\\\revert', str)
590
591         return str
592
593 conversions.append (((1,3,111), conv, '\\push -> \\override, \\pop -> \\revert'))
594
595
596 def conv (str):
597         str = re.sub ('LyricVoice', 'LyricsVoice', str)
598         # old fix
599         str = re.sub ('Chord[Nn]ames*.Chord[Nn]ames*', 'ChordNames.ChordName', str)
600         str = re.sub ('Chord[Nn]ames([ \t\n]+\\\\override)', 'ChordName\\1', str)
601         return str
602
603 conversions.append (((1,3,113), conv, 'LyricVoice -> LyricsVoice'))
604
605 def conv (str):
606         def regularize_id (str):
607                 s = ''
608                 lastx = ''
609                 for x in str:
610                         if x == '_':
611                                 lastx = x
612                                 continue
613                         elif x in string.digits:
614                                 x = chr(ord (x) - ord ('0')  +ord ('A'))
615                         elif x not in string.letters:
616                                 x = 'x'
617                         elif x in string.lowercase and lastx == '_':
618                                 x = string.upper (x)
619                         s = s + x
620                         lastx = x
621                 return s
622
623                 def regularize_dollar_reference (match):
624                         return regularize_id (match.group (1))
625                 def regularize_assignment (match):
626                         return '\n' + regularize_id (match.group (1)) + ' = '
627                 str = re.sub ('\$([^\t\n ]+)', regularize_dollar_reference, str)
628                 str = re.sub ('\n([^ \t\n]+)[ \t]*= *', regularize_assignment, str)
629                 return str
630
631 conversions.append (((1,3,117), conv, 'identifier names: $!foo_bar_123 -> xfooBarABC'))
632
633
634
635 def conv (str):
636         def regularize_paper (match):
637                 return regularize_id (match.group (1))
638
639         str = re.sub ('(paper_[a-z]+)', regularize_paper, str)
640         str = re.sub ('sustainup', 'sustainUp', str)
641         str = re.sub ('nobreak', 'noBreak', str)
642         str = re.sub ('sustaindown', 'sustainDown', str)
643         str = re.sub ('sostenutoup', 'sostenutoUp', str)
644         str = re.sub ('sostenutodown', 'sostenutoDown', str)
645         str = re.sub ('unachorda', 'unaChorda', str)
646         str = re.sub ('trechorde', 'treChorde', str)
647
648         return str
649
650 conversions.append (((1,3,120), conv, 'paper_xxx -> paperXxxx, pedalup -> pedalUp.'))
651
652
653 def conv (str):
654         str = re.sub ('drarnChords', 'chordChanges', str)
655         str = re.sub ('\\musicalpitch', '\\pitch', str)
656         return str
657
658 conversions.append (((1,3,122), conv, 'drarnChords -> chordChanges, \\musicalpitch -> \\pitch'))
659
660
661 def conv (str):
662         str = re.sub ('ly-([sg])et-elt-property', 'ly-\\1et-grob-property', str)
663         return str
664
665 conversions.append (((1,3,136), conv, 'ly-X-elt-property -> ly-X-grob-property'))
666
667
668 def conv (str):
669         str = re.sub ('point-and-click +#t', 'point-and-click line-column-location', str)
670         return str
671
672 conversions.append (((1,3,138), conv, 'point-and-click argument changed to procedure.'))
673
674
675 def conv (str):
676         str = re.sub ('followThread', 'followVoice', str)
677         str = re.sub ('Thread.FollowThread', 'Voice.VoiceFollower', str)
678         str = re.sub ('FollowThread', 'VoiceFollower', str)
679         return str
680
681 conversions.append (((1,3,138), conv, 'followThread -> followVoice.'))
682
683
684 def conv (str):
685         str = re.sub ('font-point-size', 'font-design-size', str)
686         return str
687
688 conversions.append (((1,3,139), conv, 'font-point-size -> font-design-size.'))
689
690
691 def conv (str):
692         str = re.sub ('([a-zA-Z]*)NoDots', '\\1Solid', str)
693         return str
694
695 conversions.append (((1,3,141), conv, 'xNoDots -> xSolid'))
696
697
698 def conv (str):
699         str = re.sub ('([Cc])hord([ea])', '\\1ord\\2', str)
700         return str
701
702 conversions.append (((1,3,144), conv, 'Chorda -> Corda'))
703
704
705
706 def conv (str):
707         str = re.sub ('([A-Za-z]+)MinimumVerticalExtent', 'MinimumV@rticalExtent', str)
708         str = re.sub ('([A-Za-z]+)ExtraVerticalExtent', 'ExtraV@rticalExtent', str)
709         str = re.sub ('([A-Za-z]+)VerticalExtent', 'VerticalExtent', str)
710         str = re.sub ('ExtraV@rticalExtent', 'ExtraVerticalExtent', str)
711         str = re.sub ('MinimumV@rticalExtent', 'MinimumVerticalExtent', str)
712         return str
713
714 conversions.append (((1,3,145), conv,
715 'ContextNameXxxxVerticalExtent -> XxxxVerticalExtent'))
716
717
718 def conv (str):
719         str = re.sub ('\\\\key[ \t]*;', '\\key \\default;', str)
720         str = re.sub ('\\\\mark[ \t]*;', '\\mark \\default;', str)
721
722         # Make sure groups of more than one ; have space before
723         # them, so that non of them gets removed by next rule
724         str = re.sub ("([^ \n\t;]);(;+)", "\\1 ;\\2", str)
725
726         # Only remove ; that are not after spaces, # or ;
727         # Otherwise  we interfere with Scheme comments,
728         # which is badbadbad.
729         str = re.sub ("([^ \t;#]);", "\\1", str)
730
731         return str
732 conversions.append (((1,3,146), conv, 'semicolons removed'))
733
734
735 def conv (str):
736         str = re.sub ('default-neutral-direction', 'neutral-direction',str)
737         return str
738 conversions.append (((1,3,147), conv, 'default-neutral-direction -> neutral-direction'))
739
740
741 def conv (str):
742         str = re.sub ('\(align', '(axis', str)
743         str = re.sub ('\(rows', '(columns', str)
744         return str
745 conversions.append (((1,3,148), conv, '"(align" -> "(axis", "(rows" -> "(columns"'))
746
747
748
749 def conv (str):
750         str = re.sub ('SystemStartDelimiter', 'systemStartDelimiter', str)
751         return str
752 conversions.append (((1,5,33), conv, 'SystemStartDelimiter -> systemStartDelimiter'))
753
754
755 def conv (str):
756         str = re.sub ('arithmetic-multiplier', 'spacing-increment', str)
757         str = re.sub ('arithmetic-basicspace', 'shortest-duration-space', str)
758         return str
759
760 conversions.append (((1,5,38), conv, 'SystemStartDelimiter -> systemStartDelimiter'))
761
762
763
764 def conv (str):
765
766         def func(match):
767                 break_dict = {
768                 "Instrument_name": "instrument-name",
769                 "Left_edge_item": "left-edge",
770                 "Span_bar": "span-bar",
771                 "Breathing_sign": "breathing-sign",
772                 "Staff_bar": "staff-bar",
773                 "Clef_item": "clef",
774                 "Key_item": "key-signature",
775                 "Time_signature": "time-signature",
776                 "Custos": "custos"
777                 }
778                 props =  match.group (1)
779                 for (k,v) in break_dict.items():
780                         props = re.sub (k, v, props)
781                 return  "breakAlignOrder = #'(%s)" % props
782
783         str = re.sub ("breakAlignOrder *= *#'\\(([a-z_\n\tA-Z ]+)\\)",
784                       func, str)
785         return str
786
787 # 40 ?
788 conversions.append (((1,5,40), conv, 'breakAlignOrder property names'))
789
790
791
792 def conv (str):
793         str = re.sub ('noAutoBeaming *= *##f', 'autoBeaming = ##t', str)
794         str = re.sub ('noAutoBeaming *= *##t', 'autoBeaming = ##f', str)
795         return str
796
797 conversions.append (((1,5,49), conv, 'noAutoBeaming -> autoBeaming'))
798
799
800 def conv (str):
801         str = re.sub ('tuplet-bracket-visibility', 'bracket-visibility', str)
802         str = re.sub ('tuplet-number-visibility', 'number-visibility', str)
803         return str
804
805 conversions.append (((1,5,52), conv, 'tuplet-X-visibility -> X-visibility'))
806
807
808 def conv (str):
809         str = re.sub ('Pitch::transpose', 'ly-transpose-pitch', str)
810
811         return str
812
813 conversions.append (((1,5,56), conv, 'Pitch::transpose -> ly-transpose-pitch'))
814
815
816 def conv (str):
817         str = re.sub ('textNonEmpty *= *##t', "TextScript \\set #'no-spacing-rods = ##f", str)
818         str = re.sub ('textNonEmpty *= *##f', "TextScript \\set #'no-spacing-rods = ##t", str)
819         return str
820
821 conversions.append (((1,5,58), conv, 'deprecate textNonEmpty'))
822
823
824
825 def conv (str):
826         str = re.sub ('MinimumVerticalExtent', 'minimumV@rticalExtent', str)
827         str = re.sub ('minimumVerticalExtent', 'minimumV@rticalExtent', str)
828         str = re.sub ('ExtraVerticalExtent', 'extraV@rticalExtent', str)
829         str = re.sub ('extraVerticalExtent', 'extraV@rticalExtent', str)
830         str = re.sub ('VerticalExtent', 'verticalExtent', str)
831         str = re.sub ('extraV@rticalExtent', 'extraVerticalExtent', str)
832         str = re.sub ('minimumV@rticalExtent', 'minimumVerticalExtent', str)
833         return str
834
835 conversions.append (((1,5,59), conv,
836 'XxxxVerticalExtent -> xxxVerticalExtent'))
837
838
839 def conv (str):
840         str = re.sub ('visibility-lambda', 'break-visibility', str)
841         return str
842
843 conversions.append (((1,5,62), conv,
844 'visibility-lambda -> break-visibility'))
845
846
847
848 def conv (str):
849         if re.search (r'\addlyrics',str) \
850                and re.search ('automaticMelismata', str)  == None:
851                 error_file.write ('\n')
852                 error_file.write (NOT_SMART % "automaticMelismata; turned on by default since 1.5.67.")
853                 error_file.write ('\n')
854                 raise FatalConversionError ()
855         return str
856
857 conversions.append (((1,5,67), conv,
858                      'automaticMelismata turned on by default'))
859
860
861 def conv (str):
862         str = re.sub ('ly-set-grob-property([^!])', 'ly-set-grob-property!\1', str)
863         str = re.sub ('ly-set-mus-property([^!])', 'ly-set-mus-property!\1', str)
864         return str
865
866 conversions.append (((1,5,68), conv, 'ly-set-X-property -> ly-set-X-property!'))
867
868
869 def conv (str):
870         str = re.sub ('extent-X', 'X-extent', str)
871         str = re.sub ('extent-Y', 'Y-extent', str)
872         return str
873
874 conversions.append (((1,5,71), conv, 'extent-[XY] -> [XY]-extent'))
875
876
877
878 def conv (str):
879         str = re.sub ("""#\(set! +point-and-click +line-column-location\)""",
880                       """#(set-point-and-click! \'line-column)""", str)
881         str = re.sub ("""#\(set![ \t]+point-and-click +line-location\)""",
882                       '#(set-point-and-click! \'line)', str)
883         str = re.sub ('#\(set! +point-and-click +#f\)',
884                       '#(set-point-and-click! \'none)', str)
885         return str
886
887 conversions.append (((1,5,72), conv, 'set! point-and-click -> set-point-and-click!'))
888
889
890
891 def conv (str):
892         str = re.sub ('flag-style', 'stroke-style', str)
893         str = re.sub (r"""Stem([ ]+)\\override #'style""", r"""Stem \\override #'flag-style""", str);
894         str = re.sub (r"""Stem([ ]+)\\set([ ]+)#'style""", r"""Stem \\set #'flag-style""", str);
895         return str
896
897 conversions.append (((1,6,5), conv, 'Stems: flag-style -> stroke-style; style -> flag-style'))
898
899
900
901 def subst_req_name (match):
902         return "(make-music-by-name \'%sEvent)" % regularize_id (match.group(1))
903
904 def conv (str):
905         str = re.sub ('\\(ly-make-music *\"([A-Z][a-z_]+)_req\"\\)', subst_req_name, str)
906         str = re.sub ('Request_chord', 'EventChord', str)
907         return str
908
909 conversions.append (((1,7,1), conv, 'ly-make-music foo_bar_req -> make-music-by-name FooBarEvent'))
910
911
912
913 spanner_subst ={
914         "text" : 'TextSpanEvent',
915         "decrescendo" : 'DecrescendoEvent',
916         "crescendo" : 'CrescendoEvent',
917         "Sustain" : 'SustainPedalEvent',
918         "slur" : 'SlurEvent',
919         "UnaCorda" : 'UnaCordaEvent',
920         "Sostenuto" : 'SostenutoEvent',
921         }
922 def subst_ev_name (match):
923         stype = 'STOP'
924         if re.search ('start', match.group(1)):
925                 stype= 'START'
926
927         mtype = spanner_subst[match.group(2)]
928         return "(make-span-event '%s %s)" % (mtype , stype)
929
930 def subst_definition_ev_name(match):
931         return ' = #%s' % subst_ev_name (match)
932 def subst_inline_ev_name (match):
933         s = subst_ev_name (match)
934         return '#(ly-export %s)' % s
935 def subst_csp_definition (match):
936         return ' = #(make-event-chord (list %s))' % subst_ev_name (match)
937 def subst_csp_inline (match):
938         return '#(ly-export (make-event-chord (list %s)))' % subst_ev_name (match)
939
940 def conv (str):
941         str = re.sub (r' *= *\\spanrequest *([^ ]+) *"([^"]+)"', subst_definition_ev_name, str)
942         str = re.sub (r'\\spanrequest *([^ ]+) *"([^"]+)"', subst_inline_ev_name, str)
943         str = re.sub (r' *= *\\commandspanrequest *([^ ]+) *"([^"]+)"', subst_csp_definition, str)
944         str = re.sub (r'\\commandspanrequest *([^ ]+) *"([^"]+)"', subst_csp_inline, str)
945         str = re.sub (r'ly-id ', 'ly-import ', str)
946
947         str = re.sub (r' *= *\\script "([^"]+)"', ' = #(make-articulation "\\1")', str)
948         str = re.sub (r'\\script "([^"]+)"', '#(ly-export (make-articulation "\\1"))', str)
949         return str
950
951 conversions.append (((1,7,2), conv, '\\spanrequest -> #(make-span-event .. ), \script -> #(make-articulation .. )'))
952
953
954 def conv(str):
955         str = re.sub (r'\(ly-', '(ly:', str)
956
957         changed = [
958                 r'duration\?',
959                 r'font-metric\?',
960                 r'molecule\?',
961                 r'moment\?',
962                 r'music\?',
963                 r'pitch\?',
964                 'make-duration',
965                 'music-duration-length',
966                 'duration-log',
967                 'duration-dotcount',
968                 'intlog2',
969                 'duration-factor',
970                 'transpose-key-alist',
971                 'get-system',
972                 'get-broken-into',
973                 'get-original',
974                 'set-point-and-click!',
975                 'make-moment',
976                 'make-pitch',
977                 'pitch-octave',
978                 'pitch-alteration',
979                 'pitch-notename',
980                 'pitch-semitones',
981                 r'pitch<\?',
982                 r'dir\?',
983                 'music-duration-compress',
984                 'set-point-and-click!'
985                 ]
986
987         origre = r'\b(%s)' % string.join (changed, '|')
988
989         str = re.sub (origre, r'ly:\1',str)
990         str = re.sub ('set-point-and-click!', 'set-point-and-click', str)
991
992         return str
993
994 conversions.append (((1,7,3), conv, 'ly- -> ly:'))
995
996
997 def conv(str):
998         if re.search ('new-chords-done',str):
999                 return str
1000
1001         str = re.sub (r'<<', '< <', str)
1002         str = re.sub (r'>>', '> >', str)
1003         return str
1004
1005 conversions.append (((1,7,4), conv, '<< >> -> < <  > >'))
1006
1007
1008 def conv(str):
1009         str = re.sub (r"\\transpose", r"\\transpose c'", str)
1010         str = re.sub (r"\\transpose c' *([a-z]+)'", r"\\transpose c \1", str)
1011         return str
1012 conversions.append (((1,7,5), conv, '\\transpose TO -> \\transpose FROM  TO'))
1013
1014
1015 def conv(str):
1016         kws =   ['arpeggio',
1017                  'sustainDown',
1018                  'sustainUp',
1019                  'f',
1020                  'p',
1021                  'pp',
1022                  'ppp',
1023                  'fp',
1024                  'ff',
1025                  'mf',
1026                  'mp',
1027                  'sfz',
1028                  ]
1029
1030         origstr = string.join (kws, '|')
1031         str = re.sub (r'([^_^-])\\(%s)\b' % origstr, r'\1-\\\2', str)
1032         return str
1033 conversions.append (((1,7,6), conv, 'note\\script -> note-\script'))
1034
1035
1036
1037 def conv(str):
1038         str = re.sub (r"\\property *ChordNames *\. *ChordName *\\(set|override) *#'style *= *#('[a-z]+)",
1039                       r"#(set-chord-name-style \2)", str)
1040         str = re.sub (r"\\property *ChordNames *\. *ChordName *\\revert *#'style",
1041                       r"", str)
1042         return str
1043 conversions.append (((1,7,10), conv, "\property ChordName #'style -> #(set-chord-name-style 'style)"))
1044
1045
1046
1047
1048 def conv(str):
1049         str = re.sub (r"ly:transpose-pitch", "ly:pitch-transpose", str)
1050
1051         return str
1052 conversions.append (((1,7,11), conv, "transpose-pitch -> pitch-transpose"))
1053
1054
1055 def conv(str):
1056         str = re.sub (r"ly:get-molecule-extent", "ly:molecule-get-extent", str)
1057         str = re.sub (r"ly:set-molecule-extent!", "ly:molecule-set-extent!", str)
1058         str = re.sub (r"ly:add-molecule", "ly:molecule-add", str)
1059         str = re.sub (r"ly:combine-molecule-at-edge", "ly:molecule-combine-at-edge", str)
1060         str = re.sub (r"ly:align-to!", "ly:molecule-align-to!", str)
1061
1062         return str
1063
1064 conversions.append (((1,7,13), conv, "ly:XX-molecule-YY -> ly:molecule-XX-YY"))
1065
1066
1067 def conv(str):
1068         str = re.sub (r"linewidth *= *-[0-9.]+ *(\\mm|\\cm|\\in|\\pt)?", 'raggedright = ##t', str )
1069         return str
1070
1071 conversions.append (((1,7,15), conv, "linewidth = -1 -> raggedright = ##t"))
1072
1073
1074 def conv(str):
1075         str = re.sub ("divisiomaior",
1076                       "divisioMaior", str)
1077         str = re.sub ("divisiominima",
1078                       "divisioMinima", str)
1079         str = re.sub ("divisiomaxima",
1080                       "divisioMaxima", str)
1081         return str
1082
1083 conversions.append (((1,7,16), conv, "divisiomaior -> divisioMaior"))
1084
1085
1086 def conv(str):
1087         str = re.sub ("Skip_req_swallow_translator",
1088                       "Skip_event_swallow_translator", str)
1089         return str
1090
1091 conversions.append (((1,7,17), conv, "Skip_req  -> Skip_event"))
1092
1093
1094 def conv(str):
1095         str = re.sub ("groupOpen",
1096                       "startGroup", str)
1097         str = re.sub ("groupClose",
1098                       "stopGroup", str)
1099         str = re.sub ("#'outer",
1100                       "#'enclose-bounds", str)
1101
1102         return str
1103
1104 conversions.append (((1,7,18), conv,
1105                      """groupOpen/Close  -> start/stopGroup,
1106                      #'outer  -> #'enclose-bounds
1107                      """))
1108
1109
1110 def conv(str):
1111         if re.search( r'\\GraceContext', str):
1112                 error_file.write ('\n')
1113                 error_file.write (NOT_SMART % "GraceContext")
1114                 error_file.write (FROM_TO \
1115                                   % ("GraceContext", "#(add-to-grace-init .. )"))
1116                 error_file.write ('\n')
1117                 error_file.write (UPDATE_MANUALLY)
1118                 error_file.write ('\n')
1119                 raise FatalConversionError ()
1120
1121         str = re.sub ('HaraKiriStaffContext', 'RemoveEmptyStaffContext', str)
1122         return str
1123
1124 conversions.append (((1,7,19), conv,"remove GraceContext"))
1125
1126
1127
1128
1129 def conv(str):
1130         str = re.sub (
1131                 r"(set|override|revert) *#'type",
1132                 r"\1 #'style",
1133                 str)
1134         return str
1135
1136 conversions.append (((1,7,22), conv,"#'type -> #'style"))
1137
1138
1139 def conv(str):
1140         str = re.sub (
1141                 "barNonAuto *= *##t",
1142                 "automaticBars = ##f",
1143                 str)
1144         str = re.sub (
1145                 "barNonAuto *= *##f",
1146                 "automaticBars = ##t",
1147                 str)
1148         return str
1149
1150 conversions.append (((1,7,23), conv,"barNonAuto -> automaticBars"))
1151
1152
1153
1154 def conv(str):
1155         if re.search( r'-(start|stop)Cluster', str):
1156                 error_file.write ('\n')
1157                 error_file.write (NOT_SMART % "Cluster syntax")
1158                 error_file.write ('\n')
1159                 error_file.write (UPDATE_MANUALLY)
1160                 error_file.write ('\n')
1161
1162                 raise FatalConversionError ()
1163
1164         return str
1165
1166 conversions.append (((1,7,24), conv,"cluster syntax"))
1167
1168
1169 def conv(str):
1170         str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\(override|set) *#'pedal-type *",
1171                         r"\property Staff.pedal\1Style ", str)
1172         str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\revert *#'pedal-type", '', str)
1173         return str
1174
1175 conversions.append (((1,7,28), conv,"new Pedal style syntax"))
1176
1177
1178
1179
1180
1181 def sub_chord (m):
1182         str = m.group(1)
1183
1184         origstr =  '<%s>' % str
1185         if re.search (r'\\\\', str):
1186                 return origstr
1187
1188         if re.search (r'\\property', str):
1189                 return origstr
1190
1191         if re.match (r'^\s*\)?\s*\\[a-zA-Z]+', str):
1192                 return origstr
1193
1194         durs = []
1195         def sub_durs (m, durs = durs):
1196                 durs.append(m.group(2))
1197                 return m.group (1)
1198
1199         str = re.sub (r"([a-z]+[,'!? ]*)([0-9]+\.*)", sub_durs, str)
1200         dur_str = ''
1201
1202         for d in durs:
1203                 if dur_str == '':
1204                         dur_str = d
1205                 if dur_str <> d:
1206                         return '<%s>' % m.group (1)
1207
1208         pslur_strs = ['']
1209         dyns = ['']
1210         slur_strs = ['']
1211
1212         last_str = ''
1213         while last_str <> str:
1214                 last_str = str
1215
1216                 def sub_tremolos (m, slur_strs = slur_strs):
1217                         tr = m.group (2)
1218                         if tr not in slur_strs:
1219                                 slur_strs.append (tr)
1220                         return  m.group (1)
1221
1222                 str = re.sub (r"([a-z]+[',!? ]*)(:[0-9]+)",
1223                               sub_tremolos, str)
1224
1225                 def sub_dyn_end (m, dyns = dyns):
1226                         dyns.append (' \!')
1227                         return ' ' + m.group(2)
1228
1229                 str = re.sub (r'(\\!)\s*([a-z]+)', sub_dyn_end, str)
1230                 def sub_slurs(m, slur_strs = slur_strs):
1231                         if '-)' not in slur_strs:
1232                                 slur_strs.append (')')
1233                         return m.group(1)
1234
1235                 def sub_p_slurs(m, slur_strs = slur_strs):
1236                         if '-\)' not in slur_strs:
1237                                 slur_strs.append ('\)')
1238                         return m.group(1)
1239
1240                 str = re.sub (r"\)[ ]*([a-z]+)", sub_slurs, str)
1241                 str = re.sub (r"\\\)[ ]*([a-z]+)", sub_p_slurs, str)
1242                 def sub_begin_slurs(m, slur_strs = slur_strs):
1243                         if '-(' not in slur_strs:
1244                                 slur_strs.append ('(')
1245                         return m.group(1)
1246
1247                 str = re.sub (r"([a-z]+[,'!?0-9 ]*)\(",
1248                               sub_begin_slurs, str)
1249                 def sub_begin_p_slurs(m, slur_strs = slur_strs):
1250                         if '-\(' not in slur_strs:
1251                                 slur_strs.append ('\(')
1252                         return m.group(1)
1253
1254                 str = re.sub (r"([a-z]+[,'!?0-9 ]*)\\\(",
1255                         sub_begin_p_slurs, str)
1256
1257                 def sub_dyns (m, slur_strs = slur_strs):
1258                         s = m.group(0)
1259                         if s == '@STARTCRESC@':
1260                                 slur_strs.append ("\\<")
1261                         elif s == '@STARTDECRESC@':
1262                                 slur_strs.append ("\\>")
1263                         elif s == r'-?\\!':
1264                                 slur_strs.append ('\\!')
1265                         return ''
1266
1267                 str = re.sub (r'@STARTCRESC@', sub_dyns, str)
1268                 str = re.sub (r'-?\\!', sub_dyns, str)
1269
1270                 def sub_articulations (m, slur_strs = slur_strs):
1271                         a = m.group(1)
1272                         if a not in slur_strs:
1273                                 slur_strs.append (a)
1274                         return ''
1275
1276                 str = re.sub (r"([_^-]\@ACCENT\@)", sub_articulations,
1277                               str)
1278                 str = re.sub (r"([_^-]\\[a-z]+)", sub_articulations,
1279                               str)
1280                 str = re.sub (r"([_^-][>_.+|^-])", sub_articulations,
1281                               str)
1282                 str = re.sub (r'([_^-]"[^"]+")', sub_articulations,
1283                               str)
1284
1285                 def sub_pslurs(m, slur_strs = slur_strs):
1286                         slur_strs.append (' \\)')
1287                         return m.group(1)
1288                 str = re.sub (r"\\\)[ ]*([a-z]+)", sub_pslurs, str)
1289
1290         ## end of while <>
1291
1292         suffix = string.join (slur_strs, '') + string.join (pslur_strs,
1293                                                             '') \
1294                  + string.join (dyns, '')
1295
1296         return '@STARTCHORD@%s@ENDCHORD@%s%s' % (str , dur_str, suffix)
1297
1298
1299
1300 def sub_chords (str):
1301         simend = '>'
1302         simstart = '<'
1303         chordstart = '<<'
1304         chordend = '>>'
1305         marker_str = '%% new-chords-done %%'
1306
1307         if re.search (marker_str,str):
1308                 return str
1309         str = re.sub ('<<', '@STARTCHORD@', str)
1310         str = re.sub ('>>', '@ENDCHORD@', str)
1311
1312         str = re.sub (r'\\<', '@STARTCRESC@', str)
1313         str = re.sub (r'\\>', '@STARTDECRESC@', str)
1314         str = re.sub (r'([_^-])>', r'\1@ACCENT@', str)
1315         str = re.sub (r'<([^<>{}]+)>', sub_chord, str)
1316
1317         # add dash: -[, so that [<<a b>> c d] becomes
1318         #                      <<a b>>-[ c d]
1319         # and gets skipped by articulation_substitute
1320         str = re.sub (r'\[ *(@STARTCHORD@[^@]+@ENDCHORD@[0-9.]*)',
1321                       r'\1-[', str)
1322         str = re.sub (r'\\! *(@STARTCHORD@[^@]+@ENDCHORD@[0-9.]*)',
1323                       r'\1-\\!', str)
1324
1325         str = re.sub (r'<([^?])', r'%s\1' % simstart, str)
1326         str = re.sub (r'>([^?])', r'%s\1' % simend,  str)
1327         str = re.sub ('@STARTCRESC@', r'\\<', str)
1328         str = re.sub ('@STARTDECRESC@', r'\\>' ,str)
1329         str = re.sub (r'\\context *Voice *@STARTCHORD@',
1330                       '@STARTCHORD@', str)
1331         str = re.sub ('@STARTCHORD@', chordstart, str)
1332         str = re.sub ('@ENDCHORD@', chordend, str)
1333         str = re.sub (r'@ACCENT@', '>', str)
1334         return str
1335
1336 markup_start = re.compile(r"([-^_]|\\mark)\s*(#\s*'\s*)\(")
1337 musicglyph = re.compile(r"\(\s*music\b")
1338 columns = re.compile(r"\(\s*columns\b")
1339 submarkup_start = re.compile(r"\(\s*([a-zA-Z]+)")
1340 leftpar = re.compile(r"\(")
1341 rightpar = re.compile(r"\)")
1342
1343 def text_markup (str):
1344         result = ''
1345         # Find the beginning of each markup:
1346         match = markup_start.search (str)
1347         while match:
1348                 result = result + str[:match.end (1)] + " \markup"
1349                 str = str[match.end( 2):]
1350                 # Count matching parentheses to find the end of the 
1351                 # current markup:
1352                 nesting_level = 0
1353                 pars = re.finditer(r"[()]",str)
1354                 for par in pars:
1355                         if par.group () == '(':
1356                                 nesting_level = nesting_level + 1
1357                         else:
1358                                 nesting_level = nesting_level - 1
1359                         if nesting_level == 0:
1360                                 markup_end = par.end ()
1361                                 break
1362                 # The full markup in old syntax:
1363                 markup = str[:markup_end]
1364                 # Modify to new syntax:
1365                 markup = musicglyph.sub (r"{\\musicglyph", markup)
1366                 markup = columns.sub (r"{", markup)
1367                 markup = submarkup_start.sub (r"{\\\1", markup)
1368                 markup = leftpar.sub ("{", markup)
1369                 markup = rightpar.sub ("}", markup)
1370
1371                 result = result + markup
1372                 # Find next markup
1373                 str = str[markup_end:]
1374                 match = markup_start.search(str)
1375         result = result + str
1376         return result
1377
1378 def articulation_substitute (str):
1379         str = re.sub (r"""([^-])\[ *(\\?\)?[a-z]+[,']*[!?]?[0-9:]*\.*)""",
1380                       r"\1 \2[", str)
1381         str = re.sub (r"""([^-])\\\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
1382                       r"\1 \2\\)", str)
1383         str = re.sub (r"""([^-\\])\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
1384                       r"\1 \2)", str)
1385         str = re.sub (r"""([^-])\\! *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
1386                       r"\1 \2\\!", str)
1387         return str
1388
1389 string_or_scheme = re.compile ('("(?:[^"\\\\]|\\\\.)*")|(#\\s*\'?\\s*\\()')
1390
1391 # Only apply articulation_substitute () outside strings and 
1392 # Scheme expressions:
1393 def smarter_articulation_subst (str):
1394         result = ''
1395         # Find the beginning of next string or Scheme expr.:
1396         match = string_or_scheme.search (str)
1397         while match:
1398                 # Convert the preceding LilyPond code:
1399                 previous_chunk = str[:match.start()]
1400                 result = result + articulation_substitute (previous_chunk)
1401                 if match.group (1): # Found a string
1402                         # Copy the string to output:
1403                         result = result + match.group (1)
1404                         str = str[match.end(1):]
1405                 else: # Found a Scheme expression. Count 
1406                         # matching parentheses to find its end
1407                         str = str[match.start ():]
1408                         nesting_level = 0
1409                         pars = re.finditer(r"[()]",str)
1410                         for par in pars:
1411                                 if par.group () == '(':
1412                                         nesting_level = nesting_level + 1
1413                                 else:
1414                                         nesting_level = nesting_level - 1
1415                                 if nesting_level == 0:
1416                                         scheme_end = par.end ()
1417                                         break
1418                         # Copy the Scheme expression to output:
1419                         result = result + str[:scheme_end]
1420                         str = str[scheme_end:]
1421                 # Find next string or Scheme expression:
1422                 match = string_or_scheme.search (str)
1423         # Convert the remainder of the file
1424         result = result + articulation_substitute (str)
1425         return result
1426
1427 def conv_relative(str):
1428         if re.search (r"\\relative", str):
1429                 str= "#(ly:set-option 'old-relative)\n" + str
1430
1431         return str
1432
1433 def conv (str):
1434         str = re.sub (r"#'\(\)", "@SCM_EOL@", str)
1435         str =  conv_relative (str)
1436         str = sub_chords (str)
1437
1438         str = text_markup (str)
1439         str = smarter_articulation_subst (str)
1440         str = re.sub ("@SCM_EOL@", "#'()", str)
1441
1442         return str
1443
1444 conversions.append (((1,9,0), conv, """New relative mode,
1445 Postfix articulations, new text markup syntax, new chord syntax."""))
1446
1447
1448 def conv (str):
1449         if re.search ("font-style",str):
1450                 error_file.write ('\n')
1451                 error_file.write (NOT_SMART % "font-style")
1452                 error_file.write ('\n')
1453                 error_file.write (UPDATE_MANUALLY)
1454                 error_file.write ('\n')
1455
1456                 raise FatalConversionError ()
1457
1458         str = re.sub (r'-\\markup', r'@\\markup', str)
1459         str = re.sub (r'-\\', r'\\', str)
1460         str = re.sub (r'-\)', ')', str)
1461         str = re.sub (r'-\(', '(', str)
1462         str = re.sub ('-\[', '[', str)
1463         str = re.sub ('-\]', ']', str)
1464         str = re.sub ('-~', '~', str)
1465         str = re.sub (r'@\\markup', r'-\\markup', str)
1466         return str
1467
1468 conversions.append (((1,9,1), conv, """Remove - before articulation"""))
1469
1470 def conv (str):
1471         str = re.sub ('ly:set-context-property',
1472                       'ly:set-context-property!', str)
1473         str = re.sub ('\\\\newcontext', '\\\\new', str)
1474         str = re.sub ('\\\\grace[\t\n ]*([^{ ]+)',
1475                       r'\\grace { \1 }', str)
1476         str = re.sub ("\\\\grace[\t\n ]*{([^}]+)}",
1477                       r"""\\grace {
1478 \\property Voice.Stem \\override #'stroke-style = #"grace"
1479   \1
1480   \\property Voice.Stem \\revert #'stroke-style }
1481 """, str)
1482
1483         return str
1484
1485 conversions.append (((1,9,2), conv, """\\newcontext -> \\new"""))
1486
1487 def conv (str):
1488         str = re.sub ('accacciatura',
1489                       'acciaccatura', str)
1490
1491         if re.search ("context-spec-music", str):
1492                 error_file.write ('\n')
1493                 error_file.write (NOT_SMART % "context-spec-music")
1494                 error_file.write ('\n')
1495                 error_file.write (UPDATE_MANUALLY)
1496                 error_file.write ('\n')
1497
1498                 raise FatalConversionError ()
1499
1500         str = re.sub ('fingerHorizontalDirection *= *#(LEFT|-1)',
1501                       "fingeringOrientations = #'(up down left)", str)
1502         str = re.sub ('fingerHorizontalDirection *= *#(RIGHT|1)',
1503                       "fingeringOrientations = #'(up down right)", str)
1504
1505         return str
1506
1507 conversions.append (((1,9,3), conv,
1508                      """\\acciaccatura misspelling, fingerHorizontalDirection -> fingeringOrientations"""))
1509
1510
1511 def conv (str):
1512         if re.search ('\\figures', str):
1513                 error_file.write ("Warning: attempting automatic \\figures conversion.  Check results!");
1514
1515
1516         def figures_replace (m):
1517                 s = m.group (1)
1518                 s = re.sub ('<', '@FIGOPEN@',s)
1519                 s = re.sub ('>', '@FIGCLOSE@',s)
1520                 return '\\figures { %s }' % s
1521
1522         str = re.sub (r'\\figures[ \t\n]*{([^}]+)}', figures_replace, str)
1523         str = re.sub (r'\\<', '@STARTCRESC@', str)
1524         str = re.sub (r'\\>', '@STARTDECRESC@', str)
1525         str = re.sub (r'([-^_])>', r'\1@ACCENT@', str)
1526         str = re.sub (r'<<', '@STARTCHORD@', str)
1527         str = re.sub (r'>>', '@ENDCHORD@', str)
1528         str = re.sub (r'>', '@ENDSIMUL@', str)
1529         str = re.sub (r'<', '@STARTSIMUL@', str)
1530         str = re.sub ('@STARTDECRESC@', '\\>', str)
1531         str = re.sub ('@STARTCRESC@', '\\<', str)
1532         str = re.sub ('@ACCENT@', '>', str)
1533         str = re.sub ('@ENDCHORD@', '>', str)
1534         str = re.sub ('@STARTCHORD@', '<', str)
1535         str = re.sub ('@STARTSIMUL@', '<<', str)
1536         str = re.sub ('@ENDSIMUL@', '>>', str)
1537         str = re.sub ('@FIGOPEN@', '<', str)
1538         str = re.sub ('@FIGCLOSE@', '>', str)
1539
1540         return str
1541
1542 conversions.append (((1,9,4), conv, 'Swap < > and << >>'))
1543
1544
1545 def conv (str):
1546         str = re.sub ('HaraKiriVerticalGroup', 'RemoveEmptyVerticalGroup', str)
1547
1548         return str
1549
1550 conversions.append (((1,9,5), conv, 'HaraKiriVerticalGroup -> RemoveEmptyVerticalGroup'))
1551
1552 def conv (str):
1553         if re.search ("ly:get-font", str) :
1554                 error_file.write ('\n')
1555                 error_file.write (NOT_SMART % "(ly:-get-font")
1556                 error_file.write ('\n')
1557                 error_file.write (FROM_TO \
1558                                   % ("(ly:paper-get-font (ly:grob-get-paper foo) .. )",
1559                                      "(ly:paper-get-font (ly:grob-get-paper foo) .. )"))
1560                 error_file.write (UPDATE_MANUALLY)
1561                 error_file.write ('\n')
1562                 raise FatalConversionError ()
1563
1564         if re.search ("\\pitch *#", str) :
1565                 error_file.write ('\n')
1566                 error_file.write (NOT_SMART % "\\pitch")
1567                 error_file.write ('\n')
1568                 error_file.write ("Use Scheme code to construct arbitrary note events.")
1569                 error_file.write ('\n')
1570
1571                 raise FatalConversionError ()
1572
1573         return str
1574
1575
1576 conversions.append (((1,9,6), conv, 'ly:get-font deprecated.'))
1577
1578 def conv (str):
1579         def sub_alteration (m):
1580                 alt = m.group (3)
1581                 alt = {
1582                         '-1': 'FLAT',
1583                         '-2': 'DOUBLE-FLAT',
1584                         '0': 'NATURAL',
1585                         '1': 'SHARP',
1586                         '2': 'DOUBLE-SHARP',
1587                         }[alt]
1588
1589                 return '(ly:make-pitch %s %s %s)' % (m.group(1), m.group (2),
1590                                                      alt)
1591
1592         str =re.sub ("\\(ly:make-pitch *([0-9-]+) *([0-9-]+) *([0-9-]+) *\\)",
1593                      sub_alteration, str)
1594
1595
1596         str = re.sub ("ly:verbose", "ly:get-option 'verbose", str)
1597
1598         m= re.search ("\\\\outputproperty #([^#]+)[\t\n ]*#'([^ ]+)", str)
1599         if m:
1600                 error_file.write (\
1601                         r"""\outputproperty found,
1602 Please hand-edit, using
1603
1604   \applyoutput #(outputproperty-compatibility %s '%s <GROB PROPERTY VALUE>)
1605
1606 as a substitution text.""" % (m.group (1), m.group (2)) )
1607                 raise FatalConversionError ()
1608
1609         if re.search ("ly:(make-pitch|pitch-alteration)", str) \
1610                or re.search ("keySignature", str):
1611                 error_file.write ('\n')
1612                 error_file.write (NOT_SMART % "pitches")
1613                 error_file.write ('\n')
1614                 error_file.write (
1615 """The alteration field of Scheme pitches was multiplied by 2
1616 to support quarter tone accidentals.  You must update the following constructs by manually:
1617
1618 * calls of ly:make-pitch and ly:pitch-alteration
1619 * keySignature settings made with \property
1620 """)
1621                 raise FatalConversionError ()
1622
1623         return str
1624 conversions.append (((1,9,7), conv,
1625                      '''use symbolic constants for alterations,
1626 remove \\outputproperty, move ly:verbose into ly:get-option'''))
1627
1628
1629 def conv (str):
1630         if re.search ("dash-length",str):
1631                 error_file.write ('\n')
1632                 error_file.write (NOT_SMART % "dash-length")
1633                 error_file.write ('\n')
1634                 error_file.write (FROM_TO % ("dash-length", "dash-fraction"))
1635                 error_file.write ('\n')
1636                 error_file.write (UPDATE_MANUALLY)
1637                 error_file.write ('\n')
1638                 raise FatalConversionError ()
1639         return str
1640
1641 conversions.append (((1,9,8), conv, """dash-length -> dash-fraction"""))
1642
1643
1644 def conv (str):
1645         def func(match):
1646                 return "#'font-size = #%d" % (2*string.atoi (match.group (1)))
1647
1648         str =re.sub (r"#'font-relative-size\s*=\s*#\+?([0-9-]+)", func, str)
1649         str =re.sub (r"#'font-family\s*=\s*#'ancient",
1650                      r"#'font-family = #'music", str)
1651
1652         return str
1653
1654 conversions.append (((2,1,1), conv, """font-relative-size -> font-size"""))
1655
1656 def conv (str):
1657         str =re.sub (r"ly:get-music-length", "ly:music-length", str)
1658         return str
1659
1660 conversions.append (((2,1,2), conv, """ly:get-music-length -> ly:music-length"""))
1661
1662 def conv (str):
1663         str =re.sub (r"\.\s+stz=", ". instr ", str)
1664         return str
1665
1666 conversions.append (((2,1,3), conv, """stanza -> instrument"""))
1667
1668 def conv (str):
1669         def func (match):
1670                 c = match.group (1)
1671                 b = match.group (2)
1672
1673                 if b == 't':
1674                         if c == 'Score':
1675                                 return ''
1676                         else:
1677                                 return r" \property %s.melismaBusyProperties \unset"  % c
1678                 elif b == 'f':
1679                         return r"\property %s.melismaBusyProperties = #'(melismaBusy)"  % c
1680
1681         str = re.sub (r"\\property ([a-zA-Z]+)\s*\.\s*automaticMelismata\s*=\s*##([ft])", func, str)
1682         return str
1683
1684 conversions.append (((2,1,4), conv, """removal of automaticMelismata; use melismaBusyProperties instead."""))
1685
1686
1687
1688 def conv (str):
1689         str =re.sub (r"\\translator\s+([a-zA-Z]+)", r"\\change \1", str)
1690         return str
1691
1692 conversions.append (((2,1,7), conv, """\\translator Staff -> \\change Staff"""))
1693
1694 def conv (str):
1695         str =re.sub (r"\\newaddlyrics", r"\\lyricsto", str)
1696         return str
1697
1698 conversions.append (((2,1,10), conv, """\\newaddlyrics -> \\lyricsto"""))
1699
1700 def conv (str):
1701         str = re.sub (r'\\include\s*"paper([0-9]+)(-init)?.ly"',
1702                       r"#(set-staff-size \1)", str)
1703
1704         def sub_note (match):
1705                 dur = ''
1706                 log = string.atoi (match.group (1))
1707                 dots = string.atoi (match.group (2))
1708
1709                 if log >= 0:
1710                         dur = '%d' % (1 << log)
1711                 else:
1712                         dur = { -1 : 'breve',
1713                                 -2 : 'longa',
1714                                 -3 : 'maxima'}[log]
1715
1716                 dur += ('.' * dots)
1717
1718                 return r'\note #"%s" #%s' % (dur, match.group (3))
1719
1720         str = re.sub (r'\\note\s+#([0-9-]+)\s+#([0-9]+)\s+#([0-9.-]+)',
1721                       sub_note, str)
1722         return str
1723
1724 conversions.append (((2,1,11), conv, """\\include "paper16.ly" -> #(set-staff-size 16)
1725 \\note #3 #1 #1 -> \\note #"8." #1
1726 """))
1727
1728
1729 def conv (str):
1730         str =re.sub (r"OttavaSpanner", r"OttavaBracket", str)
1731         return str
1732
1733 conversions.append (((2,1,12), conv, """OttavaSpanner -> OttavaBracket"""))
1734
1735
1736 def conv (str):
1737         str =re.sub (r"\(set-staff-size ", r"(set-global-staff-size ", str)
1738         return str
1739
1740 conversions.append (((2,1,13), conv, """set-staff-size -> set-global-staff-size"""))
1741
1742 def conv (str):
1743         str =re.sub (r"#'style\s*=\s*#'dotted-line",
1744                      r"#'dash-fraction = #0.0 ", str)
1745         return str
1746
1747 conversions.append (((2,1,14), conv, """style = dotted -> dash-fraction = 0"""))
1748
1749 def conv (str):
1750         str =re.sub (r'LyricsVoice\s*\.\s*instrument\s*=\s*("[^"]*")',
1751                      r'LyricsVoice . vocalName = \1', str)
1752
1753         str =re.sub (r'LyricsVoice\s*\.\s*instr\s*=\s*("[^"]*")',
1754                      r'LyricsVoice . vocNam = \1', str)
1755         return str
1756
1757 conversions.append (((2,1,15), conv, """LyricsVoice . instr(ument) -> vocalName"""))
1758
1759 def conv (str):
1760         def sub_acc (m):
1761                 d = {
1762                 '4': 'doublesharp',
1763                 '3': 'threeqsharp',
1764                 '2': 'sharp',
1765                 '1': 'semisharp',
1766                 '0': 'natural',
1767                 '-1': 'semiflat',
1768                 '-2': 'flat',
1769                 '-3': 'threeqflat',
1770                 '-4': 'doubleflat'}
1771                 return '\\%s' %  d[m.group (1)]
1772
1773         str = re.sub (r'\\musicglyph\s*#"accidentals-([0-9-]+)"',
1774                       sub_acc, str)
1775         return str
1776
1777 conversions.append (((2,1,16), conv, """\\musicglyph #"accidentals-NUM" -> \\sharp/flat/etc."""))
1778
1779
1780 def conv (str):
1781
1782         if re.search (r'\\partcombine', str):
1783                 error_file.write ('\n')
1784                 error_file.write (NOT_SMART % "\\partcombine")
1785                 error_file.write ('\n')
1786                 error_file.write (UPDATE_MANUALLY)
1787                 error_file.write ('\n')
1788                 raise FatalConversionError ()
1789
1790         # this rule doesn't really work,
1791         # too lazy to figure out why.
1792         str = re.sub (r'\\context\s+Voice\s*=\s*one\s*\\partcombine\s+Voice\s*\\context\s+Thread\s*=\s*one(.*)\s*'
1793                       + r'\\context\s+Thread\s*=\s*two',
1794                       '\\\\newpartcombine\n\\1\n', str)
1795
1796
1797         return str
1798
1799 conversions.append (((2,1,17), conv, """\\partcombine syntax change to \\newpartcombine"""))
1800
1801
1802 def conv (str):
1803         str = re.sub (r'\\newpartcombine', r'\\partcombine', str)
1804         str = re.sub (r'\\autochange\s+Staff', r'\\autochange ', str)
1805         return str
1806
1807 conversions.append (((2,1,18), conv, """\\newpartcombine -> \\partcombine,
1808 \\autochange Staff -> \\autochange
1809 """))
1810
1811
1812
1813
1814 def conv (str):
1815         if re.search ('include "drumpitch', str):
1816                 error_file.write ("Drums found. Enclose drum notes in \\drummode")
1817                 
1818         str = re.sub (r'\\include "drumpitch-init.ly"','', str)
1819         
1820         str = re.sub (r'\\pitchnames ','pitchnames = ', str)
1821         str = re.sub (r'\\chordmodifiers ','chordmodifiers = ', str)
1822         str = re.sub (r'\bdrums\b\s*=','drumContents = ', str)
1823         str = re.sub (r'\\drums\b','\\drumContents ', str)
1824
1825
1826         if re.search ('drums->paper', str):
1827                 error_file.write ("\nDrum notation found. Check file manually!")
1828
1829         str = re.sub (r"""\\apply\s+#\(drums->paper\s+'([a-z]+)\)""",
1830                       r"""\property DrumStaff.drumStyleTable = #\1-style""",
1831                       str)
1832
1833         if re.search ('Thread', str):
1834                 error_file.write ("\nThread found. Check file manually!\n");
1835
1836         str = re.sub (r"""(\\once\s*)?\\property\s+Thread\s*\.\s*NoteHead\s*"""
1837                       + r"""\\(set|override)\s*#'style\s*=\s*#'harmonic"""
1838                       + r"""\s+([a-z]+[,'=]*)([0-9]*\.*)"""
1839                       ,r"""<\3\\harmonic>\4""", str)
1840
1841         str = re.sub (r"""\\new Thread""", """\context Voice""", str)
1842         str = re.sub (r"""Thread""", """Voice""", str)
1843
1844         if re.search ('\bLyrics\b', str):
1845                 error_file.write ("\nLyrics found. Check file manually!\n");
1846
1847         str = re.sub (r"""LyricsVoice""", r"""L@ricsVoice""", str)
1848         str = re.sub (r"""\bLyrics\b""", r"""LyricsVoice""", str)
1849         str = re.sub (r"""LyricsContext""", r"""LyricsVoiceContext""", str)
1850         str = re.sub (r"""L@ricsVoice""", r"""LyricsVoice""",str)
1851
1852
1853         return str
1854
1855 conversions.append (((2,1,19), conv, """Drum notation changes, Removing \\chordmodifiers, \\notenames.
1856 Harmonic notes. Thread context removed. Lyrics context removed."""))
1857
1858 def conv (str):
1859         str = re.sub (r'nonevent-skip', 'skip-music', str)
1860         return str
1861
1862 conversions.append (((2,1,20), conv, """nonevent-skip -> skip-music""" ))
1863
1864 def conv (str):
1865         str = re.sub (r'molecule-callback', 'print-function', str)
1866         str = re.sub (r'brew_molecule', 'print', str)
1867         str = re.sub (r'brew-new-markup-molecule', 'Text_item::print', str)
1868         str = re.sub (r'LyricsVoice', 'Lyrics', str)
1869         str = re.sub (r'tupletInvisible',
1870                       r"TupletBracket \\set #'transparent", str)
1871 #       str = re.sub (r'molecule', 'collage', str)
1872 #molecule -> collage
1873         str = re.sub (r"\\property\s+[a-zA-Z]+\s*\.\s*[a-zA-Z]+\s*"
1874                       + r"\\set\s*#'X-extent-callback\s*=\s*#Grob::preset_extent",
1875                       "", str)
1876
1877         return str
1878
1879 conversions.append (((2,1,21), conv, """molecule-callback -> print-function,
1880 brew_molecule -> print
1881 brew-new-markup-molecule -> Text_item::print
1882 LyricsVoice -> Lyrics
1883 tupletInvisible -> TupletBracket \set #'transparent
1884 Grob::preset_extent removed.
1885 """ ))
1886
1887
1888 def conv (str):
1889         str = re.sub (r'(\\property[^=]+)=\s*([-0-9]+)',
1890                       r'\1= #\2', str)
1891         str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\=]+)\s*\\(set|override)',
1892                       r"\\overrid@ \1.\2 ", str)
1893         str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*=\s*',
1894                       r'\\s@t \1.\2 = ', str)
1895         str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*\\unset',
1896                       r'\\uns@t \1.\2 ', str)
1897         str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*\\revert'
1898                       + r"\s*#'([-a-z0-9_]+)",
1899                       r"\\rev@rt \1.\2 #'\3", str)
1900         str = re.sub (r'Voice\.', '', str)
1901         str = re.sub (r'Lyrics\.', '', str)
1902         str = re.sub (r'ChordNames\.', '', str)
1903
1904         str = re.sub ('rev@rt', 'revert',str)
1905         str = re.sub ('s@t', 'set',str)
1906         str = re.sub ('overrid@', 'override',str)
1907
1908         str = re.sub ('molecule', 'stencil', str)
1909         str = re.sub ('Molecule', 'Stencil', str)
1910         return str
1911
1912 conversions.append (((2,1,22), conv, """new syntax for property settings:
1913         \\set A.B = #C , \\unset A.B
1914         \\override A.B #C = #D, \\revert A.B #C
1915
1916 """))
1917
1918 def conv (str):
1919         def subst_in_trans (match):
1920                 s = match.group (0)
1921                 s = re.sub (r'\s([a-zA-Z]+)\s*\\override',
1922                               r' \\override \1', s)
1923                 s = re.sub (r'\s([a-zA-Z]+)\s*\\set',
1924                               r' \\override \1', s)
1925                 s = re.sub (r'\s([a-zA-Z]+)\s*\\revert',
1926                               r' \\revert \1', s)
1927                 return s
1928         str = re.sub (r'\\(translator|with)\s*{[^}]+}',  subst_in_trans, str)
1929
1930         def sub_abs (m):
1931
1932                 context = m.group ('context')
1933                 d = m.groupdict ()
1934                 if context:
1935                         context = " '%s" % context[:-1] # -1: remove .
1936                 else:
1937                         context = ''
1938
1939                 d['context'] = context
1940
1941                 return r"""#(override-auto-beam-setting %(prop)s %(num)s %(den)s%(context)s)""" % d
1942
1943         str = re.sub (r"""\\override\s*(?P<context>[a-zA-Z]+\s*\.\s*)?autoBeamSettings"""
1944                       +r"""\s*#(?P<prop>[^=]+)\s*=\s*#\(ly:make-moment\s+(?P<num>\d+)\s+(?P<den>\d)\s*\)""",
1945                       sub_abs, str)
1946
1947         return str
1948
1949 conversions.append (((2,1,23), conv, """Property setting syntax in \\translator{ }"""))
1950 def conv (str):
1951         str = re.sub (r'music-list\?', 'ly:music-list?', str)
1952         str = re.sub (r'\|\s*~', '~ |', str)
1953         return str
1954
1955 conversions.append (((2,1,24), conv, """music-list? -> ly:music-list?"""))
1956
1957 def conv (str):
1958         str = re.sub (r'ly:get-spanner-bound', 'ly:spanner-get-bound', str)
1959         str = re.sub (r'ly:get-extent', 'ly:grob-extent', str)
1960         str = re.sub (r'ly:get-system', 'ly:grob-system', str)
1961         str = re.sub (r'ly:get-original', 'ly:grob-original', str)
1962         str = re.sub (r'ly:get-parent', 'ly:grob-parent', str)
1963         str = re.sub (r'ly:get-broken-into', 'ly:spanner-broken-into', str)
1964         str = re.sub (r'Melisma_engraver', 'Melisma_translator', str)
1965         if re.search ("ly:get-paper-variable", str):
1966                 error_file.write ('\n')
1967                 error_file.write (NOT_SMART % "ly:paper-get-variable")
1968                 error_file.write ('\n')
1969                 error_file.write ('use (ly:paper-lookup (ly:grob-paper ))')
1970                 error_file.write ('\n')
1971                 raise FatalConversionError ()
1972
1973         str = re.sub (r'\\defaultAccidentals', "#(set-accidental-style 'default)", str)
1974         str = re.sub (r'\\voiceAccidentals', "#(set-accidental-style 'voice)", str)
1975         str = re.sub (r'\\modernAccidentals', "#(set-accidental-style 'modern)", str)
1976         str = re.sub (r'\\modernCautionaries', "#(set-accidental-style 'modern-cautionary)", str)
1977         str = re.sub (r'\\modernVoiceAccidental', "#(set-accidental-style 'modern-voice)", str)
1978         str = re.sub (r'\\modernVoiceCautionaries', "#(set-accidental-style 'modern-voice-cautionary)", str)
1979         str = re.sub (r'\\pianoAccidentals', "#(set-accidental-style 'piano)", str)
1980         str = re.sub (r'\\pianoCautionaries', "#(set-accidental-style 'piano-cautionary)", str)
1981         str = re.sub (r'\\forgetAccidentals', "#(set-accidental-style 'forget)", str)
1982         str = re.sub (r'\\noResetKey', "#(set-accidental-style 'no-reset)", str)
1983
1984         return str
1985
1986 conversions.append (((2,1,25), conv, """Scheme grob function renaming"""))
1987
1988
1989 def conv (str):
1990         str = re.sub ('ly:set-grob-property!', 'ly:grob-set-property!',str)
1991         str = re.sub ('ly:set-mus-property!', 'ly:music-set-property!',str)
1992         str = re.sub ('ly:set-context-property!', 'ly:context-set-property!', str)
1993         str = re.sub ('ly:get-grob-property', 'ly:grob-property',str)
1994         str = re.sub ('ly:get-mus-property', 'ly:music-property',str)
1995         str = re.sub ('ly:get-context-property', 'ly:context-property',str)
1996
1997         return str
1998
1999 conversions.append (((2,1,26), conv, """More Scheme function renaming"""))
2000
2001 def conv (str):
2002         def subst (m):
2003                 g = string.atoi (m.group (2))
2004                 o = g / 12
2005                 g -= o * 12
2006                 if g <  0:
2007                         g += 12
2008                         o -= 1
2009
2010
2011                 lower_pitches = filter (lambda x : x <= g, [0, 2, 4, 5, 7, 9, 11, 12])
2012                 s = len (lower_pitches) -1
2013                 a = g - lower_pitches [-1]
2014
2015
2016                 print s , lower_pitches, g, a, s
2017                 str = 'cdefgab' [s]
2018                 str += ['eses', 'es', '', 'is', 'isis'][a + 2]
2019                 if o < 0:
2020                         str += ',' * (-o - 1)
2021                 elif o >= 0:
2022                         str += "'" * (o + 1)
2023
2024                 return '\\transposition %s ' % str
2025
2026
2027         str = re.sub (r"\\set ([A-Za-z]+\s*\.\s*)?transposing\s*=\s*#([-0-9]+)",
2028                       subst, str)
2029         return str
2030
2031 conversions.append (((2,1,27), conv, """property transposing -> tuning"""))
2032
2033 def conv (str):
2034         str = re.sub (r'make-music-by-name', 'make-music', str)
2035         str = re.sub (r"\\override\s+.*Arpeggio\s+#.print-function\s+=\s+\\arpeggioBracket", r"\\arpeggioBracket", str)
2036         return str
2037
2038 conversions.append (((2,1,28), conv,
2039                      """make-music-by-name -> make-music,
2040 new syntax for setting \\arpeggioBracket"""))
2041
2042 def conv (str):
2043         str = re.sub (r'\\center([^-])', '\\center-align\\1', str)
2044         str = re.sub (r'\\translator', '\\context', str)
2045         return str
2046
2047 conversions.append (((2,1,29), conv,
2048                      '\\center -> \\center-align, \\translator -> \\context'))
2049
2050
2051 def conv (str):
2052         str = re.sub (r'\\threeq(flat|sharp)', r'\\sesqui\1', str)
2053         str = re.sub (r'ly:stencil-get-extent',
2054                       'ly:stencil-extent', str)
2055         str = re.sub (r'ly:translator-find',
2056                       'ly:context-find', str)
2057         str = re.sub ('ly:unset-context-property','ly:context-unset-property',
2058                       str)
2059
2060         str = re.sub (r'ly:get-mutable-properties',
2061                       'ly:mutable-music-properties',str)
2062         str = re.sub (r'centralCPosition',
2063                       'middleCPosition',str)
2064         return str
2065
2066 conversions.append (((2,1,30), conv,
2067                      '''\\threeq{flat,sharp} -> \\sesqui{flat,sharp}
2068 ly:get-mutable-properties -> ly:mutable-music-properties
2069 centralCPosition -> middleCPosition
2070 ly:unset-context-property -> ly:context-unset-property
2071 ly:translator-find -> ly:context-find
2072 ly:get-stencil-extent -> ly:stencil-extent
2073 '''))
2074
2075
2076 def conv (str):
2077         str = re.sub (r'\\alias\s*"?Timing"?', '', str)
2078         return str
2079
2080 conversions.append (((2,1,31), conv,
2081                      '''remove \\alias Timing'''))
2082
2083 def conv (str):
2084         str = re.sub (r"(\\set\s+)?(?P<context>(Score\.)?)breakAlignOrder\s*=\s*#'(?P<list>[^\)]+)",
2085                       r"\n\\override \g<context>BreakAlignment #'break-align-orders = "
2086                       + "#(make-vector 3 '\g<list>)", str)
2087
2088         return str
2089
2090 conversions.append (((2,1,33), conv,
2091                      '''breakAlignOrder -> break-align-orders.'''))
2092
2093 def conv (str):
2094         str = re.sub (r"\(set-paper-size",
2095                       "(set-default-paper-size",str)
2096         return str
2097
2098 conversions.append (((2,1,34), conv,
2099                      '''set-paper-size -> set-default-paper-size.'''))
2100
2101 def conv (str):
2102         str = re.sub (r"ly:mutable-music-properties",
2103                       "ly:music-mutable-properties", str)
2104         return str
2105
2106 conversions.append (((2,1, 36), conv,
2107                      '''ly:mutable-music-properties -> ly:music-mutable-properties'''))
2108
2109
2110
2111 def conv (str):
2112         return str
2113
2114 conversions.append (((2, 2, 0), conv,
2115                      '''clean up version. '''))
2116
2117 def conv (str):
2118         return re.sub (r'\\apply\b', r'\\applymusic', str)
2119
2120 conversions.append (((2, 3, 1), conv,
2121                      '''\\apply -> \\applymusic'''))
2122
2123 def conv (str):
2124         if re.search ('textheight', str):
2125                 error_file.write ('\n')
2126                 error_file.write (NOT_SMART % "textheight")
2127                 error_file.write ('\n')
2128                 error_file.write (UPDATE_MANUALLY)
2129                 error_file.write ('\n')
2130                 error_file.write (
2131 """Page layout has been changed, using paper size and margins.
2132 textheight is no longer used.
2133 """)
2134         str = re.sub (r'\\OrchestralScoreContext', '\\Score', str)
2135         def func(m):
2136                 if m.group(1) not in ['RemoveEmptyStaff',
2137                                       'AncientRemoveEmptyStaffContext',
2138                                       'EasyNotation']:
2139                         return '\\' + m.group (1)
2140                 else:
2141                         return m.group (0)
2142
2143
2144         str = re.sub (r'\\([a-zA-Z]+)Context\b', func, str)
2145         str = re.sub ('ly:paper-lookup', 'ly:output-def-lookup', str)
2146         return str
2147
2148 conversions.append (((2, 3, 2), conv,
2149                      '''\\FooContext -> \\Foo'''))
2150
2151 def conv (str):
2152         str = re.sub (r'\\notes\b', '', str)
2153
2154         return str
2155
2156 conversions.append (((2, 3, 4), conv,
2157                      '''remove \\notes'''))
2158
2159
2160
2161 def conv (str):
2162         str = re.sub (r'lastpagefill\s*=\s*"?1"', 'raggedlastbottom = ##t', str)
2163         return str
2164
2165 conversions.append (((2, 3, 6), conv,
2166                      '''lastpagefill -> raggedlastbottom'''))
2167
2168
2169
2170 def conv (str):
2171         str = re.sub (r'\\consistsend', '\\consists', str)
2172         str = re.sub (r'\\lyricsto\s+("?[a-zA-Z]+"?)(\s*\\new Lyrics\s*)?\\lyrics',
2173                       r'\\lyricsto \1 \2', str)
2174         return str
2175
2176 conversions.append (((2, 3, 8), conv,
2177                      '''remove \\consistsend, strip \\lyrics from \\lyricsto.'''))
2178
2179 def conv (str):
2180         str = re.sub (r'neo_mensural', 'neomensural', str)
2181         str = re.sub (r'if-text-padding', 'bound-padding', str)
2182         return str
2183
2184 conversions.append (((2, 3, 9), conv,
2185                      '''neo_mensural -> neomensural, if-text-padding -> bound-padding'''))
2186
2187
2188
2189 def conv (str):
2190         str = re.sub (r'\\addlyrics', r'\\oldaddlyrics', str)
2191         str = re.sub (r'\\newlyrics', r'\\addlyrics', str)
2192         if re.search (r"\\override\s*TextSpanner", str):
2193                 error_file.write ("\nWarning: TextSpanner has been split into DynamicTextSpanner and TextSpanner\n")
2194         return str
2195
2196 conversions.append (((2, 3, 10), conv,
2197                      '''\\addlyrics -> \\oldaddlyrics, \\newlyrics -> \\addlyrics'''))
2198
2199 def conv (str):
2200         str = re.sub (r'\\setMmRestFermata\s+(R[0-9.*/]*)',
2201                       r'\1^\\fermataMarkup', str)
2202         return str
2203
2204 conversions.append (((2, 3, 11), conv,
2205                      '''\\setMmRestFermata -> ^\\fermataMarkup'''))
2206
2207 def conv (str):
2208         str = re.sub (r'\\newpage', r'\\pageBreak', str)
2209         str = re.sub (r'\\scriptUp', r"""{
2210   \\override TextScript  #'direction = #1
2211   \\override Script  #'direction = #1
2212 }""", str)
2213         str = re.sub (r'\\scriptDown', r"""{
2214   \\override TextScript  #'direction = #-1
2215   \\override Script  #'direction = #-1
2216 }""", str)
2217         str = re.sub (r'\\scriptBoth', r"""{
2218   \\revert TextScript  #'direction
2219   \\revert Script  #'direction
2220 }""", str)
2221         str = re.sub ('soloADue', 'printPartCombineTexts', str)
2222         str = re.sub (r'\\applymusic\s*#notes-to-clusters',
2223                       '\\makeClusters', str)
2224
2225         str = re.sub (r'pagenumber\s*=', 'firstpagenumber = ', str)
2226         return str
2227
2228 conversions.append (((2, 3, 12), conv,
2229                      '''\\newpage -> \\pageBreak, junk \\script{up,down,both},
2230 soloADue -> printPartCombineTexts, #notes-to-clusters -> \\makeClusters
2231 '''))
2232
2233
2234 def conv (str):
2235         str = re.sub (r'\\chords\b', r'\\chordmode', str)
2236         str = re.sub (r'\\lyrics\b', r'\\lyricmode', str)
2237         str = re.sub (r'\\figures\b', r'\\figuremode', str)
2238         str = re.sub (r'\\notes\b', r'\\notemode', str)
2239         str = re.sub (r'\\drums\b', r'\\drummode', str)
2240         str = re.sub (r'\\chordmode\s*\\new ChordNames', r'\\chords', str)
2241         str = re.sub (r'\\new ChordNames\s*\\chordmode', r'\\chords', str)
2242         str = re.sub (r'\\new FiguredBass\s*\\figuremode', r'\\figures', str)
2243         str = re.sub (r'\\figuremode\s*\new FiguredBass', r'\\figures', str)
2244         str = re.sub (r'\\new DrumStaff\s*\\drummode', r'\\drums', str)
2245         str = re.sub (r'\\drummode\s*\\new DrumStaff', r'\\drums', str)
2246
2247         return str
2248
2249 conversions.append (((2, 3, 16), conv,
2250                      '''\\foo -> \\foomode (for chords, notes, etc.)
2251 fold \\new FooContext \\foomode into \\foo.'''))
2252
2253 def conv (str):
2254         str = re.sub (r'(slur|stem|phrasingSlur|tie|dynamic|dots|tuplet|arpeggio|)Both', r'\1Neutral', str)
2255         str = re.sub (r"\\applymusic\s*#\(remove-tag\s*'([a-z-0-9]+)\)",
2256                       r"\\removeWithTag #'\1", str)
2257         return str
2258
2259 conversions.append (((2, 3, 17), conv,
2260                      '''\\foo -> \\foomode (for chords, notes, etc.)
2261 fold \\new FooContext \\foomode into \\foo.'''))
2262
2263
2264 def conv (str):
2265         str = re.sub (r'Text_item', 'Text_interface', str)
2266         return str
2267
2268 conversions.append (((2, 3, 18),
2269                      conv,
2270                      '''Text_item -> Text_interface''' ))
2271
2272 def conv (str):
2273         str = re.sub (r'\\paper', r'\\layout', str)
2274         str = re.sub (r'\\bookpaper', r'\\paper', str)
2275         if re.search ('paper-set-staff-size', str):
2276                 error_file.write ('''\nWarning: staff size should be changed at top-level
2277 with
2278
2279   #(set-global-staff-size <STAFF-HEIGHT-IN-POINT>)
2280
2281 ''')
2282
2283
2284         str = re.sub (r'#\(paper-set-staff-size', '%Use set-global-staff-size at toplevel\n% #(layout-set-staff-size', str)
2285         return str
2286
2287 conversions.append (((2, 3, 22),
2288                      conv,
2289                      '''paper -> layout
2290  bookpaper -> paper''' ))
2291
2292
2293 def conv (str):
2294         str = re.sub (r'\\context\s+([a-zA-Z]+)\s*=\s*([a-z]+)\s',
2295                       r'\\context \1 = "\2" ',
2296                       str )
2297         return str
2298
2299 conversions.append (((2, 3, 23),
2300                      conv,
2301                      '''\context Foo = NOTENAME -> \context Foo = "NOTENAME"'''))
2302
2303 def conv (str):
2304         def sub(m):
2305                 return regularize_id (m.group (1))
2306         str = re.sub (r'(maintainer_email|maintainer_web|midi_stuff|gourlay_maxmeasures)',
2307                       sub, str)
2308         return str
2309
2310 conversions.append (((2, 3, 24),
2311                      conv,
2312                      '''regularize other identifiers.'''))
2313
2314
2315 def conv (str):
2316         return str
2317
2318 conversions.append (((2, 4, 0),
2319                      conv,
2320                      ''))
2321
2322
2323 def conv (str):
2324         str = re.sub (r'\\quote\s+"?([a-zA-Z0-9]+)"?\s+([0-9.*/]+)',
2325                       r'\\quoteDuring #"\1" { \skip \2 }',
2326                       str
2327                       )
2328         return str
2329
2330 conversions.append (((2, 5, 0),
2331                      conv,
2332                      ''))
2333
2334
2335 def conv (str):
2336         str = re.sub (r'ly:import-module',
2337                       r'ly:module-copy', str)
2338         return str
2339
2340 conversions.append (((2, 5, 1),
2341                      conv,
2342                      'ly:import-module -> ly:module-copy'))
2343
2344 def conv (str):
2345         str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>',
2346                       r'\\\1 {\2}', str)
2347         str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>',
2348                       r'\\\1 {\2}', str)
2349         str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>',
2350                       r'\\\1 {\2}', str)
2351         def get_markup (m):
2352                 s = m.group (0)
2353                 s = re.sub (r'''((\\"|})\s*){''', '\2 \\line {', s)
2354                 return s
2355         str = re.sub (r'\\markup\s*{([^}]|{[^}]*})*}', get_markup, str)
2356         return str
2357
2358 conversions.append (((2, 5, 2),
2359                      conv,
2360                      '\markup .. < .. > .. -> \markup .. { .. } ..'))
2361
2362 def conv (str):
2363         str = re.sub ('ly:find-glyph-by-name', 'ly:font-get-glyph', str)
2364         str = re.sub ('"(scripts|clefs|accidentals)-', r'"\1.', str)
2365         str = re.sub ("'hufnagel-do-fa", "'hufnagel.do.fa", str)
2366         str = re.sub ("'(vaticana|hufnagel|medicaea|petrucci|neomensural|mensural)-", r"'\1.", str)
2367         return str
2368
2369 conversions.append (((2, 5, 3),
2370                      conv,
2371                      'ly:find-glyph-by-name -> ly:font-get-glyph, remove - from glyphnames.'))
2372
2373
2374 def conv (str):
2375         str = re.sub (r"\\override\s+(Voice\.)?Slur #'dashed\s*=\s*#\d*(\.\d+)?",
2376                       r"\\slurDashed", str)
2377         return str
2378
2379 conversions.append (((2, 5, 12),
2380                      conv,
2381                      '\set Slur #\'dashed = #X -> \slurDashed'))
2382
2383 def conv (str):
2384         input_encoding = 'latin1'
2385         def func (match):
2386                 encoding = match.group (1)
2387
2388                 # FIXME: automatic recoding of other than latin1?
2389                 if encoding == 'latin1':
2390                         return match.group (2)
2391
2392                 error_file.write ('\n')
2393                 error_file.write (NOT_SMART % ("\\encoding: %s" % encoding))
2394                 error_file.write ('\n')
2395                 error_file.write (_ ("LilyPond source must be UTF-8"))
2396                 error_file.write ('\n')
2397                 if encoding == 'TeX':
2398                         error_file.write (_ ("Try the texstrings backend"))
2399                         error_file.write ('\n')
2400                 else:
2401                         error_file.write ( _("Do something like: %s") % \
2402                                            ("recode %s..utf-8 FILE" % encoding))
2403                         error_file.write ('\n')
2404                 error_file.write (_ ("Or save as UTF-8 in your editor"))
2405                 error_file.write ('\n')
2406                 raise FatalConversionError ()
2407
2408                 return match.group (0)
2409
2410         str = re.sub (r'\\encoding\s+"?([a-zA-Z0-9]+)"?(\s+)', func, str)
2411
2412         import codecs
2413         de_ascii = codecs.getdecoder ('ascii')
2414         de_utf_8 = codecs.getdecoder ('utf_8')
2415         de_input = codecs.getdecoder (input_encoding)
2416         en_utf_8 = codecs.getencoder ('utf_8')
2417         try:
2418                 de_ascii (str)
2419         # only in python >= 2.3
2420         # except UnicodeDecodeError:
2421         except UnicodeError:
2422                 # do not re-recode UTF-8 input
2423                 try:
2424                         de_utf_8 (str)
2425                 #except UnicodeDecodeError:
2426                 except UnicodeError:
2427                         str = en_utf_8 (de_input (str)[0])[0]
2428
2429
2430
2431         str = re.sub (r"#\(ly:set-point-and-click '[a-z-]+\)", '', str)
2432         return str
2433
2434 conversions.append (((2, 5, 13),
2435                      conv,
2436                      '\\encoding: smart recode latin1..utf-8. Remove ly:point-and-click'))
2437
2438
2439 def conv (str):
2440         if re.search ("ly:stencil-set-extent!", str):
2441                 error_file.write ('\n')
2442                 error_file.write (NOT_SMART % "ly:stencil-set-extent!")
2443                 error_file.write ('\n')
2444                 error_file.write ('use (set! VAR (ly:make-stencil (ly:stencil-expr VAR) X-EXT Y-EXT))\n')
2445                 raise FatalConversionError ()
2446         if re.search ("ly:stencil-align-to!", str):
2447                 error_file.write ('\n')
2448                 error_file.write (NOT_SMART % "ly:stencil-align-to!")
2449                 error_file.write ('\n')
2450                 error_file.write ('use (set! VAR (ly:stencil-aligned-to VAR AXIS DIR))\n')
2451                 raise FatalConversionError ()
2452         return str
2453
2454 conversions.append (((2, 5, 17),
2455                      conv,
2456                      'ly:stencil-set-extent! removed'))
2457                     
2458 def conv (str):
2459         str = re.sub (r"ly:warn\b", 'ly:warning', str)
2460         return str
2461
2462 conversions.append (((2, 5, 18),
2463                      conv,
2464                      'ly:warn -> ly:warning'))
2465 def conv (str):
2466         if re.search ("(override-|revert-)auto-beam-setting", str)\
2467            or re.search ("autoBeamSettings", str):
2468                 error_file.write ('\n')
2469                 error_file.write (NOT_SMART % "auto beam settings")
2470                 error_file.write ('\n')
2471                 error_file.write ('''
2472 Auto beam settings must now specify each interesting moment in a measure
2473 explicitely; 1/4 is no longer multiplied to cover moments 1/2 and 3/4 too.
2474 ''')
2475                 error_file.write (UPDATE_MANUALLY)
2476                 error_file.write ('\n')
2477                 raise FatalConversionError ()
2478         return str
2479
2480 conversions.append (((2, 5, 21),
2481                      conv,
2482                      'warn about auto beam settings'))
2483
2484 def conv (str):
2485         str = re.sub (r"unfoldrepeats", 'unfoldRepeats', str)
2486         str = re.sub (r"compressmusic", 'compressMusic', str)
2487         return str
2488
2489 conversions.append (((2, 5, 25), conv,
2490
2491                      'unfoldrepeats -> unfoldRepeats,'
2492                      + 'compressmusic -> compressMusic'))
2493
2494 def conv (str):
2495         return str
2496
2497 conversions.append (((2, 6, 0), conv,
2498
2499                      'dummy rule for 2.6')) 
2500
2501
2502
2503 def conv (str):
2504         return re.sub('ly:get-default-font', 'ly:grob-default-font', str) 
2505
2506 conversions.append (((2, 7, 0), conv,
2507                      'ly:get-default-font -> ly:grob-default-font'))
2508
2509 def conv (str):
2510         str = re.sub('ly:parser-define', 'ly:parser-define!', str)
2511         str = re.sub('excentricity', 'eccentricity', str)
2512         str = re.sub(r'\\(consists|remove) *"?Timing_engraver"?',
2513                      r'\\\1 "Timing_translator" \\\1 "Default_bar_line_engraver"',
2514                      str)
2515         return str
2516
2517 conversions.append (((2, 7, 1), conv,
2518                      '''ly:parser-define -> ly:parser-define!
2519 excentricity -> eccentricity
2520 Timing_engraver -> Timing_translator + Default_bar_line_engraver
2521 '''))
2522
2523
2524 def conv (str):
2525         str = re.sub('ly:(add|mul|mod|div)-moment', r'ly:moment-\1', str)
2526         return str
2527
2528 conversions.append (((2, 7, 2), conv,
2529                      '''ly:X-moment -> ly:moment-X'''))
2530
2531
2532 def conv (str):
2533         str = re.sub('keyAccidentalOrder', 'keyAlterationOrder', str)
2534         return str
2535
2536 conversions.append (((2, 7, 4), conv,
2537                      '''keyAccidentalOrder->keyAlterationOrder'''))
2538
2539
2540
2541 def conv (str):
2542         str = re.sub('Performer_group_performer', 'Performer_group', str)
2543         str = re.sub('Engraver_group_engraver', 'Engraver_group', str)
2544         str = re.sub (r"#'inside-slur\s*=\s*##t *",
2545                       r"#'avoid-slur = #'inside ", str)
2546         str = re.sub (r"#'inside-slur\s*=\s*##f *",
2547                       r"#'avoid-slur = #'around ", str)
2548         str = re.sub (r"#'inside-slur",
2549                       r"#'avoid-slur", str)
2550         return str
2551
2552 conversions.append (((2, 7, 6), conv,
2553                      '''Performer_group_performer -> Performer_group, Engraver_group_engraver -> Engraver_group
2554 inside-slur -> avoid-slur'''))
2555
2556
2557
2558 def conv (str):
2559         str = re.sub(r'\\applyoutput', r'\\applyOutput', str)
2560         str = re.sub(r'\\applycontext', r'\\applyContext', str)
2561         str = re.sub(r'\\applymusic',  r'\\applyMusic', str)
2562         str = re.sub(r'ly:grob-suicide', 'ly:grob-suicide!', str)
2563         return str
2564
2565 conversions.append (((2, 7, 10), conv,
2566                      '''\\applyxxx -> \\applyXxx'''))
2567
2568
2569
2570 def conv (str):
2571         str = re.sub(r'\"tabloid\"', '"11x17"', str)
2572         return str
2573
2574 conversions.append (((2, 7, 11), conv,
2575                      '''\"tabloid\" -> \"11x17\"'''))
2576
2577 def conv (str):
2578         str = re.sub(r'outputProperty' , 'overrideProperty', str)
2579         return str
2580
2581 conversions.append (((2, 7, 12), conv,
2582                      '''outputProperty -> overrideProperty'''))
2583
2584
2585 def conv (str):
2586         def subber (match):
2587                 newkey = {'spacing-procedure': 'springs-and-rods',
2588                           'after-line-breaking-callback' : 'after-line-breaking',
2589                           'before-line-breaking-callback' : 'before-line-breaking',
2590                           'print-function' : 'stencil'} [match.group(3)]
2591                 what = match.group (1)
2592                 grob = match.group (2)
2593
2594                 if what == 'revert':
2595                         return "revert %s #'callbacks %% %s\n" % (grob, newkey)
2596                 elif what == 'override':
2597                         return "override %s #'callbacks #'%s" % (grob, newkey)
2598                 else:
2599                         raise 'urg'
2600                         return ''
2601                 
2602         str = re.sub(r"(override|revert)\s*([a-zA-Z.]+)\s*#'(spacing-procedure|after-line-breaking-callback"
2603                     + r"|before-line-breaking-callback|print-function)",
2604                     subber, str)
2605
2606         if re.search ('bar-size-procedure', str):
2607                 error_file.write (NOT_SMART % "bar-size-procedure")
2608         if re.search ('space-function', str):
2609                 error_file.write (NOT_SMART % "space-function")
2610         if re.search ('verticalAlignmentChildCallback', str):
2611                 error_file.write ('verticalAlignmentChildCallback has been deprecated') 
2612         return str
2613
2614 conversions.append (((2, 7, 13), conv,
2615                      '''layout engine refactoring. [FIXME] '''))
2616
2617
2618
2619 def conv (str):
2620         str = re.sub (r"\\override +([A-Z.a-z]+) #'callbacks",
2621                       r"\\override \1", str)
2622         str = re.sub (r"\\revert ([A-Z.a-z]+) #'callbacks % ([a-zA-Z]+)",
2623                       r"\\revert \1 #'\2", str)
2624         str = re.sub (r"([XY]-extent)-callback", r'\1', str)
2625         str = re.sub (r"RemoveEmptyVerticalGroup", "VerticalAxisGroup", str)
2626         str = re.sub (r"\\set ([a-zA-Z]*\.?)minimumVerticalExtent",
2627                       r"\\override \1VerticalAxisGroup #'minimum-Y-extent",
2628                       str)
2629         str = re.sub (r"minimumVerticalExtent",
2630                       r"\\override VerticalAxisGroup #'minimum-Y-extent",
2631                       str)
2632         
2633         return str
2634
2635 conversions.append (((2, 7, 14), conv,
2636                      '''Remove callbacks property, deprecate XY-extent-callback. '''))
2637
2638
2639 def conv (str):
2640         if re.search ('[XY]-offset-callbacks', str):
2641                 error_file.write (NOT_SMART % "[XY]-offset-callbacks")
2642         if re.search ('position-callbacks', str):
2643                 error_file.write (NOT_SMART % "position-callbacks")
2644         return str
2645
2646 conversions.append (((2, 7, 15), conv,
2647                      '''Use grob closures iso. XY-offset-callbacks.'''))
2648
2649
2650 def conv (str):
2651         def sub_syms (m):
2652                 syms =  m.group (1).split ()
2653                 tags = ["\\tag #'%s" % s for s in syms]
2654                 return ' '.join (tags)
2655                 
2656         str = re.sub (r"\\tag #'\(([^)]+)\)",  sub_syms, str)
2657         return str
2658
2659 conversions.append (((2, 7, 22), conv,
2660                      """\tag #'(a b) -> \tag #'a \tag #'b""" ))
2661
2662 def conv (str):
2663         str = re.sub (r"#'number-visibility",
2664                       "#'number-visibility % number-visibility is deprecated. Tune the TupletNumber instead\n",
2665                       str)
2666         return str
2667
2668 conversions.append (((2, 7, 24), conv,
2669                      """deprecate number-visibility""")) 
2670
2671 def conv (str):
2672         str = re.sub (r"ly:spanner-get-bound", "ly:spanner-bound", str)
2673         return str
2674
2675 conversions.append (((2, 7, 28), conv,
2676                      """ly:spanner-get-bound -> ly:spanner-bound"""))
2677
2678 def conv (str):
2679         for a in ['beamed-lengths', 'beamed-minimum-free-lengths',
2680                   'beamed-extreme-minimum-free-lengths']:
2681                 str = re.sub (r"\\override\s+Stem\s+#'%s" % a,
2682                               r"\\override Stem #'details #'%s" % a,
2683                               str)
2684         return str
2685
2686 conversions.append (((2, 7, 29), conv,
2687                      """override Stem #'beamed-* -> #'details #'beamed-*"""))
2688
2689 def conv (str):
2690         str = re.sub (r'\epsfile *#"', r'\epsfile #X #10 #"', str)
2691         return str
2692
2693 conversions.append (((2, 7, 30), conv,
2694                      """\\epsfile"""))
2695
2696
2697 def conv (str):
2698         def sub_cxx_id (m):
2699                 str = m.group(1)
2700                 return 'ly:' + str.lower ().replace ('_','-')
2701                 
2702         str = re.sub (r'([A-Z][a-z_0-9]+::[a-z_0-9]+)',
2703                       sub_cxx_id, str)
2704         return str
2705
2706 conversions.append (((2, 7, 31), conv,
2707                      """Foo_bar::bla_bla -> ly:foo-bar::bla-bla"""))
2708
2709
2710 def conv (str):
2711         identifier_subs = [
2712                 ('inputencoding', 'input-encoding'),
2713                 ('printpagenumber', 'print-page-number'),
2714                 ('outputscale', 'output-scale'),
2715                 ('betweensystemspace', 'between-system-space'),
2716                 ('betweensystempadding', 'between-system-padding'),
2717                 ('pagetopspace', 'page-top-space'),
2718                 ('raggedright', 'ragged-right'),
2719                 ('raggedlast', 'ragged-last'),
2720                 ('raggedbottom', 'ragged-bottom'),
2721                 ('raggedlastbottom', 'ragged-last-bottom'),
2722                 ('aftertitlespace', 'after-title-space'),
2723                 ('beforetitlespace', 'before-title-space'),
2724                 ('betweentitlespace', 'between-title-space'),
2725                 ('topmargin', 'top-margin'),
2726                 ('bottommargin', 'bottom-margin'),
2727                 ('headsep', 'head-separation'),
2728                 ('footsep', 'foot-separation'),
2729                 ('rightmargin', 'right-margin'),
2730                 ('leftmargin', 'left-margin'),
2731                 ('printfirstpagenumber', 'print-first-page-number'),
2732                 ('firstpagenumber', 'first-page-number'),
2733                 ('hsize', 'paper-width'),
2734                 ('vsize', 'paper-height'),
2735                 ('horizontalshift', 'horizontal-shift'),
2736                 ('staffspace', 'staff-space'),
2737                 ('linethickness', 'line-thickness'),
2738                 ('ledgerlinethickness', 'ledger-line-thickness'),
2739                 ('blotdiameter', 'blot-diameter'),
2740                 ('staffheight', 'staff-height'),
2741                 ('linewidth', 'line-width'),
2742                 ('annotatespacing', 'annotate-spacing')
2743                 ]
2744         
2745         for (a,b)  in identifier_subs:
2746                 ### for C++:
2747                 ## str = re.sub ('"%s"' % a, '"%s"' b, str)
2748                 
2749                 str = re.sub (a, b, str)
2750         return str
2751
2752 conversions.append (((2, 7, 32), conv,
2753                      """foobar -> foo-bar for \paper, \layout"""))
2754
2755 def conv (str):
2756         str = re.sub ('debug-beam-quanting', 'debug-beam-scoring', str)
2757         return str
2758
2759 conversions.append (((2, 7, 32), conv,
2760                      """debug-beam-quanting -> debug-beam-scoring"""))
2761
2762
2763 def conv (str):
2764         str = re.sub ('def-music-function', 'define-music-function', str)
2765         str = re.sub ('def-markup-command', 'define-markup-command', str)
2766         return str
2767
2768 conversions.append (((2, 7, 36), conv,
2769                     """def-(music-function|markup-command) -> define-(music-function|markup-command)"""))