X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fconvert-ly.py;h=07f0a387b3189d8c56345cb50eab038d427f98db;hb=402045837e7134cdf90d1fcf31768c62227a4936;hp=9d9d08e96df86b861d7454df6382eb7cb7139288;hpb=ed0b666b2bfca7e31c9a2639e436855bba59b884;p=lilypond.git diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index 9d9d08e96d..07f0a387b3 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -1,10 +1,12 @@ #!@PYTHON@ # -# convert-ly.py -- convertor for lilypond versions -# +# convert-ly.py -- Update old LilyPond input files (fix name?) +# # source file of the GNU LilyPond music typesetter -# -# (c) 1998--2001 +# +# (c) 1998--2004 Han-Wen Nienhuys +# Jan Nieuwenhuizen + # TODO # use -f and -t for -s output @@ -39,21 +41,20 @@ def identify (): def usage (): sys.stdout.write ( - r"""Usage: %s [OPTION]... [FILE]... + 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 +input is guessed by default from \version directive. Options: - -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. 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. + -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 +Report bugs to bugs-gnu-music@gnu.org. """ % program_name) @@ -516,7 +517,7 @@ if 1: str = re.sub (r"""\\key *([a-z]+) *;""", r"""\\key \1 \major;""",str); return str conversions.append (((1,3,59), conv, - '\key X ; -> \key X major; ')) + '\key X ; -> \key X major; ')) if 1: def conv (str): @@ -631,7 +632,7 @@ if 1: str = re.sub ('\\\\property *"?Voice"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Voice.TextScript \\\\set #\'font-style = #\'\\1', str) str = re.sub ('\\\\property *"?Lyrics"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Lyrics.LyricText \\\\set #\'font-style = #\'\\1', str) - str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?timeSignatureStyle"? *= *"([^"]*)"', '\\\\property \\1.TimeSignature \\\\override #\'style = #\'\\2', str) + str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?timeSignatureStyle"? *= *"([^"]*)"', '\\\\property \\1.TimeSignature \\\\override #\'style = #\'\\2', str) str = re.sub ('"?timeSignatureStyle"? *= *#?""', 'TimeSignature \\\\override #\'style = ##f', str) @@ -639,12 +640,12 @@ if 1: 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 ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *"([^"]*)"', '\\\\property \\1.Stem \\\\override #\'flag-style = #\'\\2', 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 ')) @@ -865,7 +866,7 @@ if 1: func, str) return str - # 40 ? + # 40 ? conversions.append (((1,5,40), conv, 'breakAlignOrder property names')) @@ -904,11 +905,13 @@ if 1: if 1: def conv (str): - str = re.sub ('MinimumVerticalExtent', 'MinimumV@rticalExtent', str) - str = re.sub ('ExtraVerticalExtent', 'ExtraV@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 ('VerticalExtent', 'verticalExtent', str) - str = re.sub ('ExtraV@rticalExtent', 'extraVerticalExtent', str) - str = re.sub ('MinimumV@rticalExtent', 'minimumVerticalExtent', str) + str = re.sub ('extraV@rticalExtent', 'extraVerticalExtent', str) + str = re.sub ('minimumV@rticalExtent', 'minimumVerticalExtent', str) return str conversions.append (((1,5,59), conv, @@ -936,8 +939,8 @@ if 1: if 1: def conv (str): - str = re.sub ('ly-set-grob-property', 'ly-set-grob-property!', str) - str = re.sub ('ly-set-mus-property', 'ly-set-mus-property!', 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) return str conversions.append (((1,5,68), conv, 'ly-set-X-property -> ly-set-X-property!')) @@ -951,6 +954,926 @@ if 1: conversions.append (((1,5,71), conv, 'extent-[XY] -> [XY]-extent')) +if 1: + def conv (str): + str = re.sub ("""#\(set! +point-and-click +line-column-location\)""", + """#(set-point-and-click! \'line-column)""", str) + str = re.sub ("""#\(set![ \t]+point-and-click +line-location\)""", + '#(set-point-and-click! \'line)', str) + 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!')) + + +if 1: + def conv (str): + str = re.sub ('flag-style', 'stroke-style', str) + 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')) + + +if 1: + def subst_req_name (match): + return "(make-music-by-name \'%sEvent)" % regularize_id (match.group(1)) + + def conv (str): + 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')) + + +if 1: + spanner_subst ={ + "text" : 'TextSpanEvent', + "decrescendo" : 'DecrescendoEvent', + "crescendo" : 'CrescendoEvent', + "Sustain" : 'SustainPedalEvent', + "slur" : 'SlurEvent', + "UnaCorda" : 'UnaCordaEvent', + "Sostenuto" : 'SostenutoEvent', + } + def subst_ev_name (match): + stype = 'STOP' + if re.search ('start', match.group(1)): + stype= 'START' + + mtype = spanner_subst[match.group(2)] + return "(make-span-event '%s %s)" % (mtype , stype) + + def subst_definition_ev_name(match): + return ' = #%s' % subst_ev_name (match) + def subst_inline_ev_name (match): + s = subst_ev_name (match) + return '#(ly-export %s)' % s + def subst_csp_definition (match): + 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) + str = re.sub (r' *= *\\commandspanrequest *([^ ]+) *"([^"]+)"', subst_csp_definition, str) + str = re.sub (r'\\commandspanrequest *([^ ]+) *"([^"]+)"', subst_csp_inline, str) + str = re.sub (r'ly-id ', 'ly-import ', str) + + str = re.sub (r' *= *\\script "([^"]+)"', ' = #(make-articulation "\\1")', str) + str = re.sub (r'\\script "([^"]+)"', '#(ly-export (make-articulation "\\1"))', str) + return str + + conversions.append (((1,7,2), conv, '\\spanrequest -> #(make-span-event .. ), \script -> #(make-articulation .. )')) + +if 1: + def conv(str): + str = re.sub (r'\(ly-', '(ly:', str) + + changed = [ + r'duration\?', + r'font-metric\?', + r'molecule\?', + r'moment\?', + r'music\?', + r'pitch\?', + 'make-duration', + 'music-duration-length', + 'duration-log', + 'duration-dotcount', + 'intlog2', + 'duration-factor', + 'transpose-key-alist', + 'get-system', + 'get-broken-into', + 'get-original', + 'set-point-and-click!', + 'make-moment', + 'make-pitch', + 'pitch-octave', + 'pitch-alteration', + 'pitch-notename', + 'pitch-semitones', + r'pitch<\?', + r'dir\?', + 'music-duration-compress', + 'set-point-and-click!' + ] + + 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: + def conv(str): + str = re.sub (r"\\transpose", r"\\transpose c'", str) + str = re.sub (r"\\transpose c' *([a-z]+)'", r"\\transpose c \1", str) + return str + conversions.append (((1,7,5), conv, '\\transpose TO -> \\transpose FROM TO')) + +if 1: + def conv(str): + kws = ['arpeggio', + 'sustainDown', + 'sustainUp', + 'f', + 'p', + 'pp', + 'ppp', + 'fp', + 'ff', + 'mf', + 'mp', + 'sfz', + ] + + origstr = string.join (kws, '|') + str = re.sub (r'([^_^-])\\(%s)\b' % origstr, r'\1-\\\2', str) + return str + conversions.append (((1,7,6), conv, 'note\\script -> note-\script')) + + +if 1: + def conv(str): + str = re.sub (r"\\property *ChordNames *\. *ChordName *\\(set|override) *#'style *= *#('[a-z]+)", + r"#(set-chord-name-style \2)", str) + str = re.sub (r"\\property *ChordNames *\. *ChordName *\\revert *#'style", + 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")) + +if 1: + def conv(str): + str = re.sub (r"ly:get-molecule-extent", "ly:molecule-get-extent", str) + str = re.sub (r"ly:set-molecule-extent!", "ly:molecule-set-extent!", str) + 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")) + +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")) + +if 1: + def conv(str): + str = re.sub ("divisiomaior", + "divisioMaior", str) + str = re.sub ("divisiominima", + "divisioMinima", str) + str = re.sub ("divisiomaxima", + "divisioMaxima", str) + return str + + conversions.append (((1,7,16), conv, "divisiomaior -> divisioMaior")) + +if 1: + def conv(str): + 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: + def conv(str): + str = re.sub ("groupOpen", + "startGroup", str) + str = re.sub ("groupClose", + "stopGroup", str) + str = re.sub ("#'outer", + "#'enclose-bounds", str) + + return str + + conversions.append (((1,7,18), conv, + """groupOpen/Close -> start/stopGroup, + #'outer -> #'enclose-bounds + """)) + +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 .. )") + raise FatalConversionError() + + str = re.sub ('HaraKiriStaffContext', 'RemoveEmptyStaffContext', str) + return str + + conversions.append (((1,7,19), conv,"remove GraceContext")) + + + +if 1: + def conv(str): + str = re.sub ( + r"(set|override|revert) *#'type", + r"\1 #'style", + str) + return str + + conversions.append (((1,7,22), conv,"#'type -> #'style")) + +if 1: + def conv(str): + str = re.sub ( + "barNonAuto *= *##t", + "automaticBars = ##f", + str) + str = re.sub ( + "barNonAuto *= *##f", + "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. +""") + + raise FatalConversionError() + + return str + + conversions.append (((1,7,24), conv,"cluster syntax")) + +if 1: + def conv(str): + str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\(override|set) *#'pedal-type *", + 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")) + + + +if 1: + + def sub_chord (m): + str = m.group(1) + + origstr = '<%s>' % str + if re.search (r'\\\\', str): + return origstr + + if re.search (r'\\property', str): + return origstr + + if re.match (r'^\s*\)?\s*\\[a-zA-Z]+', str): + return origstr + + durs = [] + def sub_durs (m, durs = durs): + durs.append(m.group(2)) + return m.group (1) + + str = re.sub (r"([a-z]+[,'!? ]*)([0-9]+\.*)", sub_durs, str) + dur_str = '' + + for d in durs: + if dur_str == '': + dur_str = d + if dur_str <> d: + return '<%s>' % m.group (1) + + pslur_strs = [''] + dyns = [''] + slur_strs = [''] + + last_str = '' + while last_str <> str: + last_str = str + + def sub_tremolos (m, slur_strs = slur_strs): + tr = m.group (2) + 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) + + def sub_dyn_end (m, dyns = dyns): + dyns.append (' \!') + return ' ' + m.group(2) + + str = re.sub (r'(\\!)\s*([a-z]+)', sub_dyn_end, str) + def sub_slurs(m, slur_strs = slur_strs): + 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): + if '-\(' not in slur_strs: + slur_strs.append ('\(') + return m.group(1) + + str = re.sub (r"([a-z]+[,'!?0-9 ]*)\\\(", + sub_begin_p_slurs, str) + + def sub_dyns (m, slur_strs = slur_strs): + s = m.group(0) + if s == '@STARTCRESC@': + slur_strs.append ("\\<") + elif s == '@STARTDECRESC@': + slur_strs.append ("\\>") + elif s == r'-?\\!': + slur_strs.append ('\\!') + return '' + + str = re.sub (r'@STARTCRESC@', sub_dyns, str) + str = re.sub (r'-?\\!', sub_dyns, str) + + def sub_articulations (m, slur_strs = slur_strs): + a = m.group(1) + if a not in slur_strs: + slur_strs.append (a) + return '' + + str = re.sub (r"([_^-]\@ACCENT\@)", sub_articulations, + str) + str = re.sub (r"([_^-]\\[a-z]+)", sub_articulations, + str) + str = re.sub (r"([_^-][>_.+|^-])", sub_articulations, + str) + str = re.sub (r'([_^-]"[^"]+")', sub_articulations, + str) + + def sub_pslurs(m, slur_strs = slur_strs): + slur_strs.append (' \\)') + return m.group(1) + str = re.sub (r"\\\)[ ]*([a-z]+)", sub_pslurs, str) + + ## end of while <> + + suffix = string.join (slur_strs, '') + string.join (pslur_strs, + '') \ + + string.join (dyns, '') + + return '@STARTCHORD@%s@ENDCHORD@%s%s' % (str , dur_str, suffix) + + + + def sub_chords (str): + simend = '>' + simstart = '<' + chordstart = '<<' + chordend = '>>' + marker_str = '%% new-chords-done %%' + + if re.search (marker_str,str): + 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) + str = re.sub (r'<([^<>{}]+)>', sub_chord, str) + + # add dash: -[, so that [<> c d] becomes + # <>-[ c d] + # and gets skipped by articulation_substitute + str = re.sub (r'\[ *(@STARTCHORD@[^@]+@ENDCHORD@[0-9.]*)', + 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) + str = re.sub ('@STARTDECRESC@', r'\\>' ,str) + str = re.sub (r'\\context *Voice *@STARTCHORD@', + '@STARTCHORD@', str) + str = re.sub ('@STARTCHORD@', chordstart, str) + str = re.sub ('@ENDCHORD@', chordend, str) + str = re.sub (r'@ACCENT@', '>', str) + return str + + def articulation_substitute (str): + str = re.sub (r"""([^-])\[ *([a-z]+[,']*[!?]?[0-9:]*\.*)""", + r"\1 \2[", str) + str = re.sub (r"""([^-])\\\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""", + r"\1 \2\\)", str) + str = re.sub (r"""([^-\\])\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""", + r"\1 \2)", str) + 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 = conv_relative (str) + str = sub_chords (str) + + str = articulation_substitute (str) + + return str + + conversions.append (((1,9,0), conv, """New relative mode, +Postfix articulations, new chord syntax.""")) + +if 1: + def conv (str): + if re.search ("font-style",str): + sys.stderr.write ("font-style is deprecated. Please remove.") + raise FatalConversionError() + + str = re.sub (r'-\\markup', r'@\\markup', str) + str = re.sub (r'-\\', r'\\', str) + str = re.sub (r'-\)', ')', str) + str = re.sub (r'-\(', '(', str) + str = re.sub ('-\[', '[', str) + str = re.sub ('-\]', ']', str) + str = re.sub ('-~', '~', str) + str = re.sub (r'@\\markup', r'-\\markup', str) + return str + + conversions.append (((1,9,1), conv, """Remove - before articulation""")) +if 1: + def conv (str): + str = re.sub ('ly:set-context-property', + 'ly:set-context-property!', str) + str = re.sub ('\\\\newcontext', '\\\\new', str) + str = re.sub ('\\\\grace[\t\n ]*([^{ ]+)', + r'\\grace { \1 }', str) + str = re.sub ("\\\\grace[\t\n ]*{([^}]+)}", + r"""\\grace { + \\property Voice.Stem \\override #'stroke-style = #"grace" + \1 + \\property Voice.Stem \\revert #'stroke-style } +""", str) + + return str + + conversions.append (((1,9,2), conv, """\newcontext -> \new""")) + +if 1: + def conv (str): + str = re.sub ('accacciatura', + '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.") + + 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""")) + + +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) + str = re.sub (r'([-^_])>', r'\1@ACCENT@', str) + str = re.sub (r'<<', '@STARTCHORD@', str) + str = re.sub (r'>>', '@ENDCHORD@', str) + str = re.sub (r'>', '@ENDSIMUL@', str) + str = re.sub (r'<', '@STARTSIMUL@', str) + str = re.sub ('@STARTDECRESC@', '\\>', str) + str = re.sub ('@STARTCRESC@', '\\<', str) + str = re.sub ('@ACCENT@', '>', str) + str = re.sub ('@ENDCHORD@', '>', str) + str = re.sub ('@STARTCHORD@', '<', str) + str = re.sub ('@STARTSIMUL@', '<<', str) + str = re.sub ('@ENDSIMUL@', '>>', str) + str = re.sub ('@FIGOPEN@', '<', str) + str = re.sub ('@FIGCLOSE@', '>', str) + + return str + +conversions.append (((1,9,4), conv, 'Swap < > and << >>')) + + +def conv (str): + str = re.sub ('HaraKiriVerticalGroup', 'RemoveEmptyVerticalGroup', str) + + return str + +conversions.append (((1,9,5), conv, 'HaraKiriVerticalGroup -> RemoveEmptyVerticalGroup')) + +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.") + + raise FatalConversionError() + + if re.search ("\\pitch *#", str) : + sys.stderr.write (r"\\pitch has been deprecated. " +\ + " Use Scheme code to construct arbitrary note events.") + + raise FatalConversionError() + + return str + + +conversions.append (((1,9,6), conv, 'ly:get-font deprecated.')) + +def conv (str): + def sub_alteration (m): + alt = m.group (3) + alt = { + '-1': 'FLAT', + '-2': 'DOUBLE-FLAT', + '0': 'NATURAL', + '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) + + + str = re.sub ("ly:verbose", "ly:get-option 'verbose", str) + + m= re.search ("\\\\outputproperty #([^#]+)[\t\n ]*#'([^ ]+)", str) + if m: + sys.stderr.write (\ + r"""\outputproperty found, +Please hand-edit, using + + \applyoutput #(outputproperty-compatibility %s '%s ) + +as a substitution text.""" % (m.group (1), m.group (2)) ) + raise FatalConversionError () + + if re.search ("ly:(make-pitch|pitch-alteration)", str) \ + or re.search ("keySignature", str): + 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: + +* 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, +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.""") + raise FatalConversionError() + return str + +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))) + + 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""")) + +def conv (str): + str =re.sub (r"ly:get-music-length", "ly:music-length", str) + return str + +conversions.append (((2,1,2), conv, """ly:get-music-length -> ly:music-length""")) + +def conv (str): + str =re.sub (r"\.\s+stz=", ". instr ", str) + return str + +conversions.append (((2,1,3), conv, """stanza -> instrument""")) + +def conv (str): + def func (match): + c = match.group (1) + b = match.group (2) + + if b == 't': + if c == 'Score': + return '' + else: + 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) + return str + +conversions.append (((2,1,4), conv, """removal of automaticMelismata; use melismaBusyProperties instead.""")) + + + +def conv (str): + str =re.sub (r"\\translator\s+([a-zA-Z]+)", r"\\change \1", str) + return str + +conversions.append (((2,1,7), conv, """\\translator Staff -> \\change Staff""")) + +def conv (str): + str =re.sub (r"\\newaddlyrics", r"\\lyricsto", str) + return str + +conversions.append (((2,1,10), conv, """\\newaddlyrics -> \\lyricsto""")) + +def conv (str): + str = re.sub (r'\\include\s*"paper([0-9]+)(-init)?.ly"', + r"#(set-staff-size \1)", str) + + def sub_note (match): + dur = '' + log = string.atoi (match.group (1)) + dots = string.atoi (match.group (2)) + + if log >= 0: + dur = '%d' % (1 << log) + else: + dur = { -1 : 'breve', + -2 : 'longa', + -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 + +conversions.append (((2,1,11), conv, """\\include "paper16.ly" -> #(set-staff-size 16) +\note #3 #1 #1 -> \note #"8." #1 +""")) + + +def conv (str): + str =re.sub (r"OttavaSpanner", r"OttavaBracket", str) + return str + +conversions.append (((2,1,12), conv, """OttavaSpanner -> OttavaBracket""")) + + +def conv (str): + str =re.sub (r"\(set-staff-size ", r"(set-global-staff-size ", str) + return str + +conversions.append (((2,1,13), conv, """set-staff-size -> set-global-staff-size""")) + +def conv (str): + str =re.sub (r"#'style\s*=\s*#'dotted-line", + r"#'dash-fraction = #0.0 ", str) + return str + +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 + +conversions.append (((2,1,15), conv, """LyricsVoice . instr(ument) -> vocalName""")) + +def conv (str): + def sub_acc (m): + d = { + '4': 'doublesharp', + '3': 'threeqsharp', + '2': 'sharp', + '1': 'semisharp', + '0': 'natural', + '-1': 'semiflat', + '-2': 'flat', + '-3': 'threeqflat', + '-4': 'doubleflat'} + return '\\%s' % d[m.group (1)] + + str = re.sub (r'\\musicglyph\s*#"accidentals-([0-9-]+)"', + sub_acc, str) + return str + +conversions.append (((2,1,16), conv, """\\musicglyph #"accidentals-NUM" -> \\sharp/flat/etc.""")) + + +def conv (str): + + if re.search (r'\\partcombine', str): + sys.stderr.write ('Warning: \\partcombine has been changed. ' + +'Check conversion manually!') + + raise FatalConversionError() + + # this rule doesn't really work, + # too lazy to figure out why. + 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""")) + + +def conv (str): + str = re.sub (r'\\newpartcombine', r'\\partcombine', str) + str = re.sub (r'\\autochange\s+Staff', r'\\autochange ', str) + return str + +conversions.append (((2,1,18), conv, """\\newpartcombine -> \\partcombine, +\\autochange Staff -> \\autochange +""")) + + + + +def conv (str): + str = re.sub (r'\\include "drumpitch-init.ly"','', str) + str = re.sub (r'\\pitchnames ','pitchnames = ', 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) + + if re.search ('Thread', str): + sys.stderr.write ("\nThread found. Check file manually!\n"); + + 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"""<\3\\harmonic>\4""", str) + + str = re.sub (r"""\\new Thread""", """\context Voice""", str) + str = re.sub (r"""Thread""", """Voice""", str) + + if re.search ('\bLyrics\b', str): + sys.stderr.write ("\nLyrics found. Check file manually!\n"); + + str = re.sub (r"""LyricsVoice""", r"""L@ricsVoice""", 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. +Harmonic notes. Thread context removed. Lyrics context removed.""")) + +def conv (str): + str = re.sub (r'nonevent-skip', 'skip-music', str) + return str + +conversions.append (((2,1,20), conv, """nonevent-skip -> skip-music""" )) + +def conv (str): + str = re.sub (r'molecule-callback', 'print-function', str) + str = re.sub (r'brew_molecule', 'print', str) + str = re.sub (r'brew-new-markup-molecule', 'Text_item::print', str) + str = re.sub (r'LyricsVoice', 'Lyrics', str) + str = re.sub (r'tupletInvisible', + r"TupletBracket \\set #'transparent", str) +# str = re.sub (r'molecule', 'collage', str) +#molecule -> collage + str = re.sub (r"\\property\s+[a-zA-Z]+\s*\.\s*[a-zA-Z]+\s*" + + r"\\set\s*#'X-extent-callback\s*=\s*#Grob::preset_extent", + "", str) + + return str + +conversions.append (((2,1,21), conv, """molecule-callback -> print-function, +brew_molecule -> print +brew-new-markup-molecule -> Text_item::print +LyricsVoice -> Lyrics +tupletInvisible -> TupletBracket \set #'transparent +Grob::preset_extent removed. +""" )) + + +def conv (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*=', + r'\\s@t \1.\2 = ', str) + str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*\\unset', + r'\\uns@t \1.\2 ', str) + str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*\\revert' + + r"\s*#'([-a-z0-9_]+)", + r"\\rev@rt \1.\2 #'\3", 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) + + str = re.sub ('molecule', 'stencil', str) + str = re.sub ('Molecule', 'Stencil', str) + return str + +conversions.append (((2,1,22), conv, """new syntax for property settings: + \set A.B = #C , \unset A.B + \override A.B #C = #D, \revert A.B #C + +""")) + + ################################ # END OF CONVERSIONS ################################ @@ -1053,7 +1976,7 @@ from_version = () outfile_name = '' (options, files) = getopt.getopt ( - sys.argv[1:], 'ao:f:t:senh', ['no-version', 'assume-old', 'version', 'output', 'show-rules', 'help', 'edit', 'from=', 'to=']) + sys.argv[1:], 'ao:f:t:senh', ['no-version', 'version', 'output', 'show-rules', 'help', 'edit', 'from=', 'to=']) for opt in options: o = opt[0] @@ -1075,8 +1998,6 @@ for opt in options: sys.exit(0) elif o == '--output' or o == '-o': outfile_name = a - elif o == '--assume-old' or o == '-a': - assume_old = 1 elif o == '--no-version' or o == '-n': add_version = 0 else: @@ -1087,7 +2008,7 @@ identify () for f in files: if f == '-': f = '' - if not os.path.isfile (f): + elif not os.path.isfile (f): continue try: do_one_file (f) @@ -1103,4 +2024,5 @@ for f in files: else: sys.stderr.write ("%s: skipping: `%s' " % (program_name, f)) pass + sys.stderr.write ('\n')