3 # convert-ly.py -- convertor for lilypond versions
5 # source file of the GNU LilyPond music typesetter
10 # use -f and -t for -s output
16 program_name = 'convert-ly'
17 version = '@TOPLEVEL_VERSION@'
27 # Did we ever have \mudela-version? I doubt it.
28 # lilypond_version_re_str = '\\\\version *\"(.*)\"'
29 lilypond_version_re_str = '\\\\(mudela-)?version *\"(.*)\"'
30 lilypond_version_re = re.compile (lilypond_version_re_str)
35 return '%s (GNU LilyPond) %s' %(program_name, version);
38 sys.stderr.write (program_id () + '\n')
42 r"""Usage: %s [OPTION]... [FILE]...
43 Try to convert to newer lilypond-versions. The version number of the
44 input is guessed by default from \version directive
47 -a, --assume-old apply all conversions to unversioned files
48 -h, --help print this help
49 -e, --edit in place edit
50 -f, --from=VERSION start from version. Overrides \version found in file.
51 -s, --show-rules print all rules.
52 -t, --to=VERSION target version
53 -n, --no-version don't add new version stamp.
54 --version print program version
56 Report bugs to bugs-gnu-music@gnu.org
65 sys.stdout.write (r"""%s
67 This is free software. It is covered by the GNU General Public
68 License, and you are welcome to change it and/or distribute copies of
69 it under certain conditions. invoke as `%s --warranty' for more
72 """ % (program_id() , program_name))
81 print 'can\'t open file: ' + f + '\n'
85 print 'gulped empty file: ' + f + '\n'
90 return tuple (map (string.atoi, string.split (s,'.')))
93 return string.join (map (lambda x: '%s' % x, list (t)), '.')
95 def version_cmp (t1, t2):
101 def guess_lilypond_version (filename):
102 s = gulp_file (filename)
103 m = lilypond_version_re.search (s)
109 class FatalConversionError:
114 def show_rules (file):
115 for x in conversions:
116 file.write ('%s: %s\n' % (tup_to_str (x[0]), x[2]))
118 ############################
122 if re.search ('\\\\multi', str):
123 sys.stderr.write ('\nNot smart enough to convert \\multi')
126 conversions.append (((0,1,9), conv, '\\header { key = concat + with + operator }'))
128 if 1: # need new a namespace
130 if re.search ('\\\\octave', str):
131 sys.stderr.write ('\nNot smart enough to convert \\octave')
132 # raise FatalConversionError()
136 conversions.append ((
137 ((0,1,19), conv, 'deprecated \\octave; can\'t convert automatically')))
140 if 1: # need new a namespace
142 str = re.sub ('\\\\textstyle([^;]+);',
143 '\\\\property Lyrics . textstyle = \\1', str)
144 # harmful to current .lys
145 # str = re.sub ('\\\\key([^;]+);', '\\\\accidentals \\1;', str)
149 conversions.append ((
150 ((0,1,20), conv, 'deprecated \\textstyle, new \key syntax')))
155 str = re.sub ('\\\\musical_pitch', '\\\\musicalpitch',str)
156 str = re.sub ('\\\\meter', '\\\\time',str)
160 conversions.append ((
161 ((0,1,21), conv, '\\musical_pitch -> \\musicalpitch, '+
162 '\\meter -> \\time')))
168 conversions.append ((
169 ((1,0,0), conv, '0.1.21 -> 1.0.0 ')))
174 str = re.sub ('\\\\accidentals', '\\\\keysignature',str)
175 str = re.sub ('specialaccidentals *= *1', 'keyoctaviation = 0',str)
176 str = re.sub ('specialaccidentals *= *0', 'keyoctaviation = 1',str)
180 conversions.append ((
181 ((1,0,1), conv, '\\accidentals -> \\keysignature, ' +
182 'specialaccidentals -> keyoctaviation')))
186 if re.search ('\\\\header', str):
187 sys.stderr.write ('\nNot smart enough to convert to new \\header format')
190 conversions.append (((1,0,2), conv, '\\header { key = concat + with + operator }'))
194 str = re.sub ('\\\\melodic([^a-zA-Z])', '\\\\notes\\1',str)
197 conversions.append (((1,0,3), conv, '\\melodic -> \\notes'))
201 str = re.sub ('default_paper *=', '',str)
202 str = re.sub ('default_midi *=', '',str)
205 conversions.append (((1,0,4), conv, 'default_{paper,midi}'))
209 str = re.sub ('ChoireStaff', 'ChoirStaff',str)
210 str = re.sub ('\\\\output', 'output = ',str)
214 conversions.append (((1,0,5), conv, 'ChoireStaff -> ChoirStaff'))
218 if re.search ('[a-zA-Z]+ = *\\translator',str):
219 sys.stderr.write ('\nNot smart enough to change \\translator syntax')
220 # raise FatalConversionError()
223 conversions.append (((1,0,6), conv, 'foo = \\translator {\\type .. } ->\\translator {\\type ..; foo; }'))
228 str = re.sub ('\\\\lyrics*', '\\\\lyrics',str)
232 conversions.append (((1,0,7), conv, '\\lyric -> \\lyrics'))
236 str = re.sub ('\\\\\\[/3+', '\\\\times 2/3 { ',str)
237 str = re.sub ('\\[/3+', '\\\\times 2/3 { [',str)
238 str = re.sub ('\\\\\\[([0-9/]+)', '\\\\times \\1 {',str)
239 str = re.sub ('\\[([0-9/]+)', '\\\\times \\1 { [',str)
240 str = re.sub ('\\\\\\]([0-9/]+)', '}', str)
241 str = re.sub ('\\\\\\]', '}',str)
242 str = re.sub ('\\]([0-9/]+)', '] }', str)
245 conversions.append (((1,0,10), conv, '[2/3 ]1/1 -> \\times 2/3 '))
250 conversions.append (((1,0,12), conv, 'Chord syntax stuff'))
257 str = re.sub ('<([^>~]+)~([^>]*)>','<\\1 \\2> ~', str)
261 conversions.append (((1,0,13), conv, '<a ~ b> c -> <a b> ~ c'))
265 str = re.sub ('<\\[','[<', str)
266 str = re.sub ('\\]>','>]', str)
270 conversions.append (((1,0,14), conv, '<[a b> <a b]>c -> [<a b> <a b>]'))
275 str = re.sub ('\\\\type([^\n]*engraver)','\\\\TYPE\\1', str)
276 str = re.sub ('\\\\type([^\n]*performer)','\\\\TYPE\\1', str)
277 str = re.sub ('\\\\type','\\\\context', str)
278 str = re.sub ('\\\\TYPE','\\\\type', str)
279 str = re.sub ('textstyle','textStyle', str)
283 conversions.append (((1,0,16), conv, '\\type -> \\context, textstyle -> textStyle'))
288 if re.search ('\\\\repeat',str):
289 sys.stderr.write ('\nNot smart enough to convert \\repeat')
290 # raise FatalConversionError()
293 conversions.append (((1,0,18), conv,
294 '\\repeat NUM Music Alternative -> \\repeat FOLDSTR Music Alternative'))
298 str = re.sub ('SkipBars','skipBars', str)
299 str = re.sub ('fontsize','fontSize', str)
300 str = re.sub ('midi_instrument','midiInstrument', str)
304 conversions.append (((1,0,19), conv,
305 'fontsize -> fontSize, midi_instrument -> midiInstrument, SkipBars -> skipBars'))
310 str = re.sub ('tieydirection','tieVerticalDirection', str)
311 str = re.sub ('slurydirection','slurVerticalDirection', str)
312 str = re.sub ('ydirection','verticalDirection', str)
316 conversions.append (((1,0,20), conv,
317 '{,tie,slur}ydirection -> {v,tieV,slurV}erticalDirection'))
322 str = re.sub ('hshift','horizontalNoteShift', str)
326 conversions.append (((1,0,21), conv,
327 'hshift -> horizontalNoteShift'))
332 str = re.sub ('\\\\grouping[^;]*;','', str)
336 conversions.append (((1,1,52), conv,
337 'deprecate \\grouping'))
342 str = re.sub ('\\\\wheel','\\\\coda', str)
346 conversions.append (((1,1,55), conv,
347 '\\wheel -> \\coda'))
351 str = re.sub ('keyoctaviation','keyOctaviation', str)
352 str = re.sub ('slurdash','slurDash', str)
356 conversions.append (((1,1,65), conv,
357 'slurdash -> slurDash, keyoctaviation -> keyOctaviation'))
361 str = re.sub ('\\\\repeat *\"?semi\"?','\\\\repeat "volta"', str)
365 conversions.append (((1,1,66), conv,
371 str = re.sub ('\"?beamAuto\"? *= *\"?0?\"?','noAutoBeaming = "1"', str)
375 conversions.append (((1,1,67), conv,
376 'beamAuto -> noAutoBeaming'))
380 str = re.sub ('automaticMelismas', 'automaticMelismata', str)
384 conversions.append (((1,2,0), conv,
385 'automaticMelismas -> automaticMelismata'))
389 str = re.sub ('dynamicDir\\b', 'dynamicDirection', str)
393 conversions.append (((1,2,1), conv,
394 'dynamicDir -> dynamicDirection'))
398 str = re.sub ('\\\\cadenza *0 *;', '\\\\cadenzaOff', str)
399 str = re.sub ('\\\\cadenza *1 *;', '\\\\cadenzaOn', str)
403 conversions.append (((1,3,4), conv,
404 '\\cadenza -> \cadenza{On|Off}'))
408 str = re.sub ('"?beamAuto([^"=]+)"? *= *"([0-9]+)/([0-9]+)" *;*',
409 'beamAuto\\1 = #(make-moment \\2 \\3)',
413 conversions.append (((1,3,5), conv, 'beamAuto moment properties'))
417 str = re.sub ('stemStyle',
422 conversions.append (((1,3,17), conv, 'stemStyle -> flagStyle'))
426 str = re.sub ('staffLineLeading',
431 conversions.append (((1,3,18), conv, 'staffLineLeading -> staffSpace'))
436 if re.search ('\\\\repetitions',str):
437 sys.stderr.write ('\nNot smart enough to convert \\repetitions')
438 # raise FatalConversionError()
441 conversions.append (((1,3,23), conv,
442 '\\\\repetitions feature dropped'))
447 str = re.sub ('textEmptyDimension *= *##t',
448 'textNonEmpty = ##f',
450 str = re.sub ('textEmptyDimension *= *##f',
451 'textNonEmpty = ##t',
455 conversions.append (((1,3,35), conv, 'textEmptyDimension -> textNonEmpty'))
459 str = re.sub ("([a-z]+)[ \t]*=[ \t]*\\\\musicalpitch *{([- 0-9]+)} *\n",
460 "(\\1 . (\\2))\n", str)
461 str = re.sub ("\\\\musicalpitch *{([0-9 -]+)}",
462 "\\\\musicalpitch #'(\\1)", str)
463 if re.search ('\\\\notenames',str):
464 sys.stderr.write ('\nNot smart enough to convert to new \\notenames format')
467 conversions.append (((1,3,38), conv, '\musicalpitch { a b c } -> #\'(a b c)'))
472 return '\\key %s;' % string.lower (match.group (1))
474 str = re.sub ("\\\\key ([^;]+);", replace, str)
477 conversions.append (((1,3,39), conv, '\\key A ; ->\\key a;'))
481 if re.search ('\\[:',str):
482 sys.stderr.write ('\nNot smart enough to convert to new tremolo format')
485 conversions.append (((1,3,41), conv,
486 '[:16 c4 d4 ] -> \\repeat "tremolo" 2 { c16 d16 }'))
490 str = re.sub ('Staff_margin_engraver' , 'Instrument_name_engraver', str)
493 conversions.append (((1,3,42), conv,
494 'Staff_margin_engraver deprecated, use Instrument_name_engraver'))
498 str = re.sub ('note[hH]eadStyle\\s*=\\s*"?(\\w+)"?' , "noteHeadStyle = #'\\1", str)
501 conversions.append (((1,3,49), conv,
502 'noteHeadStyle value: string -> symbol'))
506 if re.search ('\\\\keysignature', str):
507 sys.stderr.write ('\nNot smart enough to convert to new tremolo format')
511 conversions.append (((1,3,58), conv,
512 'noteHeadStyle value: string -> symbol'))
516 str = re.sub (r"""\\key *([a-z]+) *;""", r"""\\key \1 \major;""",str);
518 conversions.append (((1,3,59), conv,
519 '\key X ; -> \key X major; '))
523 str = re.sub (r'latexheaders *= *"\\\\input ',
527 conversions.append (((1,3,68), conv, 'latexheaders = "\\input global" -> latexheaders = "global"'))
532 # TODO: lots of other syntax change should be done here as well
535 str = re.sub ('basicCollisionProperties', 'NoteCollision', str)
536 str = re.sub ('basicVoltaSpannerProperties' , "VoltaBracket", str)
537 str = re.sub ('basicKeyProperties' , "KeySignature", str)
539 str = re.sub ('basicClefItemProperties' ,"Clef", str)
542 str = re.sub ('basicLocalKeyProperties' ,"Accidentals", str)
543 str = re.sub ('basicMarkProperties' ,"Accidentals", str)
544 str = re.sub ('basic([A-Za-z_]+)Properties', '\\1', str)
546 str = re.sub ('Repeat_engraver' ,'Volta_engraver', str)
549 conversions.append (((1,3,92), conv, 'basicXXXProperties -> XXX, Repeat_engraver -> Volta_engraver'))
553 # Ugh, but meaning of \stemup changed too
554 # maybe we should do \stemup -> \stemUp\slurUp\tieUp ?
555 str = re.sub ('\\\\stemup', '\\\\stemUp', str)
556 str = re.sub ('\\\\stemdown', '\\\\stemDown', str)
557 str = re.sub ('\\\\stemboth', '\\\\stemBoth', str)
559 str = re.sub ('\\\\slurup', '\\\\slurUp', str)
560 str = re.sub ('\\\\slurboth', '\\\\slurBoth', str)
561 str = re.sub ('\\\\slurdown', '\\\\slurDown', str)
562 str = re.sub ('\\\\slurdotted', '\\\\slurDotted', str)
563 str = re.sub ('\\\\slurnormal', '\\\\slurNoDots', str)
565 str = re.sub ('\\\\shiftoff', '\\\\shiftOff', str)
566 str = re.sub ('\\\\shifton', '\\\\shiftOn', str)
567 str = re.sub ('\\\\shiftonn', '\\\\shiftOnn', str)
568 str = re.sub ('\\\\shiftonnn', '\\\\shiftOnnn', str)
570 str = re.sub ('\\\\onevoice', '\\\\oneVoice', str)
571 str = re.sub ('\\\\voiceone', '\\\\voiceOne', str)
572 str = re.sub ('\\\\voicetwo', '\\\\voiceTwo', str)
573 str = re.sub ('\\\\voicethree', '\\\\voiceThree', str)
574 str = re.sub ('\\\\voicefour', '\\\\voiceFour', str)
576 # I don't know exactly when these happened...
577 # ugh, we loose context setting here...
578 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\stemUp\\\\slurUp\\\\tieUp', str)
579 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\stemDown\\\\slurDown\\\\tieDown', str)
580 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\stemBoth\\\\slurBoth\\\\tieBoth', str)
582 str = re.sub ('verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #1', str)
583 str = re.sub ('verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #-1', str)
584 str = re.sub ('verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #0', str)
586 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\\\1Up', str)
587 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\\\1Down', str)
588 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\\\1Both', str)
590 # (lacks capitalisation slur -> Slur)
591 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\1 \\\\override #\'direction = #1', str)
592 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\1 \\override #\'direction = #-1', str)
593 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\1 \\\\override #\'direction = #0', str)
596 str = re.sub ('\\\\property *[^ .]*[.]?dynamicDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\dynamicUp', str)
597 str = re.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\dynamicDown', str)
598 str = re.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?(0|(\\\\center))"?', '\\\\dynamicBoth', str)
600 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?(0|(""))"?', '\\\\\\1NoDots', str)
601 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?([1-9]+)"?', '\\\\\\1Dotted', str)
603 str = re.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?(0|(""))"?', '\\\\autoBeamOn', str)
604 str = re.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?([1-9]+)"?', '\\\\autoBeamOff', str)
610 conversions.append (((1,3,93), conv,
611 'property definiton case (eg. onevoice -> oneVoice)'))
616 str = re.sub ('ChordNames*', 'ChordNames', str)
617 if re.search ('\\\\textscript "[^"]* *"[^"]*"', str):
618 sys.stderr.write ('\nNot smart enough to convert to new \\textscript markup text')
620 str = re.sub ('\\textscript +("[^"]*")', '\\textscript #\\1', str)
624 conversions.append (((1,3,97), conv, 'ChordName -> ChordNames'))
627 # TODO: add lots of these
631 str = re.sub ('\\\\property *"?Voice"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Voice.TextScript \\\\set #\'font-style = #\'\\1', str)
632 str = re.sub ('\\\\property *"?Lyrics"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Lyrics.LyricText \\\\set #\'font-style = #\'\\1', str)
634 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?timeSignatureStyle"? *= *"([^"]*)"', '\\\\property \\1.TimeSignature \\\\override #\'style = #\'\\2', str)
636 str = re.sub ('"?timeSignatureStyle"? *= *#?""', 'TimeSignature \\\\override #\'style = ##f', str)
638 str = re.sub ('"?timeSignatureStyle"? *= *#?"([^"]*)"', 'TimeSignature \\\\override #\'style = #\'\\1', str)
640 str = re.sub ('#\'style *= #*"([^"])"', '#\'style = #\'\\1', str)
642 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?horizontalNoteShift"? *= *"?#?([-0-9]+)"?', '\\\\property \\1.NoteColumn \\\\override #\'horizontal-shift = #\\2', str)
645 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *""', '\\\\property \\1.Stem \\\\override #\'flag-style = ##f', str)
647 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *"([^"]*)"', '\\\\property \\1.Stem \\\\override #\'flag-style = #\'\\2', str)
650 conversions.append (((1,3,98), conv, 'CONTEXT.textStyle -> GROB.#font-style '))
654 str = re.sub ('"?beamAutoEnd_([0-9]*)"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end 1 \\1 * *) = \\2', str)
655 str = re.sub ('"?beamAutoBegin_([0-9]*)"? *= *(#\\([^)]*\))', 'autoBeamSettings \\push #\'(begin 1 \\1 * *) = \\2', str)
656 str = re.sub ('"?beamAutoEnd"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end * * * *) = \\1', str)
657 str = re.sub ('"?beamAutoBegin"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(begin * * * *) = \\1', str)
662 conversions.append (((1,3,102), conv, 'beamAutoEnd -> autoBeamSettings \\push (end * * * *)'))
667 str = re.sub ('\\\\push', '\\\\override', str)
668 str = re.sub ('\\\\pop', '\\\\revert', str)
672 conversions.append (((1,3,111), conv, '\\push -> \\override, \\pop -> \\revert'))
676 str = re.sub ('LyricVoice', 'LyricsVoice', str)
678 str = re.sub ('Chord[Nn]ames*.Chord[Nn]ames*', 'ChordNames.ChordName', str)
679 str = re.sub ('Chord[Nn]ames([ \t\n]+\\\\override)', 'ChordName\\1', str)
682 conversions.append (((1,3,113), conv, 'LyricVoice -> LyricsVoice'))
684 def regularize_id (str):
691 elif x in string.digits:
692 x = chr(ord (x) - ord ('0') +ord ('A'))
693 elif x not in string.letters:
695 elif x in string.lowercase and lastx == '_':
704 def regularize_dollar_reference (match):
705 return regularize_id (match.group (1))
706 def regularize_assignment (match):
707 return '\n' + regularize_id (match.group (1)) + ' = '
708 str = re.sub ('\$([^\t\n ]+)', regularize_dollar_reference, str)
709 str = re.sub ('\n([^ \t\n]+)[ \t]*= *', regularize_assignment, str)
712 conversions.append (((1,3,117), conv, 'identifier names: $!foo_bar_123 -> xfooBarABC'))
717 def regularize_paper (match):
718 return regularize_id (match.group (1))
720 str = re.sub ('(paper_[a-z]+)', regularize_paper, str)
721 str = re.sub ('sustainup', 'sustainUp', str)
722 str = re.sub ('nobreak', 'noBreak', str)
723 str = re.sub ('sustaindown', 'sustainDown', str)
724 str = re.sub ('sostenutoup', 'sostenutoUp', str)
725 str = re.sub ('sostenutodown', 'sostenutoDown', str)
726 str = re.sub ('unachorda', 'unaChorda', str)
727 str = re.sub ('trechorde', 'treChorde', str)
731 conversions.append (((1,3,120), conv, 'paper_xxx -> paperXxxx, pedalup -> pedalUp.'))
735 str = re.sub ('drarnChords', 'chordChanges', str)
736 str = re.sub ('\\musicalpitch', '\\pitch', str)
739 conversions.append (((1,3,122), conv, 'drarnChords -> chordChanges, \\musicalpitch -> \\pitch'))
743 str = re.sub ('ly-([sg])et-elt-property', 'ly-\\1et-grob-property', str)
746 conversions.append (((1,3,136), conv, 'ly-X-elt-property -> ly-X-grob-property'))
750 str = re.sub ('point-and-click +#t', 'point-and-click line-column-location', str)
753 conversions.append (((1,3,138), conv, 'point-and-click argument changed to procedure.'))
757 str = re.sub ('followThread', 'followVoice', str)
758 str = re.sub ('Thread.FollowThread', 'Voice.VoiceFollower', str)
759 str = re.sub ('FollowThread', 'VoiceFollower', str)
762 conversions.append (((1,3,138), conv, 'followThread -> followVoice.'))
766 str = re.sub ('font-point-size', 'font-design-size', str)
769 conversions.append (((1,3,139), conv, 'font-point-size -> font-design-size.'))
773 str = re.sub ('([a-zA-Z]*)NoDots', '\\1Solid', str)
776 conversions.append (((1,3,141), conv, 'xNoDots -> xSolid'))
780 str = re.sub ('([Cc])hord([ea])', '\\1ord\\2', str)
783 conversions.append (((1,3,144), conv, 'Chorda -> Corda'))
788 str = re.sub ('([A-Za-z]+)MinimumVerticalExtent', 'MinimumV@rticalExtent', str)
789 str = re.sub ('([A-Za-z]+)ExtraVerticalExtent', 'ExtraV@rticalExtent', str)
790 str = re.sub ('([A-Za-z]+)VerticalExtent', 'VerticalExtent', str)
791 str = re.sub ('ExtraV@rticalExtent', 'ExtraVerticalExtent', str)
792 str = re.sub ('MinimumV@rticalExtent', 'MinimumVerticalExtent', str)
795 conversions.append (((1,3,145), conv,
796 'ContextNameXxxxVerticalExtent -> XxxxVerticalExtent'))
800 str = re.sub ('\\\\key[ \t]*;', '\\key \\default;', str)
801 str = re.sub ('\\\\mark[ \t]*;', '\\mark \\default;', str)
803 # Make sure groups of more than one ; have space before
804 # them, so that non of them gets removed by next rule
805 str = re.sub ("([^ \n\t;]);(;+)", "\\1 ;\\2", str)
807 # Only remove ; that are not after spaces, # or ;
808 # Otherwise we interfere with Scheme comments,
809 # which is badbadbad.
810 str = re.sub ("([^ \t;#]);", "\\1", str)
813 conversions.append (((1,3,146), conv, 'semicolons removed'))
817 str = re.sub ('default-neutral-direction', 'neutral-direction',str)
819 conversions.append (((1,3,147), conv, 'default-neutral-direction -> neutral-direction'))
823 str = re.sub ('\(align', '(axis', str)
824 str = re.sub ('\(rows', '(columns', str)
826 conversions.append (((1,3,148), conv, '"(align" -> "(axis", "(rows" -> "(columns"'))
831 str = re.sub ('SystemStartDelimiter', 'systemStartDelimiter', str)
833 conversions.append (((1,5,33), conv, 'SystemStartDelimiter -> systemStartDelimiter'))
837 str = re.sub ('arithmetic-multiplier', 'spacing-increment', str)
838 str = re.sub ('arithmetic-basicspace', 'shortest-duration-space', str)
841 conversions.append (((1,5,38), conv, 'SystemStartDelimiter -> systemStartDelimiter'))
845 str = re.sub ('noAutoBeaming *= *##f', 'autoBeaming = ##t', str)
846 str = re.sub ('noAutoBeaming *= *##t', 'autoBeaming = ##f', str)
849 conversions.append (((1,5,49), conv, 'noAutoBeaming -> autoBeaming'))
853 str = re.sub ('tuplet-bracket-visibility', 'bracket-visibility', str)
854 str = re.sub ('tuplet-number-visibility', 'number-visibility', str)
857 conversions.append (((1,5,52), conv, 'tuplet-X-visibility -> X-visibility'))
861 str = re.sub ('Pitch::transpose', 'ly-transpose-pitch', str)
865 conversions.append (((1,5,56), conv, 'Pitch::transpose -> ly-transpose-pitch'))
869 str = re.sub ('textNonEmpty *= *##t', "TextScript \\set #'no-spacing-rods = ##f", str)
870 str = re.sub ('textNonEmpty *= *##f', "TextScript \\set #'no-spacing-rods = ##t", str)
873 conversions.append (((1,5,58), conv, 'deprecate textNonEmpty'))
878 str = re.sub ('MinimumVerticalExtent', 'MinimumV@rticalExtent', str)
879 str = re.sub ('ExtraVerticalExtent', 'ExtraV@rticalExtent', str)
880 str = re.sub ('VerticalExtent', 'verticalExtent', str)
881 str = re.sub ('ExtraV@rticalExtent', 'extraVerticalExtent', str)
882 str = re.sub ('MinimumV@rticalExtent', 'minimumVerticalExtent', str)
885 conversions.append (((1,5,59), conv,
886 'XxxxVerticalExtent -> xxxVerticalExtent'))
890 str = re.sub ('visibility-lambda', 'break-visibility', str)
893 conversions.append (((1,5,62), conv,
894 'visibility-lambda -> break-visibility'))
898 str = re.sub ('ly-set-grob-property', 'ly-set-grob-property!', str)
899 str = re.sub ('ly-set-mus-property', 'ly-set-mus-property!', str)
902 conversions.append (((1,3,138), conv, 'ly-set-X-property -> ly-set-X-property!'))
905 ################################
907 ################################
909 def get_conversions (from_version, to_version):
910 def version_b (v, f = from_version, t = to_version):
911 return version_cmp (v[0], f) > 0 and version_cmp (v[0], t) <= 0
912 return filter (version_b, conversions)
915 def latest_version ():
916 return conversions[-1][0]
918 def do_conversion (infile, from_version, outfile, to_version):
919 conv_list = get_conversions (from_version, to_version)
921 sys.stderr.write ('Applying conversions: ')
926 sys.stderr.write (tup_to_str (x[0]) + ', ')
928 last_conversion = x[0]
930 except FatalConversionError:
931 sys.stderr.write ('Error while converting; I won\'t convert any further')
934 sys.stderr.write ('\n')
935 new_ver = '\\version \"%s\"' % tup_to_str (last_conversion)
937 if re.search (lilypond_version_re_str, str):
938 str = re.sub (lilypond_version_re_str,'\\'+new_ver , str)
940 str = new_ver + '\n' + str
944 return last_conversion
946 class UnknownVersion:
949 def do_one_file (infile_name):
950 sys.stderr.write ('Processing `%s\' ... '% infile_name)
953 outfile_name = infile_name + '.NEW'
954 elif __main__.outfile_name:
955 outfile_name = __main__.outfile_name
957 if __main__.from_version:
958 from_version = __main__.from_version
960 guess = guess_lilypond_version (infile_name)
962 raise UnknownVersion()
963 from_version = str_to_tuple (guess)
965 if __main__.to_version:
966 to_version = __main__.to_version
968 to_version = latest_version ()
972 infile = open (infile_name,'r')
977 outfile = open (outfile_name, 'w')
981 touched = do_conversion (infile, from_version, outfile, to_version)
989 if __main__.edit and touched:
991 os.remove(infile_name + '~')
994 os.rename (infile_name, infile_name + '~')
995 os.rename (infile_name + '.NEW', infile_name)
997 sys.stderr.write ('\n')
1006 (options, files) = getopt.getopt (
1007 sys.argv[1:], 'ao:f:t:senh', ['no-version', 'assume-old', 'version', 'output', 'show-rules', 'help', 'edit', 'from=', 'to='])
1012 if o== '--help' or o == '-h':
1015 if o == '--version' or o == '-v':
1018 elif o== '--from' or o=='-f':
1019 from_version = str_to_tuple (a)
1020 elif o== '--to' or o=='-t':
1021 to_version = str_to_tuple (a)
1022 elif o== '--edit' or o == '-e':
1024 elif o== '--show-rules' or o == '-s':
1025 show_rules (sys.stdout)
1027 elif o == '--output' or o == '-o':
1029 elif o == '--assume-old' or o == '-a':
1031 elif o == '--no-version' or o == '-n':
1041 if not os.path.isfile (f):
1045 except UnknownVersion:
1046 sys.stderr.write ('\n')
1047 sys.stderr.write ("%s: can't determine version for `%s'" % (program_name, f))
1048 sys.stderr.write ('\n')
1051 from_version = (0,0,0)
1055 sys.stderr.write ("%s: skipping: `%s' " % (program_name, f))
1057 sys.stderr.write ('\n')