#!@PYTHON@
-
-# convert-lilypond.py -- convertor for lilypond versions
+#
+# convert-ly.py -- convertor for lilypond versions
#
# source file of the GNU LilyPond music typesetter
#
-# (c) 1998
+# (c) 1998--2001
# TODO
# use -f and -t for -s output
# lilypond_version_re_str = '\\\\version *\"(.*)\"'
lilypond_version_re_str = '\\\\(mudela-)?version *\"(.*)\"'
lilypond_version_re = re.compile (lilypond_version_re_str)
+add_version = 1
+
def program_id ():
return '%s (GNU LilyPond) %s' %(program_name, version);
-a, --assume-old apply all conversions to unversioned files
-h, --help print this help
-e, --edit in place edit
- -f, --from=VERSION start from version
+ -f, --from=VERSION start from version. Overrides \version found in file.
-s, --show-rules print all rules.
-t, --to=VERSION target version
+ -n, --no-version don't add new version stamp.
--version print program version
Report bugs to bugs-gnu-music@gnu.org
############################
+if 1:
+ def conv(str):
+ if re.search ('\\\\multi', str):
+ sys.stderr.write ('\nNot smart enough to convert \\multi')
+ return str
+
+ conversions.append (((0,1,9), conv, '\\header { key = concat + with + operator }'))
+
if 1: # need new a namespace
def conv (str):
if re.search ('\\\\octave', str):
sys.stderr.write ('\nNot smart enough to convert \\octave')
- raise FatalConversionError()
+ # raise FatalConversionError()
return str
def conv (str):
str = re.sub ('\\\\textstyle([^;]+);',
'\\\\property Lyrics . textstyle = \\1', str)
- str = re.sub ('\\\\key([^;]+);', '\\\\accidentals \\1;', str)
+ # harmful to current .lys
+ # str = re.sub ('\\\\key([^;]+);', '\\\\accidentals \\1;', str)
return str
if 1:
def conv(str):
- str = re.sub ('\\\\melodic', '\\\\notes',str)
- if re.search ('\\\\header', str):
- sys.stderr.write ('\nNot smart enough to convert \\multi constructs')
-
+ str = re.sub ('\\\\melodic([^a-zA-Z])', '\\\\notes\\1',str)
return str
conversions.append (((1,0,3), conv, '\\melodic -> \\notes'))
if 1:
def conv(str):
str = re.sub ('ChoireStaff', 'ChoirStaff',str)
- str = re.sub ('\\output', 'output = ',str)
+ str = re.sub ('\\\\output', 'output = ',str)
return str
def conv(str):
if re.search ('[a-zA-Z]+ = *\\translator',str):
sys.stderr.write ('\nNot smart enough to change \\translator syntax')
- raise FatalConversionError()
+ # raise FatalConversionError()
return str
conversions.append (((1,0,6), conv, 'foo = \\translator {\\type .. } ->\\translator {\\type ..; foo; }'))
if 1:
def conv(str):
+ str = re.sub ('\\\\type([^\n]*engraver)','\\\\TYPE\\1', str)
+ str = re.sub ('\\\\type([^\n]*performer)','\\\\TYPE\\1', str)
str = re.sub ('\\\\type','\\\\context', str)
+ str = re.sub ('\\\\TYPE','\\\\type', str)
str = re.sub ('textstyle','textStyle', str)
return str
def conv(str):
if re.search ('\\\\repeat',str):
sys.stderr.write ('\nNot smart enough to convert \\repeat')
- raise FatalConversionError()
+ # raise FatalConversionError()
return str
conversions.append (((1,0,18), conv,
conversions.append (((1,3,18), conv, 'staffLineLeading -> staffSpace'))
+
+if 1:
+ def conv(str):
+ if re.search ('\\\\repetitions',str):
+ sys.stderr.write ('\nNot smart enough to convert \\repetitions')
+ # raise FatalConversionError()
+ return str
+
+ conversions.append (((1,3,23), conv,
+ '\\\\repetitions feature dropped'))
+
+
if 1:
def conv (str):
str = re.sub ('textEmptyDimension *= *##t',
conversions.append (((1,3,49), conv,
'noteHeadStyle value: string -> symbol'))
+if 1:
+ def conv (str):
+ if re.search ('\\\\keysignature', str):
+ sys.stderr.write ('\nNot smart enough to convert to new tremolo format')
+ return str
+
+
+ conversions.append (((1,3,58), conv,
+ 'noteHeadStyle value: string -> symbol'))
+
if 1:
def conv (str):
str = re.sub (r"""\\key *([a-z]+) *;""", r"""\\key \1 \major;""",str);
-################ TODO: lots of other syntax change should be done here as well
-
-
+# TODO: lots of other syntax change should be done here as well
if 1:
def conv (str):
str = re.sub ('basicCollisionProperties', 'NoteCollision', str)
str = re.sub ('basicLocalKeyProperties' ,"Accidentals", str)
- str = re.sub ('basicMarkProperties' ,"Accidentals", str)
+ str = re.sub ('basicMarkProperties' ,"Accidentals", str)
str = re.sub ('basic([A-Za-z_]+)Properties', '\\1', str)
+ str = re.sub ('Repeat_engraver' ,'Volta_engraver', str)
return str
- conversions.append (((1,3,92), conv, 'basicXXXProperties -> XXX'))
+ conversions.append (((1,3,92), conv, 'basicXXXProperties -> XXX, Repeat_engraver -> Volta_engraver'))
if 1:
def conv (str):
str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\stemUp\\\\slurUp\\\\tieUp', str)
str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\stemDown\\\\slurDown\\\\tieDown', str)
str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\stemBoth\\\\slurBoth\\\\tieBoth', str)
+
+ 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)
+ # (lacks capitalisation slur -> Slur)
+ str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\1 \\\\override #\'direction = #1', str)
+ str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\1 \\override #\'direction = #-1', str)
+ str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\1 \\\\override #\'direction = #0', str)
+
## dynamic..
str = re.sub ('\\\\property *[^ .]*[.]?dynamicDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\dynamicUp', str)
str = re.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\dynamicDown', str)
conversions.append (((1,3,97), conv, 'ChordName -> ChordNames'))
-## TODO: add lots of these
+# TODO: add lots of these
if 1:
def conv (str):
str = re.sub ('#\'style *= #*"([^"])"', '#\'style = #\'\\1', str)
- str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?horizontalNoteShift"? *= *"?#?([0-9]+)"?', '\\\\property \\1.NoteColumn \\\\override #\'horizontal-shift = #\\2', 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 ('LyricVoice', 'LyricsVoice', str)
# old fix
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_assignment (match):
return '\n' + regularize_id (match.group (1)) + ' = '
str = re.sub ('\$([^\t\n ]+)', regularize_dollar_reference, str)
- str = re.sub ('\n([^ \t\n]+) = ', regularize_assignment, 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'))
if 1:
def conv (str):
str = re.sub ('followThread', 'followVoice', str)
+ str = re.sub ('Thread.FollowThread', 'Voice.VoiceFollower', str)
str = re.sub ('FollowThread', 'VoiceFollower', 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'))
+
+
+if 1:
+ def conv (str):
+ str = re.sub ('([A-Za-z]+)MinimumVerticalExtent', 'MinimumV@rticalExtent', str)
+ 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)
+ return str
+
+ conversions.append (((1,3,145), conv,
+ 'ContextNameXxxxVerticalExtent -> XxxxVerticalExtent'))
+
+if 1:
+ def conv (str):
+ str = re.sub ('\\\\key[ \t]*;', '\\key \\default;', str)
+ str = re.sub ('\\\\mark[ \t]*;', '\\mark \\default;', str)
+
+ # 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.
+ str = re.sub ("([^ \t;#]);", "\\1", str)
+
+ return str
+ conversions.append (((1,3,146), conv, 'semicolons removed'))
+
+if 1:
+ def conv (str):
+ str = re.sub ('default-neutral-direction', 'neutral-direction',str)
+ return str
+ conversions.append (((1,3,147), conv, 'default-neutral-direction -> neutral-direction'))
+
+if 1:
+ def conv (str):
+ str = re.sub ('\(align', '(axis', str)
+ str = re.sub ('\(rows', '(columns', str)
+ return str
+ conversions.append (((1,3,148), conv, '"(align" -> "(axis", "(rows" -> "(columns"'))
+
+
+
+################################
+# END OF CONVERSIONS
+################################
def get_conversions (from_version, to_version):
def version_b (v, f = from_version, t = to_version):
if last_conversion:
sys.stderr.write ('\n')
new_ver = '\\version \"%s\"' % tup_to_str (last_conversion)
- # JUNKME?
- # ugh: this all really doesn't help
- # esp. as current conversion rules are soo incomplete
+
if re.search (lilypond_version_re_str, str):
str = re.sub (lilypond_version_re_str,'\\'+new_ver , str)
- else:
+ elif add_version:
str = new_ver + '\n' + str
outfile.write(str)
outfile_name = ''
(options, files) = getopt.getopt (
- sys.argv[1:], 'ao:f:t:seh', ['assume-old', 'version', 'output', 'show-rules', 'help', 'edit', 'from=', 'to='])
+ sys.argv[1:], 'ao:f:t:senh', ['no-version', 'assume-old', 'version', 'output', 'show-rules', 'help', 'edit', 'from=', 'to='])
for opt in options:
o = opt[0]
outfile_name = a
elif o == '--assume-old' or o == '-a':
assume_old = 1
+ elif o == '--no-version' or o == '-n':
+ add_version = 0
else:
print o
raise getopt.error
for f in files:
if f == '-':
f = ''
+ if not os.path.isfile (f):
+ continue
try:
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: can't determine version for `%s'" % (program_name, f))
sys.stderr.write ('\n')
if assume_old:
fv = from_version
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')