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