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