X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fconvert-ly.py;h=d0ded91a8923d9a3d0f21466186e3eadd6faba1a;hb=4300e287a18cbc4569c79f8e8445609dc7d4546a;hp=971d516130c60ee9f9ccb2d91bce6ee23064da4a;hpb=c5536befdccd6feaff702bcb4a606d80416af0d7;p=lilypond.git diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index 971d516130..d0ded91a89 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -4,17 +4,9 @@ # # source file of the GNU LilyPond music typesetter # -# (c) 1998--2004 Han-Wen Nienhuys +# (c) 1998--2005 Han-Wen Nienhuys # Jan Nieuwenhuizen - -# TODO -# use -f and -t for -s output - -# NEWS -# 0.2 -# - rewrite in python - import os import sys import __main__ @@ -23,10 +15,24 @@ import string import re import time -program_name = sys.argv[0] +localedir = '@localedir@' +try: + import gettext + gettext.bindtextdomain ('lilypond', localedir) + gettext.textdomain ('lilypond') + _ = gettext.gettext +except: + def _ (s): + return s +underscore = _ +program_name = os.path.basename (sys.argv[0]) version = '@TOPLEVEL_VERSION@' +FROM_TO = _ ( "%s has been replaced by %s") +NOT_SMART = _ ("Not smart enough to convert %s") +UPDATE_MANUALLY = _ ("Please refer to the manual for details, and update manually.") + # Did we ever have \mudela-version? I doubt it. # lilypond_version_re_str = '\\\\version *\"(.*)\"' lilypond_version_re_str = '\\\\(mudela-)?version *\"([^"]+)\"' @@ -35,73 +41,58 @@ add_version = 1 def program_id (): - return '%s (GNU LilyPond) %s' %(program_name, version); + return '%s (GNU LilyPond) %s' % (program_name, version) def identify (): sys.stderr.write (program_id () + '\n') def usage (): - sys.stdout.write ( - r"""Usage: %s [OPTIONS]... [FILE]... -Try to convert to newer lilypond-versions. The version number of the -input is guessed by default from \version directive. - -Options: - -h, --help print this help + sys.stdout.write (_ ("Usage: %s [OPTION]... [FILE]..." \ + % program_name)) + sys.stdout.write ('\n\n') + sys.stdout.write (_ ("""\ +Update LilyPond input to newer version. By default, update from the +version taken from the \\version command, to the current LilyPond version.""")) + sys.stdout.write ('\n\n') + sys.stdout.write (_ ("Options:")) + sys.stdout.write ('\n') + sys.stdout.write (_ ("""\ -e, --edit edit in place - -f, --from=VERSION start from version; overrides \version found in file - -s, --show-rules print all rules - -t, --to=VERSION show target version - -n, --no-version don't add new version stamp - --version print program version - -Report bugs to bugs-gnu-music@gnu.org. - -""" % program_name) - - + -f, --from=VERSION start from version [default: \\version found in file] + -h, --help print this help + -n, --no-version do not add \\version command if missing + -s, --show-rules print rules [default: --from=0, --to=@TOPLEVEL_VERSION@] + -t, --to=VERSION convert to version [default: @TOPLEVEL_VERSION@] + -v, --version print program version""")) + sys.stdout.write ('\n\n') + sys.stdout.write (_ ("Report bugs to %s.") % "bug-lilypond@gnu.org") + sys.stdout.write ('\n') sys.exit (0) def print_version (): - - sys.stdout.write (r"""%s - -This is free software. It is covered by the GNU General Public -License, and you are welcome to change it and/or distribute copies of -it under certain conditions. invoke as `%s --warranty' for more + sys.stdout.write (program_id ()) + sys.stdout.write ('\n') + sys.stdout.write (_ ("""\ +This program is free software. It is covered by the GNU General Public +License and you are welcome to change it and/or distribute copies of it +under certain conditions. Invoke as `%s --warranty' for more information. - -""" % (program_id() , program_name)) - -def gulp_file(f): - try: - i = open(f) - i.seek (0, 2) - n = i.tell () - i.seek (0,0) - except: - print 'can\'t open file: ' + f + '\n' - return '' - s = i.read (n) - if len (s) <= 0: - print 'gulped empty file: ' + f + '\n' - i.close () - return s +""") % "lilypond") def str_to_tuple (s): - return tuple (map (string.atoi, string.split (s,'.'))) + return tuple (map (string.atoi, string.split (s, '.'))) def tup_to_str (t): return string.join (map (lambda x: '%s' % x, list (t)), '.') def version_cmp (t1, t2): - for x in [0,1,2]: + for x in [0, 1, 2]: if t1[x] - t2[x]: return t1[x] - t2[x] return 0 def guess_lilypond_version (filename): - s = gulp_file (filename) + s = open (filename).read () m = lilypond_version_re.search (s) if m: return m.group (2) @@ -115,37 +106,44 @@ conversions = [] def show_rules (file): for x in conversions: - file.write ('%s: %s\n' % (tup_to_str (x[0]), x[2])) + if (not from_version or x[0] > from_version) \ + and (not to_version or x[0] <= to_version): + file.write ('%s: %s\n' % (tup_to_str (x[0]), x[2])) ############################ - + if 1: def conv(str): if re.search ('\\\\multi', str): - sys.stderr.write ('\nNot smart enough to convert \\multi') + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "\\multi") return str - + conversions.append (((0,1,9), conv, '\\header { key = concat + with + operator }')) -if 1: # need new a namespace +if 1: def conv (str): if re.search ('\\\\octave', str): - sys.stderr.write ('\nNot smart enough to convert \\octave') - # raise FatalConversionError() - + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "\\octave") + sys.stderr.write ('\n') + sys.stderr.write (UPDATE_MANUALLY) + sys.stderr.write ('\n') + # raise FatalConversionError () + return str conversions.append (( - ((0,1,19), conv, 'deprecated \\octave; can\'t convert automatically'))) + ((0,1,19), conv, 'deprecated \\octave; cannot convert automatically'))) -if 1: # need new a namespace +if 1: def conv (str): str = re.sub ('\\\\textstyle([^;]+);', '\\\\property Lyrics . textstyle = \\1', str) # harmful to current .lys # str = re.sub ('\\\\key([^;]+);', '\\\\accidentals \\1;', str) - + return str conversions.append (( @@ -156,7 +154,7 @@ if 1: def conv (str): str = re.sub ('\\\\musical_pitch', '\\\\musicalpitch',str) str = re.sub ('\\\\meter', '\\\\time',str) - + return str conversions.append (( @@ -176,7 +174,7 @@ if 1: str = re.sub ('\\\\accidentals', '\\\\keysignature',str) str = re.sub ('specialaccidentals *= *1', 'keyoctaviation = 0',str) str = re.sub ('specialaccidentals *= *0', 'keyoctaviation = 1',str) - + return str conversions.append (( @@ -186,16 +184,17 @@ if 1: if 1: def conv(str): if re.search ('\\\\header', str): - sys.stderr.write ('\nNot smart enough to convert to new \\header format') + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "new \\header format") return str - + conversions.append (((1,0,2), conv, '\\header { key = concat + with + operator }')) if 1: def conv(str): str = re.sub ('\\\\melodic([^a-zA-Z])', '\\\\notes\\1',str) return str - + conversions.append (((1,0,3), conv, '\\melodic -> \\notes')) if 1: @@ -203,34 +202,35 @@ if 1: str = re.sub ('default_paper *=', '',str) str = re.sub ('default_midi *=', '',str) return str - + conversions.append (((1,0,4), conv, 'default_{paper,midi}')) if 1: def conv(str): str = re.sub ('ChoireStaff', 'ChoirStaff',str) str = re.sub ('\\\\output', 'output = ',str) - + return str - + conversions.append (((1,0,5), conv, 'ChoireStaff -> ChoirStaff')) if 1: def conv(str): if re.search ('[a-zA-Z]+ = *\\translator',str): - sys.stderr.write ('\nNot smart enough to change \\translator syntax') - # raise FatalConversionError() + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "\\translator syntax") + # raise FatalConversionError () return str - + conversions.append (((1,0,6), conv, 'foo = \\translator {\\type .. } ->\\translator {\\type ..; foo; }')) if 1: def conv(str): str = re.sub ('\\\\lyrics*', '\\\\lyrics',str) - + return str - + conversions.append (((1,0,7), conv, '\\lyric -> \\lyrics')) if 1: @@ -243,7 +243,7 @@ if 1: str = re.sub ('\\\\\\]', '}',str) str = re.sub ('\\]([0-9/]+)', '] }', str) return str - + conversions.append (((1,0,10), conv, '[2/3 ]1/1 -> \\times 2/3 ')) if 1: @@ -254,21 +254,21 @@ if 1: if 1: def conv(str): - - + + str = re.sub ('<([^>~]+)~([^>]*)>','<\\1 \\2> ~', str) - + return str - + conversions.append (((1,0,13), conv, ' c -> ~ c')) if 1: def conv(str): str = re.sub ('<\\[','[<', str) str = re.sub ('\\]>','>]', str) - + return str - + conversions.append (((1,0,14), conv, '<[a b> c -> [ ]')) @@ -279,19 +279,20 @@ if 1: str = re.sub ('\\\\type','\\\\context', str) str = re.sub ('\\\\TYPE','\\\\type', str) str = re.sub ('textstyle','textStyle', str) - + return str - + conversions.append (((1,0,16), conv, '\\type -> \\context, textstyle -> textStyle')) if 1: def conv(str): if re.search ('\\\\repeat',str): - sys.stderr.write ('\nNot smart enough to convert \\repeat') - # raise FatalConversionError() + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "\\repeat") + # raise FatalConversionError () return str - + conversions.append (((1,0,18), conv, '\\repeat NUM Music Alternative -> \\repeat FOLDSTR Music Alternative')) @@ -299,8 +300,8 @@ if 1: def conv(str): str = re.sub ('SkipBars','skipBars', str) str = re.sub ('fontsize','fontSize', str) - str = re.sub ('midi_instrument','midiInstrument', str) - + str = re.sub ('midi_instrument','midiInstrument', str) + return str conversions.append (((1,0,19), conv, @@ -311,8 +312,8 @@ if 1: def conv(str): str = re.sub ('tieydirection','tieVerticalDirection', str) str = re.sub ('slurydirection','slurVerticalDirection', str) - str = re.sub ('ydirection','verticalDirection', str) - + str = re.sub ('ydirection','verticalDirection', str) + return str conversions.append (((1,0,20), conv, @@ -322,7 +323,7 @@ if 1: if 1: def conv(str): str = re.sub ('hshift','horizontalNoteShift', str) - + return str conversions.append (((1,0,21), conv, @@ -332,7 +333,7 @@ if 1: if 1: def conv(str): str = re.sub ('\\\\grouping[^;]*;','', str) - + return str conversions.append (((1,1,52), conv, @@ -342,7 +343,7 @@ if 1: if 1: def conv(str): str = re.sub ('\\\\wheel','\\\\coda', str) - + return str conversions.append (((1,1,55), conv, @@ -352,7 +353,7 @@ if 1: def conv(str): str = re.sub ('keyoctaviation','keyOctaviation', str) str = re.sub ('slurdash','slurDash', str) - + return str conversions.append (((1,1,65), conv, @@ -361,7 +362,7 @@ if 1: if 1: def conv(str): str = re.sub ('\\\\repeat *\"?semi\"?','\\\\repeat "volta"', str) - + return str conversions.append (((1,1,66), conv, @@ -371,7 +372,7 @@ if 1: if 1: def conv(str): str = re.sub ('\"?beamAuto\"? *= *\"?0?\"?','noAutoBeaming = "1"', str) - + return str conversions.append (((1,1,67), conv, @@ -380,7 +381,7 @@ if 1: if 1: def conv(str): str = re.sub ('automaticMelismas', 'automaticMelismata', str) - + return str conversions.append (((1,2,0), conv, @@ -389,7 +390,7 @@ if 1: if 1: def conv(str): str = re.sub ('dynamicDir\\b', 'dynamicDirection', str) - + return str conversions.append (((1,2,1), conv, @@ -398,8 +399,8 @@ if 1: if 1: def conv(str): str = re.sub ('\\\\cadenza *0 *;', '\\\\cadenzaOff', str) - str = re.sub ('\\\\cadenza *1 *;', '\\\\cadenzaOn', str) - + str = re.sub ('\\\\cadenza *1 *;', '\\\\cadenzaOn', str) + return str conversions.append (((1,3,4), conv, @@ -436,10 +437,11 @@ if 1: if 1: def conv(str): if re.search ('\\\\repetitions',str): - sys.stderr.write ('\nNot smart enough to convert \\repetitions') + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "\\repetitions") # raise FatalConversionError() return str - + conversions.append (((1,3,23), conv, '\\\\repetitions feature dropped')) @@ -463,7 +465,8 @@ if 1: str = re.sub ("\\\\musicalpitch *{([0-9 -]+)}", "\\\\musicalpitch #'(\\1)", str) if re.search ('\\\\notenames',str): - sys.stderr.write ('\nNot smart enough to convert to new \\notenames format') + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "new \\notenames format") return str conversions.append (((1,3,38), conv, '\musicalpitch { a b c } -> #\'(a b c)')) @@ -472,16 +475,17 @@ if 1: def conv (str): def replace (match): return '\\key %s;' % string.lower (match.group (1)) - + str = re.sub ("\\\\key ([^;]+);", replace, str) return str - + conversions.append (((1,3,39), conv, '\\key A ; ->\\key a;')) if 1: def conv (str): if re.search ('\\[:',str): - sys.stderr.write ('\nNot smart enough to convert to new tremolo format') + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "new tremolo format") return str conversions.append (((1,3,41), conv, @@ -506,7 +510,8 @@ if 1: if 1: def conv (str): if re.search ('\\\\keysignature', str): - sys.stderr.write ('\nNot smart enough to convert to new tremolo format') + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "new tremolo format") return str @@ -547,7 +552,7 @@ if 1: str = re.sub ('Repeat_engraver' ,'Volta_engraver', str) return str - + conversions.append (((1,3,92), conv, 'basicXXXProperties -> XXX, Repeat_engraver -> Volta_engraver')) if 1: @@ -557,13 +562,13 @@ if 1: str = re.sub ('\\\\stemup', '\\\\stemUp', str) str = re.sub ('\\\\stemdown', '\\\\stemDown', str) str = re.sub ('\\\\stemboth', '\\\\stemBoth', str) - + str = re.sub ('\\\\slurup', '\\\\slurUp', str) str = re.sub ('\\\\slurboth', '\\\\slurBoth', str) str = re.sub ('\\\\slurdown', '\\\\slurDown', str) str = re.sub ('\\\\slurdotted', '\\\\slurDotted', str) - str = re.sub ('\\\\slurnormal', '\\\\slurNoDots', str) - + str = re.sub ('\\\\slurnormal', '\\\\slurNoDots', str) + str = re.sub ('\\\\shiftoff', '\\\\shiftOff', str) str = re.sub ('\\\\shifton', '\\\\shiftOn', str) str = re.sub ('\\\\shiftonn', '\\\\shiftOnn', str) @@ -584,7 +589,7 @@ if 1: str = re.sub ('verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #1', str) str = re.sub ('verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #-1', str) str = re.sub ('verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #0', str) - + str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\\\1Up', str) str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\\\1Down', str) str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\\\1Both', str) @@ -608,7 +613,7 @@ if 1: return str - + conversions.append (((1,3,93), conv, 'property definiton case (eg. onevoice -> oneVoice)')) @@ -617,17 +622,18 @@ if 1: def conv (str): str = re.sub ('ChordNames*', 'ChordNames', str) if re.search ('\\\\textscript "[^"]* *"[^"]*"', str): - sys.stderr.write ('\nNot smart enough to convert to new \\textscript markup text') + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "new \\textscript markup text") str = re.sub ('\\textscript +("[^"]*")', '\\textscript #\\1', str) return str - + conversions.append (((1,3,97), conv, 'ChordName -> ChordNames')) # TODO: add lots of these - + if 1: def conv (str): str = re.sub ('\\\\property *"?Voice"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Voice.TextScript \\\\set #\'font-style = #\'\\1', str) @@ -636,19 +642,19 @@ if 1: str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?timeSignatureStyle"? *= *"([^"]*)"', '\\\\property \\1.TimeSignature \\\\override #\'style = #\'\\2', str) str = re.sub ('"?timeSignatureStyle"? *= *#?""', 'TimeSignature \\\\override #\'style = ##f', str) - + str = re.sub ('"?timeSignatureStyle"? *= *#?"([^"]*)"', 'TimeSignature \\\\override #\'style = #\'\\1', str) - + str = re.sub ('#\'style *= #*"([^"])"', '#\'style = #\'\\1', str) - + str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?horizontalNoteShift"? *= *"?#?([-0-9]+)"?', '\\\\property \\1.NoteColumn \\\\override #\'horizontal-shift = #\\2', str) # ugh str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *""', '\\\\property \\1.Stem \\\\override #\'flag-style = ##f', str) - + str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *"([^"]*)"', '\\\\property \\1.Stem \\\\override #\'flag-style = #\'\\2', str) return str - + conversions.append (((1,3,98), conv, 'CONTEXT.textStyle -> GROB.#font-style ')) if 1: @@ -660,7 +666,7 @@ if 1: return str - + conversions.append (((1,3,102), conv, 'beamAutoEnd -> autoBeamSettings \\push (end * * * *)')) @@ -670,7 +676,7 @@ if 1: str = re.sub ('\\\\pop', '\\\\revert', str) return str - + conversions.append (((1,3,111), conv, '\\push -> \\override, \\pop -> \\revert')) if 1: @@ -680,7 +686,7 @@ if 1: str = re.sub ('Chord[Nn]ames*.Chord[Nn]ames*', 'ChordNames.ChordName', str) str = re.sub ('Chord[Nn]ames([ \t\n]+\\\\override)', 'ChordName\\1', str) return str - + conversions.append (((1,3,113), conv, 'LyricVoice -> LyricsVoice')) def regularize_id (str): @@ -702,7 +708,7 @@ def regularize_id (str): if 1: def conv (str): - + def regularize_dollar_reference (match): return regularize_id (match.group (1)) def regularize_assignment (match): @@ -710,7 +716,7 @@ if 1: str = re.sub ('\$([^\t\n ]+)', regularize_dollar_reference, str) str = re.sub ('\n([^ \t\n]+)[ \t]*= *', regularize_assignment, str) return str - + conversions.append (((1,3,117), conv, 'identifier names: $!foo_bar_123 -> xfooBarABC')) @@ -718,7 +724,7 @@ if 1: def conv (str): def regularize_paper (match): return regularize_id (match.group (1)) - + str = re.sub ('(paper_[a-z]+)', regularize_paper, str) str = re.sub ('sustainup', 'sustainUp', str) str = re.sub ('nobreak', 'noBreak', str) @@ -727,9 +733,9 @@ if 1: str = re.sub ('sostenutodown', 'sostenutoDown', str) str = re.sub ('unachorda', 'unaChorda', str) str = re.sub ('trechorde', 'treChorde', str) - + return str - + conversions.append (((1,3,120), conv, 'paper_xxx -> paperXxxx, pedalup -> pedalUp.')) if 1: @@ -737,21 +743,21 @@ if 1: str = re.sub ('drarnChords', 'chordChanges', str) str = re.sub ('\\musicalpitch', '\\pitch', str) return str - + conversions.append (((1,3,122), conv, 'drarnChords -> chordChanges, \\musicalpitch -> \\pitch')) if 1: def conv (str): str = re.sub ('ly-([sg])et-elt-property', 'ly-\\1et-grob-property', str) return str - + conversions.append (((1,3,136), conv, 'ly-X-elt-property -> ly-X-grob-property')) if 1: def conv (str): str = re.sub ('point-and-click +#t', 'point-and-click line-column-location', str) return str - + conversions.append (((1,3,138), conv, 'point-and-click argument changed to procedure.')) if 1: @@ -760,28 +766,28 @@ if 1: str = re.sub ('Thread.FollowThread', 'Voice.VoiceFollower', str) str = re.sub ('FollowThread', 'VoiceFollower', str) return str - + conversions.append (((1,3,138), conv, 'followThread -> followVoice.')) if 1: def conv (str): str = re.sub ('font-point-size', 'font-design-size', str) return str - + conversions.append (((1,3,139), conv, 'font-point-size -> font-design-size.')) if 1: def conv (str): str = re.sub ('([a-zA-Z]*)NoDots', '\\1Solid', str) return str - + conversions.append (((1,3,141), conv, 'xNoDots -> xSolid')) if 1: def conv (str): str = re.sub ('([Cc])hord([ea])', '\\1ord\\2', str) return str - + conversions.append (((1,3,144), conv, 'Chorda -> Corda')) @@ -791,7 +797,7 @@ if 1: str = re.sub ('([A-Za-z]+)ExtraVerticalExtent', 'ExtraV@rticalExtent', str) str = re.sub ('([A-Za-z]+)VerticalExtent', 'VerticalExtent', str) str = re.sub ('ExtraV@rticalExtent', 'ExtraVerticalExtent', str) - str = re.sub ('MinimumV@rticalExtent', 'MinimumVerticalExtent', str) + str = re.sub ('MinimumV@rticalExtent', 'MinimumVerticalExtent', str) return str conversions.append (((1,3,145), conv, @@ -805,7 +811,7 @@ if 1: # Make sure groups of more than one ; have space before # them, so that non of them gets removed by next rule str = re.sub ("([^ \n\t;]);(;+)", "\\1 ;\\2", str) - + # Only remove ; that are not after spaces, # or ; # Otherwise we interfere with Scheme comments, # which is badbadbad. @@ -837,15 +843,15 @@ if 1: if 1: def conv (str): str = re.sub ('arithmetic-multiplier', 'spacing-increment', str) - str = re.sub ('arithmetic-basicspace', 'shortest-duration-space', str) + str = re.sub ('arithmetic-basicspace', 'shortest-duration-space', str) return str - + conversions.append (((1,5,38), conv, 'SystemStartDelimiter -> systemStartDelimiter')) if 1: def conv (str): - + def func(match): break_dict = { "Instrument_name": "instrument-name", @@ -869,22 +875,22 @@ if 1: # 40 ? conversions.append (((1,5,40), conv, 'breakAlignOrder property names')) - + if 1: def conv (str): str = re.sub ('noAutoBeaming *= *##f', 'autoBeaming = ##t', str) str = re.sub ('noAutoBeaming *= *##t', 'autoBeaming = ##f', str) return str - + conversions.append (((1,5,49), conv, 'noAutoBeaming -> autoBeaming')) if 1: def conv (str): str = re.sub ('tuplet-bracket-visibility', 'bracket-visibility', str) - str = re.sub ('tuplet-number-visibility', 'number-visibility', str) + str = re.sub ('tuplet-number-visibility', 'number-visibility', str) return str - + conversions.append (((1,5,52), conv, 'tuplet-X-visibility -> X-visibility')) if 1: @@ -892,7 +898,7 @@ if 1: str = re.sub ('Pitch::transpose', 'ly-transpose-pitch', str) return str - + conversions.append (((1,5,56), conv, 'Pitch::transpose -> ly-transpose-pitch')) if 1: @@ -900,19 +906,19 @@ if 1: str = re.sub ('textNonEmpty *= *##t', "TextScript \\set #'no-spacing-rods = ##f", str) str = re.sub ('textNonEmpty *= *##f', "TextScript \\set #'no-spacing-rods = ##t", str) return str - + conversions.append (((1,5,58), conv, 'deprecate textNonEmpty')) if 1: def conv (str): str = re.sub ('MinimumVerticalExtent', 'minimumV@rticalExtent', str) - str = re.sub ('minimumVerticalExtent', 'minimumV@rticalExtent', str) + str = re.sub ('minimumVerticalExtent', 'minimumV@rticalExtent', str) str = re.sub ('ExtraVerticalExtent', 'extraV@rticalExtent', str) - str = re.sub ('extraVerticalExtent', 'extraV@rticalExtent', str) + str = re.sub ('extraVerticalExtent', 'extraV@rticalExtent', str) str = re.sub ('VerticalExtent', 'verticalExtent', str) str = re.sub ('extraV@rticalExtent', 'extraVerticalExtent', str) - str = re.sub ('minimumV@rticalExtent', 'minimumVerticalExtent', str) + str = re.sub ('minimumV@rticalExtent', 'minimumVerticalExtent', str) return str conversions.append (((1,5,59), conv, @@ -925,13 +931,14 @@ if 1: conversions.append (((1,5,62), conv, 'visibility-lambda -> break-visibility')) - + if 1: def conv (str): if re.search (r'\addlyrics',str) \ and re.search ('automaticMelismata', str) == None: - sys.stderr.write ('automaticMelismata is turned on by default since 1.5.67. Please fix this by hand.') + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "automaticMelismata; turned on by default since 1.5.67.") raise FatalConversionError() return str @@ -941,17 +948,17 @@ if 1: if 1: def conv (str): str = re.sub ('ly-set-grob-property([^!])', 'ly-set-grob-property!\1', str) - str = re.sub ('ly-set-mus-property([^!])', 'ly-set-mus-property!\1', str) + str = re.sub ('ly-set-mus-property([^!])', 'ly-set-mus-property!\1', str) return str - + conversions.append (((1,5,68), conv, 'ly-set-X-property -> ly-set-X-property!')) if 1: def conv (str): str = re.sub ('extent-X', 'X-extent', str) - str = re.sub ('extent-Y', 'Y-extent', str) + str = re.sub ('extent-Y', 'Y-extent', str) return str - + conversions.append (((1,5,71), conv, 'extent-[XY] -> [XY]-extent')) @@ -964,7 +971,7 @@ if 1: str = re.sub ('#\(set! +point-and-click +#f\)', '#(set-point-and-click! \'none)', str) return str - + conversions.append (((1,5,72), conv, 'set! point-and-click -> set-point-and-click!')) @@ -974,7 +981,7 @@ if 1: str = re.sub (r"""Stem([ ]+)\\override #'style""", r"""Stem \\override #'flag-style""", str); str = re.sub (r"""Stem([ ]+)\\set([ ]+)#'style""", r"""Stem \\set #'flag-style""", str); return str - + conversions.append (((1,6,5), conv, 'Stems: flag-style -> stroke-style; style -> flag-style')) @@ -986,7 +993,7 @@ if 1: str = re.sub ('\\(ly-make-music *\"([A-Z][a-z_]+)_req\"\\)', subst_req_name, str) str = re.sub ('Request_chord', 'EventChord', str) return str - + conversions.append (((1,7,1), conv, 'ly-make-music foo_bar_req -> make-music-by-name FooBarEvent')) @@ -1017,7 +1024,7 @@ if 1: return ' = #(make-event-chord (list %s))' % subst_ev_name (match) def subst_csp_inline (match): return '#(ly-export (make-event-chord (list %s)))' % subst_ev_name (match) - + def conv (str): str = re.sub (r' *= *\\spanrequest *([^ ]+) *"([^"]+)"', subst_definition_ev_name, str) str = re.sub (r'\\spanrequest *([^ ]+) *"([^"]+)"', subst_inline_ev_name, str) @@ -1066,23 +1073,23 @@ if 1: ] origre = r'\b(%s)' % string.join (changed, '|') - + str = re.sub (origre, r'ly:\1',str) str = re.sub ('set-point-and-click!', 'set-point-and-click', str) - + return str - + conversions.append (((1,7,3), conv, 'ly- -> ly:')) if 1: def conv(str): if re.search ('new-chords-done',str): return str - + str = re.sub (r'<<', '< <', str) str = re.sub (r'>>', '> >', str) return str - + conversions.append (((1,7,4), conv, '<< >> -> < < > >')) if 1: @@ -1122,13 +1129,13 @@ if 1: r"", str) return str conversions.append (((1,7,10), conv, "\property ChordName #'style -> #(set-chord-name-style 'style)")) - + if 1: def conv(str): str = re.sub (r"ly:transpose-pitch", "ly:pitch-transpose", str) - + return str conversions.append (((1,7,11), conv, "transpose-pitch -> pitch-transpose")) @@ -1139,17 +1146,17 @@ if 1: str = re.sub (r"ly:add-molecule", "ly:molecule-add", str) str = re.sub (r"ly:combine-molecule-at-edge", "ly:molecule-combine-at-edge", str) str = re.sub (r"ly:align-to!", "ly:molecule-align-to!", str) - + return str - - conversions.append (((1,7,13), conv, "ly:XX-molecule-YY -> ly:molecule-XX-YY")) + + conversions.append (((1,7,13), conv, "ly:XX-molecule-YY -> ly:molecule-XX-YY")) if 1: def conv(str): str = re.sub (r"linewidth *= *-[0-9.]+ *(\\mm|\\cm|\\in|\\pt)?", 'raggedright = ##t', str ) return str - - conversions.append (((1,7,15), conv, "linewidth = -1 -> raggedright = ##t")) + + conversions.append (((1,7,15), conv, "linewidth = -1 -> raggedright = ##t")) if 1: def conv(str): @@ -1160,7 +1167,7 @@ if 1: str = re.sub ("divisiomaxima", "divisioMaxima", str) return str - + conversions.append (((1,7,16), conv, "divisiomaior -> divisioMaior")) if 1: @@ -1168,7 +1175,7 @@ if 1: str = re.sub ("Skip_req_swallow_translator", "Skip_event_swallow_translator", str) return str - + conversions.append (((1,7,17), conv, "Skip_req -> Skip_event")) if 1: @@ -1181,7 +1188,7 @@ if 1: "#'enclose-bounds", str) return str - + conversions.append (((1,7,18), conv, """groupOpen/Close -> start/stopGroup, #'outer -> #'enclose-bounds @@ -1190,13 +1197,18 @@ if 1: if 1: def conv(str): if re.search( r'\\GraceContext', str): - sys.stderr.write ("GraceContext has been removed") - sys.stderr.write ("please use #(add-to-grace-init .. )") + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "GraceContext") + sys.stderr.write (FROM_TO \ + % ("GraceContext", "#(add-to-grace-init .. )")) + sys.stderr.write ('\n') + sys.stderr.write (UPDATE_MANUALLY) + sys.stderr.write ('\n') raise FatalConversionError() str = re.sub ('HaraKiriStaffContext', 'RemoveEmptyStaffContext', str) return str - + conversions.append (((1,7,19), conv,"remove GraceContext")) @@ -1208,7 +1220,7 @@ if 1: r"\1 #'style", str) return str - + conversions.append (((1,7,22), conv,"#'type -> #'style")) if 1: @@ -1222,21 +1234,23 @@ if 1: "automaticBars = ##t", str) return str - + conversions.append (((1,7,23), conv,"barNonAuto -> automaticBars")) - + if 1: def conv(str): if re.search( r'-(start|stop)Cluster', str): - sys.stderr.write ("""Cluster syntax has been changed. -Please refer to the manual for details, and convert manually. -""") - + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "Cluster syntax") + sys.stderr.write ('\n') + sys.stderr.write (UPDATE_MANUALLY) + sys.stderr.write ('\n') + raise FatalConversionError() return str - + conversions.append (((1,7,24), conv,"cluster syntax")) if 1: @@ -1245,7 +1259,7 @@ if 1: r"\property Staff.pedal\1Style ", str) str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\revert *#'pedal-type", '', str) return str - + conversions.append (((1,7,28), conv,"new Pedal style syntax")) @@ -1292,7 +1306,7 @@ if 1: if tr not in slur_strs: slur_strs.append (tr) return m.group (1) - + str = re.sub (r"([a-z]+[',!? ]*)(:[0-9]+)", sub_tremolos, str) @@ -1305,19 +1319,19 @@ if 1: if '-)' not in slur_strs: slur_strs.append (')') return m.group(1) - + def sub_p_slurs(m, slur_strs = slur_strs): if '-\)' not in slur_strs: slur_strs.append ('\)') return m.group(1) - + str = re.sub (r"\)[ ]*([a-z]+)", sub_slurs, str) str = re.sub (r"\\\)[ ]*([a-z]+)", sub_p_slurs, str) def sub_begin_slurs(m, slur_strs = slur_strs): if '-(' not in slur_strs: slur_strs.append ('(') return m.group(1) - + str = re.sub (r"([a-z]+[,'!?0-9 ]*)\(", sub_begin_slurs, str) def sub_begin_p_slurs(m, slur_strs = slur_strs): @@ -1382,7 +1396,7 @@ if 1: return str str = re.sub ('<<', '@STARTCHORD@', str) str = re.sub ('>>', '@ENDCHORD@', str) - + str = re.sub (r'\\<', '@STARTCRESC@', str) str = re.sub (r'\\>', '@STARTDECRESC@', str) str = re.sub (r'([_^-])>', r'\1@ACCENT@', str) @@ -1395,7 +1409,7 @@ if 1: r'\1-[', str) str = re.sub (r'\\! *(@STARTCHORD@[^@]+@ENDCHORD@[0-9.]*)', r'\1-\\!', str) - + str = re.sub (r'<([^?])', r'%s\1' % simstart, str) str = re.sub (r'>([^?])', r'%s\1' % simend, str) str = re.sub ('@STARTCRESC@', r'\\<', str) @@ -1416,7 +1430,7 @@ if 1: r"\\mark \\markup { \\musicglyph #\1 }", str) str = re.sub (r"""\\mark *# *' *\( *([a-z]+) *([^()]*)\)""", r"\\mark \\markup { \\\1 \2 }", str) - return str + return str def articulation_substitute (str): str = re.sub (r"""([^-])\[ *([a-z]+[,']*[!?]?[0-9:]*\.*)""", @@ -1428,13 +1442,13 @@ if 1: str = re.sub (r"""([^-])\\! *([a-z]+[,']*[!?]?[0-9:]*\.*)""", r"\1 \2\\!", str) return str - + def conv_relative(str): if re.search (r"\\relative", str): str= "#(ly:set-option 'old-relative)\n" + str return str - + def conv (str): str = re.sub (r"#'\(\)", "@SCM_EOL@", str) str = conv_relative (str) @@ -1443,18 +1457,23 @@ if 1: str = text_markup (str) str = articulation_substitute (str) str = re.sub ("@SCM_EOL@", "#'()", str) - + return str - + conversions.append (((1,9,0), conv, """New relative mode, Postfix articulations, new text markup syntax, new chord syntax.""")) if 1: def conv (str): if re.search ("font-style",str): - sys.stderr.write ("font-style is deprecated. Please remove.") + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "font-sytle") + sys.stderr.write ('\n') + sys.stderr.write (UPDATE_MANUALLY) + sys.stderr.write ('\n') + raise FatalConversionError() - + str = re.sub (r'-\\markup', r'@\\markup', str) str = re.sub (r'-\\', r'\\', str) str = re.sub (r'-\)', ')', str) @@ -1479,9 +1498,9 @@ if 1: \1 \\property Voice.Stem \\revert #'stroke-style } """, str) - + return str - + conversions.append (((1,9,2), conv, """\\newcontext -> \\new""")) if 1: @@ -1490,17 +1509,21 @@ if 1: 'acciaccatura', str) if re.search ("context-spec-music", str): - sys.stderr.write ("context-spec-music takes a symbol for the context now. Update by hand.") - + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "context-spec-music") + sys.stderr.write ('\n') + sys.stderr.write (UPDATE_MANUALLY) + sys.stderr.write ('\n') + raise FatalConversionError() - + str = re.sub ('fingerHorizontalDirection *= *#(LEFT|-1)', "fingeringOrientations = #'(up down left)", str) str = re.sub ('fingerHorizontalDirection *= *#(RIGHT|1)', "fingeringOrientations = #'(up down right)", str) return str - + conversions.append (((1,9,3), conv, """\\acciaccatura misspelling, fingerHorizontalDirection -> fingeringOrientations""")) @@ -1508,14 +1531,14 @@ if 1: def conv (str): if re.search ('\\figures', str): sys.stderr.write ("Warning: attempting automatic \\figures conversion. Check results!"); - - + + def figures_replace (m): s = m.group (1) s = re.sub ('<', '@FIGOPEN@',s) s = re.sub ('>', '@FIGCLOSE@',s) return '\\figures { %s }' % s - + str = re.sub (r'\\figures[ \t\n]*{([^}]+)}', figures_replace, str) str = re.sub (r'\\<', '@STARTCRESC@', str) str = re.sub (r'\\>', '@STARTDECRESC@', str) @@ -1548,20 +1571,26 @@ conversions.append (((1,9,5), conv, 'HaraKiriVerticalGroup -> RemoveEmptyVertica def conv (str): if re.search ("ly:get-font", str) : - sys.stderr.write (r"(ly:get-font foo ..) has been replaced by" + \ - " (ly:paper-get-font (ly:grob-get-paper foo) .. ).\n" +\ - "please update manually.") - + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "(ly:-get-font") + sys.stderr.write ('\n') + sys.stderr.write (FROM_TO \ + % ("(ly:paper-get-font (ly:grob-get-paper foo) .. )", + "(ly:paper-get-font (ly:grob-get-paper foo) .. )")) + sys.stderr.write (UPDATE_MANUALLY) + sys.stderr.write ('\n') raise FatalConversionError() - + if re.search ("\\pitch *#", str) : - sys.stderr.write (r"\\pitch has been deprecated. " +\ - " Use Scheme code to construct arbitrary note events.") - + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "\\pitch") + sys.stderr.write ('\n') + sys.stderr.write ("Use Scheme code to construct arbitrary note events.") + raise FatalConversionError() - + return str - + conversions.append (((1,9,6), conv, 'ly:get-font deprecated.')) @@ -1575,10 +1604,10 @@ def conv (str): '1': 'SHARP', '2': 'DOUBLE-SHARP', }[alt] - + return '(ly:make-pitch %s %s %s)' % (m.group(1), m.group (2), alt) - + str =re.sub ("\\(ly:make-pitch *([0-9-]+) *([0-9-]+) *([0-9-]+) *\\)", sub_alteration, str) @@ -1598,15 +1627,18 @@ as a substitution text.""" % (m.group (1), m.group (2)) ) if re.search ("ly:(make-pitch|pitch-alteration)", str) \ or re.search ("keySignature", str): + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "pitches") + sys.stderr.write ('\n') sys.stderr.write ( """The alteration field of Scheme pitches was multiplied by 2 -to support quarter tone accidentals. You have to edit the following constructs by hand: +to support quarter tone accidentals. You must update the following constructs by manually: -* calls of ly:make-pitch and ly:pitch-alteration +* calls of ly:make-pitch and ly:pitch-alteration * keySignature settings made with \property """) raise FatalConversionError () - + return str conversions.append (((1,9,7), conv, '''use symbolic constants for alterations, @@ -1615,7 +1647,13 @@ remove \\outputproperty, move ly:verbose into ly:get-option''')) def conv (str): if re.search ("dash-length",str): - sys.stderr.write ("""dash-length has been removed. Use dash-fraction instead.""") + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "dash-length") + sys.stderr.write ('\n') + sys.stderr.write (FROM_TO % ("dash-length", "dash-fraction")) + sys.stderr.write ('\n') + sys.stderr.write (UPDATE_MANUALLY) + sys.stderr.write ('\n') raise FatalConversionError() return str @@ -1624,12 +1662,12 @@ conversions.append (((1,9,8), conv, """dash-length -> dash-fraction""")) def conv (str): def func(match): - return "#'font-size = #%d" % (2*string.atoi (match.group (1))) - + return "#'font-size = #%d" % (2*string.atoi (match.group (1))) + str =re.sub (r"#'font-relative-size\s*=\s*#\+?([0-9-]+)", func, str) str =re.sub (r"#'font-family\s*=\s*#'ancient", r"#'font-family = #'music", str) - + return str conversions.append (((2,1,1), conv, """font-relative-size -> font-size""")) @@ -1650,7 +1688,7 @@ def conv (str): def func (match): c = match.group (1) b = match.group (2) - + if b == 't': if c == 'Score': return '' @@ -1658,8 +1696,8 @@ def conv (str): return r" \property %s.melismaBusyProperties \unset" % c elif b == 'f': return r"\property %s.melismaBusyProperties = #'(melismaBusy)" % c - - str =re.sub (r"\\property ([a-zA-Z]+)\s*\.\s*automaticMelismata\s*=\s*##([ft])", func, str) + + str = re.sub (r"\\property ([a-zA-Z]+)\s*\.\s*automaticMelismata\s*=\s*##([ft])", func, str) return str conversions.append (((2,1,4), conv, """removal of automaticMelismata; use melismaBusyProperties instead.""")) @@ -1686,7 +1724,7 @@ def conv (str): dur = '' log = string.atoi (match.group (1)) dots = string.atoi (match.group (2)) - + if log >= 0: dur = '%d' % (1 << log) else: @@ -1695,9 +1733,9 @@ def conv (str): -3 : 'maxima'}[log] dur += ('.' * dots) - + return r'\note #"%s" #%s' % (dur, match.group (3)) - + str = re.sub (r'\\note\s+#([0-9-]+)\s+#([0-9]+)\s+#([0-9.-]+)', sub_note, str) return str @@ -1730,7 +1768,7 @@ conversions.append (((2,1,14), conv, """style = dotted -> dash-fraction = 0""")) def conv (str): str =re.sub (r'LyricsVoice\s*\.\s*instrument\s*=\s*("[^"]*")', r'LyricsVoice . vocalName = \1', str) - + str =re.sub (r'LyricsVoice\s*\.\s*instr\s*=\s*("[^"]*")', r'LyricsVoice . vocNam = \1', str) return str @@ -1750,7 +1788,7 @@ def conv (str): '-3': 'threeqflat', '-4': 'doubleflat'} return '\\%s' % d[m.group (1)] - + str = re.sub (r'\\musicglyph\s*#"accidentals-([0-9-]+)"', sub_acc, str) return str @@ -1761,9 +1799,11 @@ conversions.append (((2,1,16), conv, """\\musicglyph #"accidentals-NUM" -> \\sha def conv (str): if re.search (r'\\partcombine', str): - sys.stderr.write ('Warning: \\partcombine has been changed. ' - +'Check conversion manually!') - + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "\\partcombine") + sys.stderr.write ('\n') + sys.stderr.write (UPDATE_MANUALLY) + sys.stderr.write ('\n') raise FatalConversionError() # this rule doesn't really work, @@ -1771,8 +1811,8 @@ def conv (str): str = re.sub (r'\\context\s+Voice\s*=\s*one\s*\\partcombine\s+Voice\s*\\context\s+Thread\s*=\s*one(.*)\s*' + r'\\context\s+Thread\s*=\s*two', '\\\\newpartcombine\n\\1\n', str) - - + + return str conversions.append (((2,1,17), conv, """\\partcombine syntax change to \\newpartcombine""")) @@ -1796,11 +1836,11 @@ def conv (str): str = re.sub (r'\\chordmodifiers ','chordmodifiers = ', str) str = re.sub (r'\bdrums\b\s*=','drumContents = ', str) str = re.sub (r'\\drums\b','\\drumContents ', str) - + if re.search ('drums->paper', str): sys.stderr.write ("\nDrum notation found. Check file manually!") - + str = re.sub (r"""\\apply\s+#\(drums->paper\s+'([a-z]+)\)""", r"""\property DrumStaff.drumStyleTable = #\1-style""", str) @@ -1810,7 +1850,7 @@ def conv (str): str = re.sub (r"""(\\once\s*)?\\property\s+Thread\s*\.\s*NoteHead\s*""" + r"""\\(set|override)\s*#'style\s*=\s*#'harmonic""" - + r"""\s+([a-z]+[,'=]*)([0-9]*\.*)""" + + r"""\s+([a-z]+[,'=]*)([0-9]*\.*)""" ,r"""<\3\\harmonic>\4""", str) str = re.sub (r"""\\new Thread""", """\context Voice""", str) @@ -1823,8 +1863,8 @@ def conv (str): str = re.sub (r"""\bLyrics\b""", r"""LyricsVoice""", str) str = re.sub (r"""LyricsContext""", r"""LyricsVoiceContext""", str) str = re.sub (r"""L@ricsVoice""", r"""LyricsVoice""",str) - - + + return str conversions.append (((2,1,19), conv, """Drum notation changes, Removing \\chordmodifiers, \\notenames. @@ -1861,6 +1901,8 @@ Grob::preset_extent removed. def conv (str): + str = re.sub (r'(\\property[^=]+)=\s*([-0-9]+)', + r'\1= #\2', str) str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\=]+)\s*\\(set|override)', r"\\overrid@ \1.\2 ", str) str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*=\s*', @@ -1873,7 +1915,7 @@ def conv (str): str = re.sub (r'Voice\.', '', str) str = re.sub (r'Lyrics\.', '', str) str = re.sub (r'ChordNames\.', '', str) - + str = re.sub ('rev@rt', 'revert',str) str = re.sub ('s@t', 'set',str) str = re.sub ('overrid@', 'override',str) @@ -1901,28 +1943,28 @@ def conv (str): str = re.sub (r'\\(translator|with)\s*{[^}]+}', subst_in_trans, str) def sub_abs (m): - + context = m.group ('context') d = m.groupdict () if context: - context = " '%s" % context[:-1] # -1: remove . + context = " '%s" % context[:-1] # -1: remove . else: context = '' d['context'] = context - + return r"""#(override-auto-beam-setting %(prop)s %(num)s %(den)s%(context)s)""" % d str = re.sub (r"""\\override\s*(?P[a-zA-Z]+\s*\.\s*)?autoBeamSettings""" +r"""\s*#(?P[^=]+)\s*=\s*#\(ly:make-moment\s+(?P\d+)\s+(?P\d)\s*\)""", sub_abs, str) - + return str - + conversions.append (((2,1,23), conv, """Property setting syntax in \\translator{ }""")) def conv (str): str = re.sub (r'music-list\?', 'ly:music-list?', str) - str = re.sub (r'\|\s*~', '~ |', str) + str = re.sub (r'\|\s*~', '~ |', str) return str conversions.append (((2,1,24), conv, """music-list? -> ly:music-list?""")) @@ -1936,6 +1978,9 @@ def conv (str): str = re.sub (r'ly:get-broken-into', 'ly:spanner-broken-into', str) str = re.sub (r'Melisma_engraver', 'Melisma_translator', str) if re.search ("ly:get-paper-variable", str): + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "ly:paper-get-variable") + sys.stderr.write ('\n') sys.stderr.write ('use (ly:paper-lookup (ly:grob-paper ))') raise FatalConversionError() @@ -1949,7 +1994,7 @@ def conv (str): str = re.sub (r'\\pianoCautionaries', "#(set-accidental-style 'piano-cautionary)", str) str = re.sub (r'\\forgetAccidentals', "#(set-accidental-style 'forget)", str) str = re.sub (r'\\noResetKey', "#(set-accidental-style 'no-reset)", str) - + return str conversions.append (((2,1,25), conv, """Scheme grob function renaming""")) @@ -1957,12 +2002,12 @@ conversions.append (((2,1,25), conv, """Scheme grob function renaming""")) def conv (str): str = re.sub ('ly:set-grob-property!', 'ly:grob-set-property!',str) - str = re.sub ('ly:set-mus-property!', 'ly:music-set-property!',str) - str = re.sub ('ly:set-context-property!', 'ly:context-set-property!', str) + str = re.sub ('ly:set-mus-property!', 'ly:music-set-property!',str) + str = re.sub ('ly:set-context-property!', 'ly:context-set-property!', str) str = re.sub ('ly:get-grob-property', 'ly:grob-property',str) str = re.sub ('ly:get-mus-property', 'ly:music-property',str) str = re.sub ('ly:get-context-property', 'ly:context-property',str) - + return str conversions.append (((2,1,26), conv, """More Scheme function renaming""")) @@ -1978,21 +2023,21 @@ def conv (str): lower_pitches = filter (lambda x : x <= g, [0, 2, 4, 5, 7, 9, 11, 12]) - s = len (lower_pitches) -1 + s = len (lower_pitches) -1 a = g - lower_pitches [-1] - print s , lower_pitches, g, a, s + print s , lower_pitches, g, a, s str = 'cdefgab' [s] str += ['eses', 'es', '', 'is', 'isis'][a + 2] if o < 0: str += ',' * (-o - 1) elif o >= 0: str += "'" * (o + 1) - + return '\\transposition %s ' % str - + str = re.sub (r"\\set ([A-Za-z]+\s*\.\s*)?transposing\s*=\s*#([-0-9]+)", subst, str) return str @@ -2025,7 +2070,7 @@ def conv (str): 'ly:context-find', str) str = re.sub ('ly:unset-context-property','ly:context-unset-property', str) - + str = re.sub (r'ly:get-mutable-properties', 'ly:mutable-music-properties',str) str = re.sub (r'centralCPosition', @@ -2053,7 +2098,7 @@ def conv (str): str = re.sub (r"(\\set\s+)?(?P(Score\.)?)breakAlignOrder\s*=\s*#'(?P[^\)]+)", r"\n\\override \gBreakAlignment #'break-align-orders = " + "#(make-vector 3 '\g)", str) - + return str conversions.append (((2,1,33), conv, @@ -2080,7 +2125,7 @@ conversions.append (((2,1, 36), conv, def conv (str): return str -conversions.append (((2,2, 0), conv, +conversions.append (((2, 2, 0), conv, '''clean up version. ''')) def conv (str): @@ -2090,6 +2135,13 @@ conversions.append (((2, 3, 1), conv, '''\\apply -> \\applymusic''')) def conv (str): + if re.search ('textheight', str): + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % "tuning of page layout") + sys.stderr.write ('\n') + sys.stderr.write (UPDATE_MANUALLY) + sys.stderr.write ('\n') + str = re.sub (r'\\OrchestralScoreContext', '\\Score', str) def func(m): if m.group(1) not in ['RemoveEmptyStaff', @@ -2098,8 +2150,8 @@ def conv (str): return '\\' + m.group (1) else: return m.group (0) - - + + str = re.sub (r'\\([a-zA-Z]+)Context\b', func, str) str = re.sub ('ly:paper-lookup', 'ly:output-def-lookup', str) @@ -2110,7 +2162,7 @@ conversions.append (((2, 3, 2), conv, def conv (str): str = re.sub (r'\\notes\b', '', str) - + return str conversions.append (((2, 3, 4), conv, @@ -2118,6 +2170,15 @@ conversions.append (((2, 3, 4), conv, +def conv (str): + str = re.sub (r'lastpagefill\s*=\s*"?1"', 'raggedlastbottom = ##t', str) + return str + +conversions.append (((2, 3, 6), conv, + '''lastpagefill -> raggedlastbottom''')) + + + def conv (str): str = re.sub (r'\\consistsend', '\\consists', str) str = re.sub (r'\\lyricsto\s+("?[a-zA-Z]+"?)(\s*\\new Lyrics\s*)?\\lyrics', @@ -2140,6 +2201,8 @@ conversions.append (((2, 3, 9), conv, def conv (str): str = re.sub (r'\\addlyrics', r'\\oldaddlyrics', str) str = re.sub (r'\\newlyrics', r'\\addlyrics', str) + if re.search (r"\\override\s*TextSpanner", str): + sys.stderr.write ("\nWarning: TextSpanner has been split into DynamicTextSpanner and TextSpanner\n") return str conversions.append (((2, 3, 10), conv, @@ -2170,6 +2233,8 @@ def conv (str): str = re.sub ('soloADue', 'printPartCombineTexts', str) str = re.sub (r'\\applymusic\s*#notes-to-clusters', '\\makeClusters', str) + + str = re.sub (r'pagenumber\s*=', 'firstpagenumber', str) return str conversions.append (((2, 3, 12), conv, @@ -2216,8 +2281,167 @@ conversions.append (((2, 3, 18), conv, '''Text_item -> Text_interface''' )) +def conv (str): + str = re.sub (r'\\paper', r'\\layout', str) + str = re.sub (r'\\bookpaper', r'\\paper', str) + if re.search ('paper-set-staff-size', str): + sys.stderr.write ('''\nWarning: staff size should be changed at top-level +with + + #(set-global-staff-size ) + +''') + + + str = re.sub (r'#\(paper-set-staff-size', '%Use set-global-staff-size at toplevel\n% #(layout-set-staff-size', str) + return str + +conversions.append (((2, 3, 22), + conv, + '''paper -> layout + bookpaper -> paper''' )) + + +def conv (str): + str = re.sub (r'\\context\s+([a-zA-Z]+)\s*=\s*([a-z]+)\s', + r'\\context \1 = "\2" ', + str ) + return str + +conversions.append (((2, 3, 23), + conv, + '''\context Foo = NOTENAME -> \context Foo = "NOTENAME"''')) + +def conv (str): + def sub(m): + return regularize_id (m.group (1)) + str = re.sub (r'(maintainer_email|maintainer_web|midi_stuff|gourlay_maxmeasures)', + sub, str) + return str + +conversions.append (((2, 3, 24), + conv, + '''regularize other identifiers.''')) + + +def conv (str): + return str + +conversions.append (((2, 4, 0), + conv, + '')) + + +def conv (str): + str = re.sub (r'\\quote\s+"?([a-zA-Z0-9]+)"?\s+([0-9.*/]+)', + r'\\quoteDuring #"\1" { \skip \2 }', + str + ) + return str + +conversions.append (((2, 5, 0), + conv, + '')) + + +def conv (str): + str = re.sub (r'ly:import-module', + r'ly:module-copy', str) + return str + +conversions.append (((2, 5, 1), + conv, + 'ly:import-module -> ly:module-copy')) + +def conv (str): + str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<([^<]*)>', + r'\\\1 {\2}', str) + str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<([^<]*)>', + r'\\\1 {\2}', str) + str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<([^<]*)>', + r'\\\1 {\2}', str) + return str + +conversions.append (((2, 5, 2), + conv, + '\markup .. < .. > .. -> \markup .. { .. } ..')) + +def conv (str): + str = re.sub ('ly:find-glyph-by-name', 'ly:font-get-glyph', str) + str = re.sub ('"(scripts|clefs|accidentals)-', r'"\1.', str) + str = re.sub ("'hufnagel-do-fa", "'hufnagel.do.fa", str) + str = re.sub ("'(vaticana|hufnagel|medicaea|petrucci|neomensural|mensural)-", r"'\1.", str) + return str + +conversions.append (((2, 5, 3), + conv, + 'ly:find-glyph-by-name -> ly:font-get-glyph, remove - from glyphnames.')) + + +def conv (str): + str = re.sub (r"\\override\s+(Voice\.)?Slur #'dashed\s*=\s*#\d*(\.\d+)?", + r"\\slurDashed", str) + return str + +conversions.append (((2, 5, 12), + conv, + '\set Slur #\'dashed = #X -> \slurDashed')) + +def conv (str): + input_encoding = 'latin1' + def func (match): + encoding = match.group (1) + + # FIXME: automatic recoding of other than latin1? + if encoding == 'latin1': + return match.group (2) + + sys.stderr.write ('\n') + sys.stderr.write (NOT_SMART % ("\\encoding: %s" % encoding)) + sys.stderr.write ('\n') + sys.stderr.write (_ ("LilyPond source must be UTF-8")) + sys.stderr.write ('\n') + if encoding == 'TeX': + sys.stderr.write (_ ("Try the texstrings backend")) + sys.stderr.write ('\n') + else: + sys.stderr.write ( _("Do something like: %s") % \ + ("recode %s..utf-8 FILE" % encoding)) + sys.stderr.write ('\n') + sys.stderr.write (_ ("Or save as UTF-8 in your editor")) + sys.stderr.write ('\n') + raise FatalConversionError () + + return match.group (0) + + str = re.sub (r'\\encoding\s+"?([a-zA-Z0-9]+)"?(\s+)', func, str) + + import codecs + de_ascii = codecs.getdecoder ('ascii') + de_utf_8 = codecs.getdecoder ('utf_8') + de_input = codecs.getdecoder (input_encoding) + en_utf_8 = codecs.getencoder ('utf_8') + try: + de_ascii (str) + except UnicodeDecodeError: + # do not re-recode UTF-8 input + try: + de_utf_8 (str) + except UnicodeDecodeError: + str = en_utf_8 (de_input (str)[0])[0] + + + + str = re.sub (r"#\(ly:set-point-and-click '[a-z-]+\)", '', str) + return str + +conversions.append (((2, 5, 13), + conv, + '\\encoding: smart recode latin1..utf-8. Remove ly:point-and-click')) + + ################################ -# END OF CONVERSIONS +# END OF CONVERSIONS ################################ def get_conversions (from_version, to_version): @@ -2232,36 +2456,44 @@ def latest_version (): def do_conversion (infile, from_version, outfile, to_version): conv_list = get_conversions (from_version, to_version) - sys.stderr.write ('Applying conversions: ') + sys.stderr.write (_ ("Applying conversion: ")) str = infile.read () last_conversion = () try: for x in conv_list: - sys.stderr.write (tup_to_str (x[0]) + ', ') + sys.stderr.write (tup_to_str (x[0])) str = x[1] (str) last_conversion = x[0] + if x != conv_list[-1]: + sys.stderr.write (', ') except FatalConversionError: - sys.stderr.write ('Error while converting; I won\'t convert any further') + sys.stderr.write (_ ("%s: error while converting") \ + % program_name) + sys.stderr.write ('\n') + sys.stderr.write (_ ("Aborting")) + sys.stderr.write ('\n') if last_conversion: - sys.stderr.write ('\n') new_ver = '\\version \"%s\"' % tup_to_str (last_conversion) if re.search (lilypond_version_re_str, str): - str = re.sub (lilypond_version_re_str,'\\'+new_ver , str) + str = re.sub (lilypond_version_re_str, + '\\%s' % new_ver, str) elif add_version: str = new_ver + '\n' + str - outfile.write(str) + sys.stderr.write ('\n') + outfile.write (str) return last_conversion - + class UnknownVersion: pass def do_one_file (infile_name): - sys.stderr.write ('Processing `%s\' ... '% infile_name) + sys.stderr.write (_ ("Processing `%s\'... ") % infile_name) + sys.stderr.write ('\n') outfile_name = '' if __main__.edit: outfile_name = infile_name + '.NEW' @@ -2273,7 +2505,7 @@ def do_one_file (infile_name): else: guess = guess_lilypond_version (infile_name) if not guess: - raise UnknownVersion() + raise UnknownVersion () from_version = str_to_tuple (guess) if __main__.to_version: @@ -2308,7 +2540,6 @@ def do_one_file (infile_name): os.rename (infile_name, infile_name + '~') os.rename (infile_name + '.NEW', infile_name) - sys.stderr.write ('\n') sys.stderr.flush () edit = 0 @@ -2316,17 +2547,20 @@ assume_old = 0 to_version = () from_version = () outfile_name = '' +show_rules_p = 0 -(options, files) = getopt.getopt ( - sys.argv[1:], 'ao:f:t:senh', ['no-version', 'version', 'output', 'show-rules', 'help', 'edit', 'from=', 'to=']) +(options, files) = getopt.getopt (sys.argv[1:], 'ao:f:t:senhv', + ['no-version', 'version', 'output', + 'show-rules', 'help', 'edit', + 'from=', 'to=']) for opt in options: o = opt[0] a = opt[1] - if o== '--help' or o == '-h': + if o == '--help' or o == '-h': usage () sys.exit (0) - if o == '--version' or o == '-v': + elif o == '--version' or o == '-v': print_version () sys.exit (0) elif o== '--from' or o=='-f': @@ -2336,8 +2570,7 @@ for opt in options: elif o== '--edit' or o == '-e': edit = 1 elif o== '--show-rules' or o == '-s': - show_rules (sys.stdout) - sys.exit(0) + show_rules_p = 1 elif o == '--output' or o == '-o': outfile_name = a elif o == '--no-version' or o == '-n': @@ -2346,6 +2579,11 @@ for opt in options: print o raise getopt.error +# should parse files[] to read \version? +if show_rules_p: + show_rules (sys.stdout) + sys.exit (0) + identify () for f in files: if f == '-': @@ -2356,15 +2594,17 @@ for f in files: do_one_file (f) except UnknownVersion: sys.stderr.write ('\n') - sys.stderr.write ("%s: can't determine version for `%s'" % (program_name, f)) + sys.stderr.write (_ ("%s: cannot determine version for `%s'") \ + % (program_name, f)) sys.stderr.write ('\n') if assume_old: fv = from_version - from_version = (0,0,0) + from_version = (0, 0, 0) do_one_file (f) from_version = fv else: - sys.stderr.write ("%s: skipping: `%s' " % (program_name, f)) + sys.stderr.write (_ ("%s: skipping: `%s'") \ + % (program_name, f)) pass sys.stderr.write ('\n')