X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=python%2Fconvertrules.py;h=da8b20fc9411c571e0a283305ba3cd2ab6b5ae07;hb=4ac94425bd4f31ef8148e49b83b0feec177bad36;hp=3ed1d18e00d3ab4756620aab7d43d3b3189a9bc5;hpb=252ec5e71b5e121734a9c9897245137cb07e4a1f;p=lilypond.git diff --git a/python/convertrules.py b/python/convertrules.py index 3ed1d18e00..da8b20fc94 100644 --- a/python/convertrules.py +++ b/python/convertrules.py @@ -3320,6 +3320,167 @@ def conv (str): str = re.sub (r"\\autoFootnote", r"\\footnote", str) return str + +@rule((2, 15, 32), r"tempoWholesPerMinute -> \tempo") +def conv (str): + def sub_tempo (m): + num = int (m.group (1)) + den = int (m.group (2)) + + if (den & (den - 1)) != 0 : + return m.group (0) + + # Don't try dotted forms if they result in less than 30 bpm. + # It is not actually relevant to get this right since this + # only occurs in non-printing situations + if den >= 16 and (num % 7) == 0 and num >= 210 : + return r"\tempo %d.. = %d" % (den/4, num/7) + + if den >= 8 and (num % 3) == 0 and num >= 90 : + return r"\tempo %d. = %d" % (den/2, num/3) + + return r"\tempo %d = %d" % (den, num) + + str = re.sub (r"\\context\s*@?\{\s*\\Score\s+tempoWholesPerMinute\s*=\s*" + + r"#\(ly:make-moment\s+([0-9]+)\s+([0-9]+)\)\s*@?\}", + sub_tempo, str) + return str + +@rule((2, 15, 39), r"\footnote ... -> \footnote ... \default") +def conv (str): + def not_first (s): + def match_fun (m): + if m.group (1): + return m.group (0) + return m.expand (s) + return match_fun + str = re.sub ("(" + matchmarkup + ")|" + + r"(\\footnote(?:\s*" + + matchmarkup + ")?" + matcharg + "(?:" + matcharg + + ")?\s+" + matchmarkup + ")", + not_first (r"\2 \\default"), str) + return str + +@rule ((2, 15, 40), r"Remove beamWholeMeasure") +def conv (str): + if re.search (r"\bbeamWholeMeasure\b", str): + stderr_write (NOT_SMART % "beamWholeMeasure") + stderr_write (_ ("beamExceptions controls whole-measure beaming.") + "\n") + return str + +@rule ((2, 15, 42), r"\set stringTuning -> \set Staff.stringTuning") +def conv (str): + str = re.sub (r"(\\set\s+)stringTuning", r"\1Staff.stringTuning", str) + return str + +wordsyntax = r"[a-zA-Z\200-\377](?:[-_]?[a-zA-Z\200-\377])*" + +@rule ((2, 15, 43), r'"custom-tuning" = -> custom-tuning =') +def conv (str): + str = re.sub ('\n"(' + wordsyntax + r')"(\s*=\s*\\stringTuning)', "\n\\1\\2", str) + return str + +@rule ((2, 16, 0), + _ ("bump version for release")) +def conv (str): + return str + +@rule ((2, 17, 0), r"blank-*-force -> blank-*-penalty") +def conv (str): + str = re.sub ('blank-page-force', 'blank-page-penalty', str) + str = re.sub ('blank-last-page-force', 'blank-last-page-penalty', str) + str = re.sub ('blank-after-score-page-force', 'blank-after-score-page-penalty', str) + return str + + +@rule ((2, 17, 4), r"\shape Grob #offsets -> \shape #offsets Grob") +def conv (str): + str = re.sub (r"\\shape(\s+(?:[a-zA-Z]+|" + matchstring + "))(" + + matcharg + ")", r"\\shape\2\1", str) + return str + +barstring=r"(\\bar|whichBar|defaultBarType|segnoType|doubleRepeatType|startRepeatType|endRepeatType|doubleRepeatSegnoType|startRepeatSegnoType|endRepeatSegnoType)(\s*[=]?\s*[#]?)" + +@rule ((2, 17, 5), r"New bar line interface") +def conv(str): + str = re.sub (barstring + r'"\|:"', '\\1\\2".|:"', str) + str = re.sub (barstring + r'":\|"', '\\1\\2":|."', str) + str = re.sub (barstring + r'"\|\|:"', '\\1\\2".|:-||"', str) + str = re.sub (barstring + r'":\|:"', '\\1\\2":..:"', str) + str = re.sub (barstring + r'"\.\|\."', '\\1\\2".."', str) + str = re.sub (barstring + r'"\|S"', '\\1\\2"S-|"', str) + str = re.sub (barstring + r'"S\|"', '\\1\\2"S-S"', str) + str = re.sub (barstring + r'":\|S"', '\\1\\2":|.S"', str) + str = re.sub (barstring + r'":\|S\."', '\\1\\2":|.S-S"', str) + str = re.sub (barstring + r'"S\|:"', '\\1\\2"S.|:-S"', str) + str = re.sub (barstring + r'"\.S\|:"', '\\1\\2"S.|:"', str) + str = re.sub (barstring + r'":\|S\|:"', '\\1\\2":|.S.|:"', str) + str = re.sub (barstring + r'":\|S\.\|:"', '\\1\\2":|.S.|:-S"', str) + str = re.sub (barstring + r'":"', '\\1\\2";"', str) + str = re.sub (barstring + r'"\|s"', '\\1\\2"|-s"', str) + str = re.sub (barstring + r'"dashed"', '\\1\\2"!"', str) + str = re.sub (barstring + r'"kievan"', '\\1\\2"k"', str) + str = re.sub (barstring + r'"empty"', '\\1\\2"-"', str) + return str + +symbol_list = (r"#'(?:" + wordsyntax + r"|\(\s*(?:" + wordsyntax + r"\s+)*" + + wordsyntax + r"\s*\))") + +grob_path = r"(?:" + symbol_list + r"\s+)*" + symbol_list + +grob_spec = wordsyntax + r"(?:\s*\.\s*" + wordsyntax + r")?" + +def path_replace (m): + return m.group (1) + string.join (re.findall (wordsyntax, m.group (2)), ".") + +@rule ((2, 17, 6), r"""\accidentalStyle #'Context "style" -> \accidentalStyle Context.style +\alterBroken "Context.grob" -> \alterBroken Context.grob +\overrideProperty "Context.grob" -> \overrideProperty Context.grob +\tweak Grob #'symbol -> \tweak Grob.symbol""") +def conv (str): + def patrep (m): + def fn_path_replace (m): + x = string.join (re.findall (wordsyntax, m.group (2)), ".") + if x in ["TimeSignature", "KeySignature", "BarLine", + "Clef", "StaffSymbol", "OttavaBracket", + "LedgerLineSpanner"]: + x = "Staff." + x + return m.group (1) + x + if m.group (1): + return m.group (0) + x = m.group (2) + m.group (4) + + if m.group (3): + x = x + re.sub (r"(\s*)(" + symbol_list + ")", fn_path_replace, + m.group (3)) + + if not m.group (5): + x = r"\single" + x + return x + + str = re.sub (r'''(\\accidentalStyle\s+)#?"([-A-Za-z]+)"''', + r"\1\2", str) + str = re.sub (r'''(\\accidentalStyle\s+)#'([A-Za-z]+)\s+#?"?([-A-Za-z]+)"?''', + r"\1\2.\3", str) + str = re.sub (r'''(\\(?:alterBroken|overrideProperty)\s+)#?"([A-Za-z]+)\s*\.\s*([A-Za-z]+)"''', + r"\1\2.\3", str) + str = re.sub (r'''(\\tweak\s+)#?"?([A-Za-z]+)"?\s+?#'([-A-Za-z]+)''', + r"\1\2.\3", str) + str = re.sub (r'''(\\tweak\s+)#'([-A-Za-z]+)''', + r"\1\2", str) + str = re.sub ("(" + matchmarkup + ")|" + + r"(\\footnote(?:\s*" + + matchmarkup + ")?" + matcharg + ")(" + matcharg + + r")?(\s+" + matchmarkup + r")(\s+\\default)?", + patrep, str) + str = re.sub (r'''(\\alterBroken)(\s+[A-Za-z.]+)(''' + matcharg + + matcharg + ")", r"\1\3\2", str) + str = re.sub (r"(\\overrideProperty\s+)(" + grob_spec + r"\s+" + grob_path + ")", + path_replace, str) + str = re.sub (r"(\\(?:override|revert)\s+)(" + grob_spec + r"\s+" + grob_path + ")", + path_replace, str) + return str + # Guidelines to write rules (please keep this at the end of this file) # # - keep at most one rule per version; if several conversions should be done,