+def brace_matcher (n):
+ # poor man's matched brace scanning, gives up
+ # after n+1 levels. Matches any string with balanced
+ # braces inside; add the outer braces yourself if needed.
+ # Nongreedy.
+ return r"[^{}]*?(?:{"*n+r"[^{}]*?"+r"}[^{}]*?)*?"*n
+
+matchstring = r'"(?:[^"\\]|\\.)*"'
+matcharg = (r"\s+(?:[$#]['`]?\s*(?:[a-zA-Z]\S*|" + matchstring + r"|\("
+ + paren_matcher(20) + r"\))|" + matchstring + r"|\\[a-z_A-Z]+)")
+matchmarkup = (r'(?:\\markup\s*(?:{' + brace_matcher (20) +r'}|' +
+ matchstring + r'|(?:\\[a-z_A-Z][a-z_A-Z-]*(?:' + matcharg +
+ r')*?\s*)*(?:' + matchstring + "|{" + brace_matcher (20) +
+ "}))|" + matchstring + ")")
+
+@rule((2, 15, 25), r"\(auto)?Footnote(Grob)? -> \footnote")
+def conv (str):
+ # The following replacement includes the final markup argument in
+ # the match in order to better avoid touching the equally named
+ # markup function. The other functions have unique names, so
+ # there is no point in including their last, possibly complex
+ # argument in the match.
+ str = re.sub (r"\\footnote(" + matcharg + (r")(\s*" + matchmarkup)*2 + ")",
+ r"\\footnote\2\1\3", str)
+ str = re.sub (r"\\footnoteGrob"+("(" + matcharg + ")")*2 + r"(\s*" + matchmarkup + ")",
+ r"\\footnote\3\2\1", str)
+ str = re.sub (r"\\autoFootnoteGrob" + ("(" + matcharg + ")")*2,
+ r"\\footnote\2\1", 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
+