X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fconvert-ly.py;h=daf03fd202736640032056a750e78ca53f2e6599;hb=d02fb0875e52111272553a47e657b6f58e136e22;hp=519be984fa76c457c7f6d6dd9fc58506f9bc38cc;hpb=789c6e6b0452e2201f299d893573b9ec8b960fe3;p=lilypond.git diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index 519be984fa..daf03fd202 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -1,9 +1,9 @@ #!@PYTHON@ # # convert-ly.py -- Update old LilyPond input files (fix name?) -# +# # source file of the GNU LilyPond music typesetter -# +# # (c) 1998--2003 Han-Wen Nienhuys # Jan Nieuwenhuizen @@ -41,7 +41,7 @@ def identify (): def usage (): sys.stdout.write ( - r"""Usage: %s [OPTIONS]... [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. @@ -517,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): @@ -632,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) @@ -640,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 ')) @@ -866,7 +866,7 @@ if 1: func, str) return str - # 40 ? + # 40 ? conversions.append (((1,5,40), conv, 'breakAlignOrder property names')) @@ -1008,7 +1008,7 @@ if 1: return "(make-span-event '%s %s)" % (mtype , stype) def subst_definition_ev_name(match): - return ' = #%s' % subst_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 @@ -1284,96 +1284,120 @@ if 1: last_str = '' while last_str <> str: - last_str = str - def sub_dyn_end (m): - dyns.append (' \!') - return ' ' + m.group(2) - - str = re.sub (r'(\\!)\s*([a-z]+)', sub_dyn_end, str) - def sub_slurs(m): - if '-)' not in slur_strs: - slur_strs.append ( ')') - return m.group(1) - def sub_p_slurs(m): - 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): - 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): - 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): - 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): - 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) - - def sub_pslurs(m): - slur_strs.append ( ' \\)') - return m.group(1) - str = re.sub (r"\\\)[ ]*([a-z]+)", sub_pslurs, str) - - suffix = string.join (slur_strs, '') + string.join (pslur_strs, '') \ + last_str = str + def sub_tremolos (m): + 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.append (' \!') + return ' ' + m.group(2) + + str = re.sub (r'(\\!)\s*([a-z]+)', sub_dyn_end, str) + def sub_slurs(m): + if '-)' not in slur_strs: + slur_strs.append (')') + return m.group(1) + + def sub_p_slurs(m): + 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): + 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): + 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): + 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): + 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) + + def sub_pslurs(m): + 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 = "<" + simstart = '<' chordstart = '<<' chordend = '>>' marker_str = '%% new-chords-done %%' if re.search (marker_str,str): return str - str= re.sub (r'\\<', '@STARTCRESC@', str) - str= re.sub (r'\\>', '@STARTDECRESC@', str) - str= re.sub (r'([_^-])>', r'\1@ACCENT@', str) - str = re.sub ('<([^<>{}]+)>', sub_chord, 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) + r'\1-[', str) str = re.sub (r'\\! *(@STARTCHORD@[^@]+@ENDCHORD@[0-9.]*)', - r'\1\\!', - str) - str = re.sub ('<([^?])', r'%s\1' % simstart, str) - str = re.sub ('>([^?])', r'%s\1' % simend, str) + 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 (r'\\context *Voice *@STARTCHORD@', + '@STARTCHORD@', str) str = re.sub ('@STARTCHORD@', chordstart, str) str = re.sub ('@ENDCHORD@', chordend, str) str = re.sub (r'@ACCENT@', '>', str) @@ -1381,7 +1405,7 @@ if 1: def articulation_substitute (str): str = re.sub (r"""([^-])\[ *([a-z]+[,']*[!?]?[0-9:]*\.*)""", - r" \1 \2[", str) + r"\1 \2[", str) str = re.sub (r"""([^-])\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""", r"\1 \2)", str) str = re.sub (r"""([^-])\\! *([a-z]+[,']*[!?]?[0-9:]*\.*)""", @@ -1405,19 +1429,229 @@ if 1: 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 - str = re.sub ('-\\markup', '@\\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 ('@\\markup', r'-\\markup', str) + \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) -conversions.append (((1,9,1), conv, """Remove - before articulation""")) + 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"\unset \property %s.melismaBusyProperties" % 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""")) + ################################ # END OF CONVERSIONS