X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=python%2Fconvertrules.py;h=ec8bd266ef7cfc2c2307d430548cb271e09de037;hb=refs%2Fheads%2Fupstream-mut;hp=fb62f925412d80ccaa8aa3d2573de73b5b6e72b4;hpb=1dff29aea8a32c30f7fcfadf8a00afa0371dbf7a;p=lilypond.git diff --git a/python/convertrules.py b/python/convertrules.py index fb62f92541..ec8bd266ef 100644 --- a/python/convertrules.py +++ b/python/convertrules.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # (setq py-indent-offset 4) @@ -9,9 +10,9 @@ import lilylib _ = lilylib._ -NOT_SMART = _ ("Not smart enough to convert %s") -UPDATE_MANUALLY = _ ("Please refer to the manual for details, and update manually.") -FROM_TO = _ ( "%s has been replaced by %s") +NOT_SMART = "\n" + _ ("Not smart enough to convert %s.") + "\n" +UPDATE_MANUALLY = _ ("Please refer to the manual for details, and update manually.") + "\n" +FROM_TO = _ ("%s has been replaced by %s") + "\n" class FatalConversionError: @@ -49,28 +50,23 @@ def rule (version, message): @rule ((0, 1, 9), _ ('\\header { key = concat + with + operator }')) def conv(str): if re.search ('\\\\multi', str): - stderr_write ('\n') - stderr_write (NOT_SMART % "\\multi") - stderr_write ('\n') + stderr_write (NOT_SMART % "\\multi") return str @rule ((0, 1, 19), _ ('deprecated %s') % '\\octave') def conv (str): if re.search ('\\\\octave', str): - stderr_write ('\n') - stderr_write (NOT_SMART % "\\octave") - stderr_write ('\n') - stderr_write (UPDATE_MANUALLY) - stderr_write ('\n') - # raise FatalConversionError () + stderr_write (NOT_SMART % "\\octave") + stderr_write (UPDATE_MANUALLY) + # raise FatalConversionError () return str @rule ((0, 1, 20), _ ('deprecated \\textstyle, new \\key syntax')) def conv (str): str = re.sub ('\\\\textstyle([^;]+);', - '\\\\property Lyrics . textstyle = \\1', str) + '\\\\property Lyrics . textstyle = \\1', str) # harmful to current .lys # str = re.sub ('\\\\key([^;]+);', '\\\\accidentals \\1;', str) return str @@ -99,9 +95,7 @@ def conv (str): @rule ((1, 0, 2), _ ('\\header { key = concat + with + operator }')) def conv(str): if re.search ('\\\\header', str): - stderr_write ('\n') - stderr_write (NOT_SMART % _ ("new \\header format")) - stderr_write ('\n') + stderr_write (NOT_SMART % _ ("new \\header format")) return str @@ -128,10 +122,8 @@ def conv(str): @rule ((1, 0, 6), 'foo = \\translator {\\type .. } ->\\translator {\\type ..; foo; }') def conv(str): if re.search ('[a-zA-Z]+ = *\\translator',str): - stderr_write ('\n') - stderr_write (NOT_SMART % _ ("\\translator syntax")) - stderr_write ('\n') - # raise FatalConversionError () + stderr_write (NOT_SMART % _ ("\\translator syntax")) + # raise FatalConversionError () return str @@ -184,10 +176,8 @@ def conv(str): @rule ((1, 0, 18), _ ('\\repeat NUM Music Alternative -> \\repeat FOLDSTR Music Alternative')) def conv(str): if re.search ('\\\\repeat',str): - stderr_write ('\n') - stderr_write (NOT_SMART % "\\repeat") - stderr_write ('\n') - # raise FatalConversionError () + stderr_write (NOT_SMART % "\\repeat") + # raise FatalConversionError () return str @@ -266,65 +256,61 @@ def conv(str): @rule ((1, 3, 5), 'beamAuto moment properties') def conv (str): str = re.sub ('"?beamAuto([^"=]+)"? *= *"([0-9]+)/([0-9]+)" *;*', - 'beamAuto\\1 = #(make-moment \\2 \\3)', - str) + 'beamAuto\\1 = #(make-moment \\2 \\3)', + str) return str @rule ((1, 3, 17), 'stemStyle -> flagStyle') def conv (str): str = re.sub ('stemStyle', - 'flagStyle', - str) + 'flagStyle', + str) return str @rule ((1, 3, 18), 'staffLineLeading -> staffSpace') def conv (str): str = re.sub ('staffLineLeading', - 'staffSpace', - str) + 'staffSpace', + str) return str @rule ((1, 3, 23), _ ('deprecate %s ') % '\\repetitions') def conv(str): if re.search ('\\\\repetitions',str): - stderr_write ('\n') - stderr_write (NOT_SMART % "\\repetitions") - stderr_write ('\n') - # raise FatalConversionError () + stderr_write (NOT_SMART % "\\repetitions") + # raise FatalConversionError () return str @rule ((1, 3, 35), 'textEmptyDimension -> textNonEmpty') def conv (str): str = re.sub ('textEmptyDimension *= *##t', - 'textNonEmpty = ##f', - str) + 'textNonEmpty = ##f', + str) str = re.sub ('textEmptyDimension *= *##f', - 'textNonEmpty = ##t', - str) + 'textNonEmpty = ##t', + str) return str @rule ((1, 3, 38), '\musicalpitch { a b c } -> #\'(a b c)') def conv (str): str = re.sub ("([a-z]+)[ \t]*=[ \t]*\\\\musicalpitch *{([- 0-9]+)} *\n", - "(\\1 . (\\2))\n", str) + "(\\1 . (\\2))\n", str) str = re.sub ("\\\\musicalpitch *{([0-9 -]+)}", - "\\\\musicalpitch #'(\\1)", str) + "\\\\musicalpitch #'(\\1)", str) if re.search ('\\\\notenames',str): - stderr_write ('\n') - stderr_write (NOT_SMART % _ ("new \\notenames format")) - stderr_write ('\n') + stderr_write (NOT_SMART % _ ("new \\notenames format")) return str @rule ((1, 3, 39), '\\key A ; ->\\key a;') def conv (str): def replace (match): - return '\\key %s;' % match.group (1).lower () + return '\\key %s;' % match.group (1).lower () str = re.sub ("\\\\key ([^;]+);", replace, str) return str @@ -333,9 +319,7 @@ def conv (str): @rule ((1, 3, 41), '[:16 c4 d4 ] -> \\repeat "tremolo" 2 { c16 d16 }') def conv (str): if re.search ('\\[:',str): - stderr_write ('\n') - stderr_write (NOT_SMART % _ ("new tremolo format")) - stderr_write ('\n') + stderr_write (NOT_SMART % _ ("new tremolo format")) return str @@ -354,9 +338,7 @@ def conv (str): @rule ((1, 3, 58), 'noteHeadStyle value: string -> symbol') def conv (str): if re.search ('\\\\keysignature', str): - stderr_write ('\n') - stderr_write (NOT_SMART % '\\keysignature') - stderr_write ('\n') + stderr_write (NOT_SMART % '\\keysignature') return str @@ -369,12 +351,12 @@ def conv (str): @rule ((1, 3, 68), 'latexheaders = "\\input global" -> latexheaders = "global"') def conv (str): str = re.sub (r'latexheaders *= *"\\\\input ', - 'latexheaders = "', - str) + 'latexheaders = "', + str) return str -# TODO: lots of other syntax change should be done here as well +# TODO: lots of other syntax changes should be done here as well @rule ((1, 3, 92), 'basicXXXProperties -> XXX, Repeat_engraver -> Volta_engraver') def conv (str): str = re.sub ('basicCollisionProperties', 'NoteCollision', str) @@ -392,7 +374,7 @@ def conv (str): return str -@rule ((1, 3, 93), _ ('change property definiton case (eg. onevoice -> oneVoice)')) +@rule ((1, 3, 93), _ ('change property definition case (eg. onevoice -> oneVoice)')) def conv (str): # Ugh, but meaning of \stemup changed too # maybe we should do \stemup -> \stemUp\slurUp\tieUp ? @@ -418,7 +400,7 @@ def conv (str): str = re.sub ('\\\\voicefour', '\\\\voiceFour', str) # I don't know exactly when these happened... - # ugh, we loose context setting here... + # ugh, we lose context setting here... 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) @@ -431,7 +413,7 @@ def conv (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) + # (lacks capitalization 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) @@ -453,9 +435,7 @@ def conv (str): def conv (str): str = re.sub ('ChordNames*', 'ChordNames', str) if re.search ('\\\\textscript "[^"]* *"[^"]*"', str): - stderr_write ('\n') - stderr_write (NOT_SMART % _ ("new \\textscript markup text")) - stderr_write ('\n') + stderr_write (NOT_SMART % _ ("new \\textscript markup text")) str = re.sub ('\\textscript +("[^"]*")', '\\textscript #\\1', str) return str @@ -530,9 +510,9 @@ def regularize_id (str): @rule ((1, 3, 117), _ ('identifier names: %s') % '$!foo_bar_123 -> xfooBarABC') def conv (str): def regularize_dollar_reference (match): - return regularize_id (match.group (1)) + return regularize_id (match.group (1)) def regularize_assignment (match): - return '\n' + regularize_id (match.group (1)) + ' = ' + return '\n' + regularize_id (match.group (1)) + ' = ' str = re.sub ('\$([^\t\n ]+)', regularize_dollar_reference, str) str = re.sub ('\n([^ \t\n]+)[ \t]*= *', regularize_assignment, str) return str @@ -541,7 +521,7 @@ def conv (str): @rule ((1, 3, 120), 'paper_xxx -> paperXxxx, pedalup -> pedalUp.') def conv (str): def regularize_paper (match): - return regularize_id (match.group (1)) + return regularize_id (match.group (1)) str = re.sub ('(paper_[a-z]+)', regularize_paper, str) str = re.sub ('sustainup', 'sustainUp', str) str = re.sub ('nobreak', 'noBreak', str) @@ -655,24 +635,24 @@ def conv (str): def conv (str): def func(match): - break_dict = { - "Instrument_name": "instrument-name", - "Left_edge_item": "left-edge", - "Span_bar": "span-bar", - "Breathing_sign": "breathing-sign", - "Staff_bar": "staff-bar", - "Clef_item": "clef", - "Key_item": "key-signature", - "Time_signature": "time-signature", - "Custos": "custos" - } - props = match.group (1) - for (k,v) in break_dict.items(): - props = re.sub (k, v, props) - return "breakAlignOrder = #'(%s)" % props + break_dict = { + "Instrument_name": "instrument-name", + "Left_edge_item": "left-edge", + "Span_bar": "span-bar", + "Breathing_sign": "breathing-sign", + "Staff_bar": "staff-bar", + "Clef_item": "clef", + "Key_item": "key-signature", + "Time_signature": "time-signature", + "Custos": "custos" + } + props = match.group (1) + for (k,v) in break_dict.items(): + props = re.sub (k, v, props) + return "breakAlignOrder = #'(%s)" % props str = re.sub ("breakAlignOrder *= *#'\\(([a-z_\n\tA-Z ]+)\\)", - func, str) + func, str) return str @@ -724,11 +704,11 @@ def conv (str): @rule ((1, 5, 67), _ ('automaticMelismata turned on by default')) def conv (str): if re.search (r'\addlyrics',str) \ - and re.search ('automaticMelismata', str) == None: - stderr_write ('\n') - stderr_write (NOT_SMART % "automaticMelismata; turned on by default since 1.5.67.") - stderr_write ('\n') - raise FatalConversionError () + and re.search ('automaticMelismata', str) == None: + stderr_write (NOT_SMART % "automaticMelismata") + stderr_write (_ ("automaticMelismata is turned on by default since 1.5.67.")) + stderr_write ('\n') + raise FatalConversionError () return str @@ -749,11 +729,11 @@ def conv (str): @rule ((1, 5, 72), 'set! point-and-click -> set-point-and-click!') def conv (str): str = re.sub ("""#\(set! +point-and-click +line-column-location\)""", - """#(set-point-and-click! \'line-column)""", str) + """#(set-point-and-click! \'line-column)""", str) str = re.sub ("""#\(set![ \t]+point-and-click +line-location\)""", - '#(set-point-and-click! \'line)', str) + '#(set-point-and-click! \'line)', str) str = re.sub ('#\(set! +point-and-click +#f\)', - '#(set-point-and-click! \'none)', str) + '#(set-point-and-click! \'none)', str) return str @@ -777,19 +757,19 @@ def conv (str): spanner_subst ={ - "text" : 'TextSpanEvent', - "decrescendo" : 'DecrescendoEvent', - "crescendo" : 'CrescendoEvent', - "Sustain" : 'SustainPedalEvent', - "slur" : 'SlurEvent', - "UnaCorda" : 'UnaCordaEvent', - "Sostenuto" : 'SostenutoEvent', - } + "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' + stype= 'START' mtype = spanner_subst[match.group(2)] return "(make-span-event '%s %s)" % (mtype , stype) @@ -825,34 +805,34 @@ 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!' - ] + 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)' % '|'.join (changed) @@ -864,7 +844,7 @@ def conv(str): @rule ((1, 7, 4), '<< >> -> < < > >') def conv(str): if re.search ('new-chords-done',str): - return str + return str str = re.sub (r'<<', '< <', str) str = re.sub (r'>>', '> >', str) @@ -881,18 +861,18 @@ def conv(str): @rule ((1, 7, 6), 'note\\script -> note-\script') def conv(str): kws = ['arpeggio', - 'sustainDown', - 'sustainUp', - 'f', - 'p', - 'pp', - 'ppp', - 'fp', - 'ff', - 'mf', - 'mp', - 'sfz', - ] + 'sustainDown', + 'sustainUp', + 'f', + 'p', + 'pp', + 'ppp', + 'fp', + 'ff', + 'mf', + 'mp', + 'sfz', + ] origstr = '|'.join (kws) str = re.sub (r'([^_^-])\\(%s)\b' % origstr, r'\1-\\\2', str) @@ -902,9 +882,9 @@ def conv(str): @rule ((1, 7, 10), "\property ChordName #'style -> #(set-chord-name-style 'style)") def conv(str): str = re.sub (r"\\property *ChordNames *\. *ChordName *\\(set|override) *#'style *= *#('[a-z]+)", - r"#(set-chord-name-style \2)", str) + r"#(set-chord-name-style \2)", str) str = re.sub (r"\\property *ChordNames *\. *ChordName *\\revert *#'style", - r"", str) + r"", str) return str @@ -933,29 +913,29 @@ def conv(str): @rule ((1, 7, 16), "divisiomaior -> divisioMaior") def conv(str): str = re.sub ("divisiomaior", - "divisioMaior", str) + "divisioMaior", str) str = re.sub ("divisiominima", - "divisioMinima", str) + "divisioMinima", str) str = re.sub ("divisiomaxima", - "divisioMaxima", str) + "divisioMaxima", str) return str @rule ((1, 7, 17), "Skip_req -> Skip_event") def conv(str): str = re.sub ("Skip_req_swallow_translator", - "Skip_event_swallow_translator", str) + "Skip_event_swallow_translator", str) return str @rule ((1, 7, 18), "groupOpen/Close -> start/stopGroup, #'outer -> #'enclose-bounds") def conv(str): str = re.sub ("groupOpen", - "startGroup", str) + "startGroup", str) str = re.sub ("groupClose", - "stopGroup", str) + "stopGroup", str) str = re.sub ("#'outer", - "#'enclose-bounds", str) + "#'enclose-bounds", str) return str @@ -963,14 +943,11 @@ def conv(str): @rule ((1, 7, 19), _ ("remove %s") % "GraceContext") def conv(str): if re.search( r'\\GraceContext', str): - stderr_write ('\n') - stderr_write (NOT_SMART % "GraceContext") - stderr_write (FROM_TO \ - % ("GraceContext", "#(add-to-grace-init .. )")) - stderr_write ('\n') - stderr_write (UPDATE_MANUALLY) - stderr_write ('\n') - raise FatalConversionError () + stderr_write (NOT_SMART % "GraceContext") + stderr_write (FROM_TO \ + % ("GraceContext", "#(add-to-grace-init .. )")) + stderr_write (UPDATE_MANUALLY) + raise FatalConversionError () str = re.sub ('HaraKiriStaffContext', 'RemoveEmptyStaffContext', str) return str @@ -979,42 +956,39 @@ def conv(str): @rule ((1, 7, 22), "#'type -> #'style") def conv(str): str = re.sub ( - r"(set|override|revert) *#'type", - r"\1 #'style", - str) + r"(set|override|revert) *#'type", + r"\1 #'style", + str) return str @rule ((1, 7, 23), "barNonAuto -> automaticBars") def conv(str): str = re.sub ( - "barNonAuto *= *##t", - "automaticBars = ##f", - str) + "barNonAuto *= *##t", + "automaticBars = ##f", + str) str = re.sub ( - "barNonAuto *= *##f", - "automaticBars = ##t", - str) + "barNonAuto *= *##f", + "automaticBars = ##t", + str) return str @rule ((1, 7, 24), _ ("cluster syntax")) def conv(str): if re.search( r'-(start|stop)Cluster', str): - stderr_write ('\n') - stderr_write (NOT_SMART % _ ("cluster syntax")) - stderr_write ('\n') - stderr_write (UPDATE_MANUALLY) - stderr_write ('\n') + stderr_write (NOT_SMART % _ ("cluster syntax")) + stderr_write (UPDATE_MANUALLY) - raise FatalConversionError () + raise FatalConversionError () return str @rule ((1, 7, 28), _ ("new Pedal style syntax")) def conv(str): str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\(override|set) *#'pedal-type *", - r"\property Staff.pedal\1Style ", str) + r"\property Staff.pedal\1Style ", str) str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\revert *#'pedal-type", '', str) return str @@ -1024,27 +998,27 @@ def sub_chord (m): origstr = '<%s>' % str if re.search (r'\\\\', str): - return origstr + return origstr if re.search (r'\\property', str): - return origstr + return origstr if re.match (r'^\s*\)?\s*\\[a-zA-Z]+', str): - return origstr + return origstr durs = [] def sub_durs (m, durs = durs): - durs.append(m.group(2)) - return m.group (1) + 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) + if dur_str == '': + dur_str = d + if dur_str <> d: + return '<%s>' % m.group (1) pslur_strs = [''] dyns = [''] @@ -1052,86 +1026,86 @@ def sub_chord (m): 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) + 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 = ''.join (slur_strs) + ''.join (pslur_strs) \ - + ''.join (dyns) + + ''.join (dyns) return '@STARTCHORD@%s@ENDCHORD@%s%s' % (str , dur_str, suffix) @@ -1145,7 +1119,7 @@ def sub_chords (str): marker_str = '%% new-chords-done %%' if re.search (marker_str,str): - return str + return str str = re.sub ('<<', '@STARTCHORD@', str) str = re.sub ('>>', '@ENDCHORD@', str) @@ -1158,16 +1132,16 @@ def sub_chords (str): # <>-[ 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) + 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) + '@STARTCHORD@', str) str = re.sub ('@STARTCHORD@', chordstart, str) str = re.sub ('@ENDCHORD@', chordend, str) str = re.sub (r'@ACCENT@', '>', str) @@ -1185,88 +1159,88 @@ def text_markup (str): # Find the beginning of each markup: match = markup_start.search (str) while match: - result = result + str[:match.end (1)] + " \markup" - str = str[match.end( 2):] - # Count matching parentheses to find the end of the - # current markup: - nesting_level = 0 - pars = re.finditer(r"[()]",str) - for par in pars: - if par.group () == '(': - nesting_level = nesting_level + 1 - else: - nesting_level = nesting_level - 1 - if nesting_level == 0: - markup_end = par.end () - break - # The full markup in old syntax: - markup = str[:markup_end] - # Modify to new syntax: - markup = musicglyph.sub (r"{\\musicglyph", markup) - markup = columns.sub (r"{", markup) - markup = submarkup_start.sub (r"{\\\1", markup) - markup = leftpar.sub ("{", markup) - markup = rightpar.sub ("}", markup) - - result = result + markup - # Find next markup - str = str[markup_end:] - match = markup_start.search(str) + result = result + str[:match.end (1)] + " \markup" + str = str[match.end( 2):] + # Count matching parentheses to find the end of the + # current markup: + nesting_level = 0 + pars = re.finditer(r"[()]",str) + for par in pars: + if par.group () == '(': + nesting_level = nesting_level + 1 + else: + nesting_level = nesting_level - 1 + if nesting_level == 0: + markup_end = par.end () + break + # The full markup in old syntax: + markup = str[:markup_end] + # Modify to new syntax: + markup = musicglyph.sub (r"{\\musicglyph", markup) + markup = columns.sub (r"{", markup) + markup = submarkup_start.sub (r"{\\\1", markup) + markup = leftpar.sub ("{", markup) + markup = rightpar.sub ("}", markup) + + result = result + markup + # Find next markup + str = str[markup_end:] + match = markup_start.search(str) result = result + str return result 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) + r"\1 \2\\)", 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) + r"\1 \2\\!", str) return str string_or_scheme = re.compile ('("(?:[^"\\\\]|\\\\.)*")|(#\\s*\'?\\s*\\()') -# Only apply articulation_substitute () outside strings and +# Only apply articulation_substitute () outside strings and # Scheme expressions: def smarter_articulation_subst (str): result = '' # Find the beginning of next string or Scheme expr.: match = string_or_scheme.search (str) while match: - # Convert the preceding LilyPond code: - previous_chunk = str[:match.start()] - result = result + articulation_substitute (previous_chunk) - if match.group (1): # Found a string - # Copy the string to output: - result = result + match.group (1) - str = str[match.end(1):] - else: # Found a Scheme expression. Count - # matching parentheses to find its end - str = str[match.start ():] - nesting_level = 0 - pars = re.finditer(r"[()]",str) - for par in pars: - if par.group () == '(': - nesting_level = nesting_level + 1 - else: - nesting_level = nesting_level - 1 - if nesting_level == 0: - scheme_end = par.end () - break - # Copy the Scheme expression to output: - result = result + str[:scheme_end] - str = str[scheme_end:] - # Find next string or Scheme expression: - match = string_or_scheme.search (str) + # Convert the preceding LilyPond code: + previous_chunk = str[:match.start()] + result = result + articulation_substitute (previous_chunk) + if match.group (1): # Found a string + # Copy the string to output: + result = result + match.group (1) + str = str[match.end(1):] + else: # Found a Scheme expression. Count + # matching parentheses to find its end + str = str[match.start ():] + nesting_level = 0 + pars = re.finditer(r"[()]",str) + for par in pars: + if par.group () == '(': + nesting_level = nesting_level + 1 + else: + nesting_level = nesting_level - 1 + if nesting_level == 0: + scheme_end = par.end () + break + # Copy the Scheme expression to output: + result = result + str[:scheme_end] + str = str[scheme_end:] + # Find next string or Scheme expression: + match = string_or_scheme.search (str) # Convert the remainder of the file result = result + articulation_substitute (str) return result def conv_relative(str): if re.search (r"\\relative", str): - str= "#(ly:set-option 'old-relative)\n" + str + str= "#(ly:set-option 'old-relative)\n" + str return str @@ -1286,13 +1260,10 @@ def conv (str): @rule ((1, 9, 1), _ ("Remove - before articulation")) def conv (str): if re.search ("font-style",str): - stderr_write ('\n') - stderr_write (NOT_SMART % "font-style") - stderr_write ('\n') - stderr_write (UPDATE_MANUALLY) - stderr_write ('\n') + stderr_write (NOT_SMART % "font-style") + stderr_write (UPDATE_MANUALLY) - raise FatalConversionError () + raise FatalConversionError () str = re.sub (r'-\\markup', r'@\\markup', str) str = re.sub (r'-\\', r'\\', str) @@ -1308,12 +1279,12 @@ def conv (str): @rule ((1, 9, 2), "\\newcontext -> \\new") def conv (str): str = re.sub ('ly:set-context-property', - 'ly:set-context-property!', str) + 'ly:set-context-property!', str) str = re.sub ('\\\\newcontext', '\\\\new', str) str = re.sub ('\\\\grace[\t\n ]*([^{ ]+)', - r'\\grace { \1 }', str) + r'\\grace { \1 }', str) str = re.sub ("\\\\grace[\t\n ]*{([^}]+)}", - r"""\\grace { + r"""\\grace { \\property Voice.Stem \\override #'stroke-style = #"grace" \1 \\property Voice.Stem \\revert #'stroke-style } @@ -1321,38 +1292,35 @@ def conv (str): return str -@rule ((1, 9, 3), (_ ("%s misspelling") % "\\acciaccatura") + +@rule ((1, 9, 3), (_ ("%s misspelling") % "\\acciaccatura") + ", fingerHorizontalDirection -> fingeringOrientations") def conv (str): str = re.sub ('accacciatura', - 'acciaccatura', str) + 'acciaccatura', str) if re.search ("context-spec-music", str): - stderr_write ('\n') - stderr_write (NOT_SMART % "context-spec-music") - stderr_write ('\n') - stderr_write (UPDATE_MANUALLY) - stderr_write ('\n') + stderr_write (NOT_SMART % "context-spec-music") + stderr_write (UPDATE_MANUALLY) - raise FatalConversionError () + raise FatalConversionError () str = re.sub ('fingerHorizontalDirection *= *#(LEFT|-1)', - "fingeringOrientations = #'(up down left)", str) + "fingeringOrientations = #'(up down left)", str) str = re.sub ('fingerHorizontalDirection *= *#(RIGHT|1)', - "fingeringOrientations = #'(up down right)", str) + "fingeringOrientations = #'(up down right)", str) return str @rule ((1, 9, 4), _ ('Swap < > and << >>')) def conv (str): if re.search ('\\figures', str): - warning (_ ("attempting automatic \\figures conversion. Check results!")); + 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 + 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) @@ -1383,24 +1351,19 @@ def conv (str): @rule ((1, 9, 6), _ ('deprecate %s') % 'ly:get-font') def conv (str): if re.search ("ly:get-font", str) : - stderr_write ('\n') - stderr_write (NOT_SMART % "(ly:-get-font") - stderr_write ('\n') - stderr_write (FROM_TO \ - % ("(ly:paper-get-font (ly:grob-get-paper foo) .. )", - "(ly:paper-get-font (ly:grob-get-paper foo) .. )")) - stderr_write (UPDATE_MANUALLY) - stderr_write ('\n') - raise FatalConversionError () + stderr_write (NOT_SMART % "ly:get-font") + stderr_write (FROM_TO \ + % ("(ly:paper-get-font (ly:grob-get-paper foo) .. )", + "(ly:paper-get-font (ly:grob-get-paper foo) .. )")) + stderr_write (UPDATE_MANUALLY) + raise FatalConversionError () if re.search ("\\pitch *#", str) : - stderr_write ('\n') - stderr_write (NOT_SMART % "\\pitch") - stderr_write ('\n') - stderr_write (_ ("Use Scheme code to construct arbitrary note events.")) - stderr_write ('\n') + stderr_write (NOT_SMART % "\\pitch") + stderr_write (_ ("Use Scheme code to construct arbitrary note events.")) + stderr_write ('\n') - raise FatalConversionError () + raise FatalConversionError () return str @@ -1408,73 +1371,67 @@ def conv (str): remove \\outputproperty, move ly:verbose into ly:get-option''')) 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) + 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) + sub_alteration, str) str = re.sub ("ly:verbose", "ly:get-option 'verbose", str) m= re.search ("\\\\outputproperty #([^#]+)[\t\n ]*#'([^ ]+)", str) if m: - stderr_write (_ (\ - r"""\outputproperty found, + 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 () + raise FatalConversionError () if re.search ("ly:(make-pitch|pitch-alteration)", str) \ - or re.search ("keySignature", str): - stderr_write ('\n') - stderr_write (NOT_SMART % "pitches") - stderr_write ('\n') - stderr_write ( - _ ("""The alteration field of Scheme pitches was multiplied by 2 + or re.search ("keySignature", str): + stderr_write (NOT_SMART % "pitches") + stderr_write ( + _ ("""The alteration field of Scheme pitches was multiplied by 2 to support quarter tone accidentals. You must update the following constructs manually: * calls of ly:make-pitch and ly:pitch-alteration * keySignature settings made with \property """)) - raise FatalConversionError () + raise FatalConversionError () return str @rule ((1, 9, 8), "dash-length -> dash-fraction") def conv (str): if re.search ("dash-length",str): - stderr_write ('\n') - stderr_write (NOT_SMART % "dash-length") - stderr_write ('\n') - stderr_write (FROM_TO % ("dash-length", "dash-fraction")) - stderr_write ('\n') - stderr_write (UPDATE_MANUALLY) - stderr_write ('\n') - raise FatalConversionError () + stderr_write (NOT_SMART % "dash-length") + stderr_write (FROM_TO % ("dash-length", "dash-fraction")) + stderr_write (UPDATE_MANUALLY) + raise FatalConversionError () return str @rule ((2, 1, 1), "font-relative-size -> font-size") def conv (str): def func(match): - return "#'font-size = #%d" % (2*int (match.group (1))) + return "#'font-size = #%d" % (2*int (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) + r"#'font-family = #'music", str) return str @@ -1493,16 +1450,16 @@ def conv (str): @rule ((2, 1, 4), _ ("removal of automaticMelismata; use melismaBusyProperties instead.")) def conv (str): def func (match): - c = match.group (1) - b = match.group (2) + 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 + 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 @@ -1525,26 +1482,26 @@ def conv (str): """) def conv (str): str = re.sub (r'\\include\s*"paper([0-9]+)(-init)?.ly"', - r"#(set-staff-size \1)", str) + r"#(set-staff-size \1)", str) def sub_note (match): - dur = '' - log = int (match.group (1)) - dots = int (match.group (2)) + dur = '' + log = int (match.group (1)) + dots = int (match.group (2)) - if log >= 0: - dur = '%d' % (1 << log) - else: - dur = { -1 : 'breve', - -2 : 'longa', - -3 : 'maxima'}[log] + if log >= 0: + dur = '%d' % (1 << log) + else: + dur = { -1 : 'breve', + -2 : 'longa', + -3 : 'maxima'}[log] - dur += ('.' * dots) + dur += ('.' * dots) - return r'\note #"%s" #%s' % (dur, match.group (3)) + 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) + sub_note, str) return str @@ -1563,37 +1520,37 @@ def conv (str): @rule ((2, 1, 14), "style = dotted -> dash-fraction = 0") def conv (str): str = re.sub (r"#'style\s*=\s*#'dotted-line", - r"#'dash-fraction = #0.0 ", str) + r"#'dash-fraction = #0.0 ", str) return str @rule ((2, 1, 15), "LyricsVoice . instr(ument) -> vocalName") def conv (str): str = re.sub (r'LyricsVoice\s*\.\s*instrument\s*=\s*("[^"]*")', - r'LyricsVoice . vocalName = \1', str) + r'LyricsVoice . vocalName = \1', str) str = re.sub (r'LyricsVoice\s*\.\s*instr\s*=\s*("[^"]*")', - r'LyricsVoice . vocNam = \1', str) + r'LyricsVoice . vocNam = \1', str) return str @rule ((2, 1, 16), '\\musicglyph #"accidentals-NUM" -> \\sharp/flat/etc.') 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)] + 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) + sub_acc, str) return str @@ -1601,18 +1558,15 @@ def conv (str): def conv (str): if re.search (r'\\partcombine', str): - stderr_write ('\n') - stderr_write (NOT_SMART % "\\partcombine") - stderr_write ('\n') - stderr_write (UPDATE_MANUALLY) - stderr_write ('\n') - raise FatalConversionError () + stderr_write (NOT_SMART % "\\partcombine") + stderr_write (UPDATE_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) + + r'\\context\s+Thread\s*=\s*two', + '\\\\newpartcombine\n\\1\n', str) return str @@ -1629,7 +1583,7 @@ def conv (str): Harmonic notes. Thread context removed. Lyrics context removed.""")) def conv (str): if re.search ('include "drumpitch', str): - stderr_write (_ ("Drums found. Enclose drum notes in \\drummode")) + stderr_write (_ ("Drums found. Enclose drum notes in \\drummode")) str = re.sub (r'\\include "drumpitch-init.ly"','', str) @@ -1640,25 +1594,25 @@ def conv (str): if re.search ('drums->paper', str): - stderr_write (_ ("\n%s found. Check file manually!\n") % _("Drum notation")) + stderr_write (_ ("\n%s found. Check file manually!\n") % _("Drum notation")) str = re.sub (r"""\\apply\s+#\(drums->paper\s+'([a-z]+)\)""", - r"""\property DrumStaff.drumStyleTable = #\1-style""", - str) + r"""\property DrumStaff.drumStyleTable = #\1-style""", + str) if re.search ('Thread', str): - stderr_write (_ ("\n%s found. Check file manually!\n") % "Thread"); + stderr_write (_ ("\n%s found. Check file manually!\n") % "Thread"); 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) + + 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): - stderr_write (_ ("\n%s found. Check file manually!\n") % "Lyrics"); + stderr_write (_ ("\n%s found. Check file manually!\n") % "Lyrics"); str = re.sub (r"""LyricsVoice""", r"""L@ricsVoice""", str) str = re.sub (r"""\bLyrics\b""", r"""LyricsVoice""", str) @@ -1686,12 +1640,12 @@ def conv (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) + 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) + + r"\\set\s*#'X-extent-callback\s*=\s*#Grob::preset_extent", + "", str) return str @@ -1702,16 +1656,16 @@ def conv (str): """ % _ ("new syntax for property settings:")) def conv (str): str = re.sub (r'(\\property[^=]+)=\s*([-0-9]+)', - r'\1= #\2', str) + r'\1= #\2', str) str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\=]+)\s*\\(set|override)', - r"\\overrid@ \1.\2 ", str) + r"\\overrid@ \1.\2 ", str) str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*=\s*', - r'\\s@t \1.\2 = ', str) + r'\\s@t \1.\2 = ', str) str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*\\unset', - r'\\uns@t \1.\2 ', str) + 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) + + 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) @@ -1728,32 +1682,32 @@ def conv (str): @rule ((2, 1, 23), _ ("Property setting syntax in \\translator{ }")) def conv (str): def subst_in_trans (match): - s = match.group (0) - s = re.sub (r'\s([a-zA-Z]+)\s*\\override', - r' \\override \1', s) - s = re.sub (r'\s([a-zA-Z]+)\s*\\set', - r' \\override \1', s) - s = re.sub (r'\s([a-zA-Z]+)\s*\\revert', - r' \\revert \1', s) - return s + s = match.group (0) + s = re.sub (r'\s([a-zA-Z]+)\s*\\override', + r' \\override \1', s) + s = re.sub (r'\s([a-zA-Z]+)\s*\\set', + r' \\override \1', s) + s = re.sub (r'\s([a-zA-Z]+)\s*\\revert', + r' \\revert \1', s) + return s str = re.sub (r'\\(translator|with)\s*{[^}]+}', subst_in_trans, str) def sub_abs (m): - context = m.group ('context') - d = m.groupdict () - if context: - context = " '%s" % context[:-1] # -1: remove . - else: - context = '' + context = m.group ('context') + d = m.groupdict () + if context: + context = " '%s" % context[:-1] # -1: remove . + else: + context = '' - d['context'] = context + d['context'] = context - return r"""#(override-auto-beam-setting %(prop)s %(num)s %(den)s%(context)s)""" % d + return r"""#(override-auto-beam-setting %(prop)s %(num)s %(den)s%(context)s)""" % d str = re.sub (r"""\\override\s*(?P[a-zA-Z]+\s*\.\s*)?autoBeamSettings""" - +r"""\s*#(?P[^=]+)\s*=\s*#\(ly:make-moment\s+(?P\d+)\s+(?P\d)\s*\)""", - sub_abs, str) + +r"""\s*#(?P[^=]+)\s*=\s*#\(ly:make-moment\s+(?P\d+)\s+(?P\d)\s*\)""", + sub_abs, str) return str @@ -1774,12 +1728,9 @@ def conv (str): str = re.sub (r'ly:get-broken-into', 'ly:spanner-broken-into', str) str = re.sub (r'Melisma_engraver', 'Melisma_translator', str) if re.search ("ly:get-paper-variable", str): - stderr_write ('\n') - stderr_write (NOT_SMART % "ly:paper-get-variable") - stderr_write ('\n') - stderr_write (_ ('use %s') % '(ly:paper-lookup (ly:grob-paper ))') - stderr_write ('\n') - raise FatalConversionError () + stderr_write (NOT_SMART % "ly:paper-get-variable") + stderr_write (_ ('Use %s\n') % '(ly:paper-lookup (ly:grob-paper ))') + raise FatalConversionError () str = re.sub (r'\\defaultAccidentals', "#(set-accidental-style 'default)", str) str = re.sub (r'\\voiceAccidentals', "#(set-accidental-style 'voice)", str) @@ -1808,32 +1759,31 @@ def conv (str): @rule ((2, 1, 27), "property transposing -> tuning") def conv (str): def subst (m): - g = int (m.group (2)) - o = g / 12 - g -= o * 12 - if g < 0: - g += 12 - o -= 1 + g = int (m.group (2)) + o = g / 12 + g -= o * 12 + if g < 0: + g += 12 + o -= 1 - lower_pitches = filter (lambda x : x <= g, [0, 2, 4, 5, 7, 9, 11, 12]) - s = len (lower_pitches) -1 - a = g - lower_pitches [-1] + lower_pitches = filter (lambda x : x <= g, [0, 2, 4, 5, 7, 9, 11, 12]) + s = len (lower_pitches) -1 + a = g - lower_pitches [-1] - print s , lower_pitches, g, a, s - str = 'cdefgab' [s] - str += ['eses', 'es', '', 'is', 'isis'][a + 2] - if o < 0: - str += ',' * (-o - 1) - elif o >= 0: - str += "'" * (o + 1) + str = 'cdefgab' [s] + str += ['eses', 'es', '', 'is', 'isis'][a + 2] + if o < 0: + str += ',' * (-o - 1) + elif o >= 0: + str += "'" * (o + 1) - return '\\transposition %s ' % str + return '\\transposition %s ' % str str = re.sub (r"\\set ([A-Za-z]+\s*\.\s*)?transposing\s*=\s*#([-0-9]+)", - subst, str) + subst, str) return str @@ -1862,16 +1812,16 @@ ly:get-stencil-extent -> ly:stencil-extent def conv (str): str = re.sub (r'\\threeq(flat|sharp)', r'\\sesqui\1', str) str = re.sub (r'ly:stencil-get-extent', - 'ly:stencil-extent', str) + 'ly:stencil-extent', str) str = re.sub (r'ly:translator-find', - 'ly:context-find', str) + 'ly:context-find', str) str = re.sub ('ly:unset-context-property','ly:context-unset-property', - str) + str) str = re.sub (r'ly:get-mutable-properties', - 'ly:mutable-music-properties',str) + 'ly:mutable-music-properties',str) str = re.sub (r'centralCPosition', - 'middleCPosition',str) + 'middleCPosition',str) return str @@ -1884,22 +1834,22 @@ def conv (str): @rule ((2, 1, 33), 'breakAlignOrder -> break-align-orders.') def conv (str): str = re.sub (r"(\\set\s+)?(?P(Score\.)?)breakAlignOrder\s*=\s*#'(?P[^\)]+)", - r"\n\\override \gBreakAlignment #'break-align-orders = " - + "#(make-vector 3 '\g)", str) + r"\n\\override \gBreakAlignment #'break-align-orders = " + + "#(make-vector 3 '\g)", str) return str @rule ((2, 1, 34), 'set-paper-size -> set-default-paper-size.') def conv (str): str = re.sub (r"\(set-paper-size", - "(set-default-paper-size",str) + "(set-default-paper-size",str) return str @rule ((2, 1, 36), 'ly:mutable-music-properties -> ly:music-mutable-properties') def conv (str): str = re.sub (r"ly:mutable-music-properties", - "ly:music-mutable-properties", str) + "ly:music-mutable-properties", str) return str @@ -1916,23 +1866,20 @@ def conv (str): @rule ((2, 3, 2), '\\FooContext -> \\Foo') def conv (str): if re.search ('textheight', str): - stderr_write ('\n') - stderr_write (NOT_SMART % "textheight") - stderr_write ('\n') - stderr_write (UPDATE_MANUALLY) - stderr_write ('\n') - stderr_write ( + stderr_write (NOT_SMART % "textheight") + stderr_write (UPDATE_MANUALLY) + stderr_write ( _ ("""Page layout has been changed, using paper size and margins. textheight is no longer used. """)) str = re.sub (r'\\OrchestralScoreContext', '\\Score', str) def func(m): - if m.group(1) not in ['RemoveEmptyStaff', - 'AncientRemoveEmptyStaffContext', - 'EasyNotation']: - return '\\' + m.group (1) - else: - return m.group (0) + if m.group(1) not in ['RemoveEmptyStaff', + 'AncientRemoveEmptyStaffContext', + 'EasyNotation']: + return '\\' + m.group (1) + else: + return m.group (0) str = re.sub (r'\\([a-zA-Z]+)Context\b', func, str) @@ -1956,7 +1903,7 @@ def conv (str): def conv (str): str = re.sub (r'\\consistsend', '\\consists', str) str = re.sub (r'\\lyricsto\s+("?[a-zA-Z]+"?)(\s*\\new Lyrics\s*)?\\lyrics', - r'\\lyricsto \1 \2', str) + r'\\lyricsto \1 \2', str) return str @@ -1972,14 +1919,14 @@ def conv (str): str = re.sub (r'\\addlyrics', r'\\oldaddlyrics', str) str = re.sub (r'\\newlyrics', r'\\addlyrics', str) if re.search (r"\\override\s*TextSpanner", str): - stderr_write ("\nWarning: TextSpanner has been split into DynamicTextSpanner and TextSpanner\n") + stderr_write ("\nWarning: TextSpanner has been split into DynamicTextSpanner and TextSpanner\n") return str @rule ((2, 3, 11), '\\setMmRestFermata -> ^\\fermataMarkup') def conv (str): str = re.sub (r'\\setMmRestFermata\s+(R[0-9.*/]*)', - r'\1^\\fermataMarkup', str) + r'\1^\\fermataMarkup', str) return str @@ -2002,8 +1949,8 @@ def conv (str): }""", str) str = re.sub ('soloADue', 'printPartCombineTexts', str) str = re.sub (r'\\applymusic\s*#notes-to-clusters', - '\\makeClusters', str) - + '\\makeClusters', str) + str = re.sub (r'pagenumber\s*=', 'firstpagenumber = ', str) return str @@ -2031,7 +1978,7 @@ def conv (str): def conv (str): str = re.sub (r'(slur|stem|phrasingSlur|tie|dynamic|dots|tuplet|arpeggio|)Both', r'\1Neutral', str) str = re.sub (r"\\applymusic\s*#\(remove-tag\s*'([a-z-0-9]+)\)", - r"\\removeWithTag #'\1", str) + r"\\removeWithTag #'\1", str) return str @@ -2046,7 +1993,7 @@ def conv (str): str = re.sub (r'\\paper', r'\\layout', str) str = re.sub (r'\\bookpaper', r'\\paper', str) if re.search ('paper-set-staff-size', str): - warning (_ ('''staff size should be changed at top-level + warning (_ ('''staff size should be changed at top-level with #(set-global-staff-size ) @@ -2056,22 +2003,22 @@ with str = re.sub (r'#\(paper-set-staff-size', '%Use set-global-staff-size at toplevel\n% #(layout-set-staff-size', str) return str - + @rule ((2, 3, 23), r'\context Foo = NOTENAME -> \context Foo = "NOTENAME"') def conv (str): str = re.sub (r'\\context\s+([a-zA-Z]+)\s*=\s*([a-z]+)\s', - r'\\context \1 = "\2" ', - str ) + r'\\context \1 = "\2" ', + str ) return str @rule ((2, 3, 24), _ ('''regularize other identifiers''')) def conv (str): def sub(m): - return regularize_id (m.group (1)) + return regularize_id (m.group (1)) str = re.sub (r'(maintainer_email|maintainer_web|midi_stuff|gourlay_maxmeasures)', - sub, str) + sub, str) return str @@ -2090,30 +2037,30 @@ def conv (str): @rule ((2, 5, 0), '\\quote -> \\quoteDuring') def conv (str): str = re.sub (r'\\quote\s+"?([a-zA-Z0-9]+)"?\s+([0-9.*/]+)', - r'\\quoteDuring #"\1" { \skip \2 }', - str) + r'\\quoteDuring #"\1" { \skip \2 }', + str) return str @rule ((2, 5, 1), 'ly:import-module -> ly:module-copy') def conv (str): str = re.sub (r'ly:import-module', - r'ly:module-copy', str) + r'ly:module-copy', str) return str @rule ((2, 5, 2), '\markup .. < .. > .. -> \markup .. { .. } ..') def conv (str): str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>', - r'\\\1 {\2}', str) + r'\\\1 {\2}', str) str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>', - r'\\\1 {\2}', str) + r'\\\1 {\2}', str) str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>', - r'\\\1 {\2}', str) + r'\\\1 {\2}', str) def get_markup (m): - s = m.group (0) - s = re.sub (r'''((\\"|})\s*){''', '\2 \\line {', s) - return s + s = m.group (0) + s = re.sub (r'''((\\"|})\s*){''', '\2 \\line {', s) + return s str = re.sub (r'\\markup\s*{([^}]|{[^}]*})*}', get_markup, str) return str @@ -2130,7 +2077,7 @@ def conv (str): @rule ((2, 5, 12), '\set Slur #\'dashed = #X -> \slurDashed') def conv (str): str = re.sub (r"\\override\s+(Voice\.)?Slur #'dashed\s*=\s*#\d*(\.\d+)?", - r"\\slurDashed", str) + r"\\slurDashed", str) return str @@ -2138,29 +2085,27 @@ def conv (str): def conv (str): input_encoding = 'latin1' def func (match): - encoding = match.group (1) - - # FIXME: automatic recoding of other than latin1? - if encoding == 'latin1': - return match.group (2) - - stderr_write ('\n') - stderr_write (NOT_SMART % ("\\encoding: %s" % encoding)) - stderr_write ('\n') - stderr_write (_ ("LilyPond source must be UTF-8")) - stderr_write ('\n') - if encoding == 'TeX': - stderr_write (_ ("Try the texstrings backend")) - stderr_write ('\n') - else: - stderr_write ( _("Do something like: %s") % \ - ("recode %s..utf-8 FILE" % encoding)) - stderr_write ('\n') - stderr_write (_ ("Or save as UTF-8 in your editor")) - stderr_write ('\n') - raise FatalConversionError () - - return match.group (0) + encoding = match.group (1) + + # FIXME: automatic recoding of other than latin1? + if encoding == 'latin1': + return match.group (2) + + stderr_write (NOT_SMART % ("\\encoding: %s" % encoding)) + stderr_write (_ ("LilyPond source must be UTF-8")) + stderr_write ('\n') + if encoding == 'TeX': + stderr_write (_ ("Try the texstrings backend")) + stderr_write ('\n') + else: + stderr_write ( _("Do something like: %s") % \ + ("recode %s..utf-8 FILE" % encoding)) + stderr_write ('\n') + stderr_write (_ ("Or save as UTF-8 in your editor")) + stderr_write ('\n') + raise FatalConversionError () + + return match.group (0) str = re.sub (r'\\encoding\s+"?([a-zA-Z0-9]+)"?(\s+)', func, str) @@ -2170,16 +2115,16 @@ def conv (str): de_input = codecs.getdecoder (input_encoding) en_utf_8 = codecs.getencoder ('utf_8') try: - de_ascii (str) + de_ascii (str) # only in python >= 2.3 # except UnicodeDecodeError: except UnicodeError: - # do not re-recode UTF-8 input - try: - de_utf_8 (str) - #except UnicodeDecodeError: - except UnicodeError: - str = en_utf_8 (de_input (str)[0])[0] + # do not re-recode UTF-8 input + try: + de_utf_8 (str) + #except UnicodeDecodeError: + except UnicodeError: + str = en_utf_8 (de_input (str)[0])[0] @@ -2190,17 +2135,13 @@ def conv (str): @rule ((2, 5, 17), _ ('remove %s') % 'ly:stencil-set-extent!') def conv (str): if re.search ("ly:stencil-set-extent!", str): - stderr_write ('\n') - stderr_write (NOT_SMART % "ly:stencil-set-extent!") - stderr_write ('\n') - stderr_write ('use (set! VAR (ly:make-stencil (ly:stencil-expr VAR) X-EXT Y-EXT))\n') - raise FatalConversionError () + stderr_write (NOT_SMART % "ly:stencil-set-extent!") + stderr_write (_ ('Use %s\n') % '(set! VAR (ly:make-stencil (ly:stencil-expr VAR) X-EXT Y-EXT))') + raise FatalConversionError () if re.search ("ly:stencil-align-to!", str): - stderr_write ('\n') - stderr_write (NOT_SMART % "ly:stencil-align-to!") - stderr_write ('\n') - stderr_write ('use (set! VAR (ly:stencil-aligned-to VAR AXIS DIR))\n') - raise FatalConversionError () + stderr_write (NOT_SMART % "ly:stencil-align-to!") + stderr_write (_ ('Use %s\n') % '(set! VAR (ly:stencil-aligned-to VAR AXIS DIR))') + raise FatalConversionError () return str @@ -2214,16 +2155,13 @@ def conv (str): def conv (str): if re.search ("(override-|revert-)auto-beam-setting", str)\ or re.search ("autoBeamSettings", str): - stderr_write ('\n') - stderr_write (NOT_SMART % _ ("auto beam settings")) - stderr_write ('\n') - stderr_write (_ (''' + stderr_write (NOT_SMART % _ ("auto beam settings")) + stderr_write (_ (''' Auto beam settings must now specify each interesting moment in a measure -explicitely; 1/4 is no longer multiplied to cover moments 1/2 and 3/4 too. +explicitly; 1/4 is no longer multiplied to cover moments 1/2 and 3/4 too. ''')) - stderr_write (UPDATE_MANUALLY) - stderr_write ('\n') - raise FatalConversionError () + stderr_write (UPDATE_MANUALLY) + raise FatalConversionError () return str @@ -2241,7 +2179,7 @@ def conv (str): @rule ((2, 7, 0), 'ly:get-default-font -> ly:grob-default-font') def conv (str): - return re.sub('ly:get-default-font', 'ly:grob-default-font', str) + return re.sub('ly:get-default-font', 'ly:grob-default-font', str) @rule ((2, 7, 1), '''ly:parser-define -> ly:parser-define! @@ -2252,8 +2190,8 @@ def conv (str): str = re.sub('ly:parser-define', 'ly:parser-define!', str) str = re.sub('excentricity', 'eccentricity', str) str = re.sub(r'\\(consists|remove) *"?Timing_engraver"?', - r'\\\1 "Timing_translator" \\\1 "Default_bar_line_engraver"', - str) + r'\\\1 "Timing_translator" \\\1 "Default_bar_line_engraver"', + str) return str @@ -2275,11 +2213,11 @@ def conv (str): str = re.sub('Performer_group_performer', 'Performer_group', str) str = re.sub('Engraver_group_engraver', 'Engraver_group', str) str = re.sub (r"#'inside-slur\s*=\s*##t *", - r"#'avoid-slur = #'inside ", str) + r"#'avoid-slur = #'inside ", str) str = re.sub (r"#'inside-slur\s*=\s*##f *", - r"#'avoid-slur = #'around ", str) + r"#'avoid-slur = #'around ", str) str = re.sub (r"#'inside-slur", - r"#'avoid-slur", str) + r"#'avoid-slur", str) return str @@ -2307,70 +2245,71 @@ def conv (str): @rule ((2, 7, 13), 'layout engine refactoring [FIXME]') def conv (str): def subber (match): - newkey = {'spacing-procedure': 'springs-and-rods', - 'after-line-breaking-callback' : 'after-line-breaking', - 'before-line-breaking-callback' : 'before-line-breaking', - 'print-function' : 'stencil'} [match.group(3)] - what = match.group (1) - grob = match.group (2) - - if what == 'revert': - return "revert %s #'callbacks %% %s\n" % (grob, newkey) - elif what == 'override': - return "override %s #'callbacks #'%s" % (grob, newkey) - else: - raise 'urg' - return '' + newkey = {'spacing-procedure': 'springs-and-rods', + 'after-line-breaking-callback' : 'after-line-breaking', + 'before-line-breaking-callback' : 'before-line-breaking', + 'print-function' : 'stencil'} [match.group(3)] + what = match.group (1) + grob = match.group (2) + + if what == 'revert': + return "revert %s #'callbacks %% %s\n" % (grob, newkey) + elif what == 'override': + return "override %s #'callbacks #'%s" % (grob, newkey) + else: + raise 'urg' + return '' str = re.sub(r"(override|revert)\s*([a-zA-Z.]+)\s*#'(spacing-procedure|after-line-breaking-callback" - + r"|before-line-breaking-callback|print-function)", - subber, str) + + r"|before-line-breaking-callback|print-function)", + subber, str) if re.search ('bar-size-procedure', str): - stderr_write (NOT_SMART % "bar-size-procedure") + stderr_write (NOT_SMART % "bar-size-procedure") if re.search ('space-function', str): - stderr_write (NOT_SMART % "space-function") + stderr_write (NOT_SMART % "space-function") if re.search ('verticalAlignmentChildCallback', str): - stderr_write (_ ('verticalAlignmentChildCallback has been deprecated')) + stderr_write (_ ('verticalAlignmentChildCallback has been deprecated')) + stderr_write ('\n') return str @rule ((2, 7, 14), _ ('Remove callbacks property, deprecate XY-extent-callback.')) def conv (str): str = re.sub (r"\\override +([A-Z.a-z]+) #'callbacks", - r"\\override \1", str) + r"\\override \1", str) str = re.sub (r"\\revert ([A-Z.a-z]+) #'callbacks % ([a-zA-Z]+)", - r"\\revert \1 #'\2", str) + r"\\revert \1 #'\2", str) str = re.sub (r"([XY]-extent)-callback", r'\1', str) str = re.sub (r"RemoveEmptyVerticalGroup", "VerticalAxisGroup", str) str = re.sub (r"\\set ([a-zA-Z]*\.?)minimumVerticalExtent", - r"\\override \1VerticalAxisGroup #'minimum-Y-extent", - str) + r"\\override \1VerticalAxisGroup #'minimum-Y-extent", + str) str = re.sub (r"minimumVerticalExtent", - r"\\override VerticalAxisGroup #'minimum-Y-extent", - str) + r"\\override VerticalAxisGroup #'minimum-Y-extent", + str) str = re.sub (r"\\set ([a-zA-Z]*\.?)extraVerticalExtent", - r"\\override \1VerticalAxisGroup #'extra-Y-extent", str) + r"\\override \1VerticalAxisGroup #'extra-Y-extent", str) str = re.sub (r"\\set ([a-zA-Z]*\.?)verticalExtent", - r"\\override \1VerticalAxisGroup #'Y-extent", str) + r"\\override \1VerticalAxisGroup #'Y-extent", str) return str @rule ((2, 7, 15), _ ('Use grob closures iso. XY-offset-callbacks.')) def conv (str): if re.search ('[XY]-offset-callbacks', str): - stderr_write (NOT_SMART % "[XY]-offset-callbacks") + stderr_write (NOT_SMART % "[XY]-offset-callbacks") if re.search ('position-callbacks', str): - stderr_write (NOT_SMART % "position-callbacks") + stderr_write (NOT_SMART % "position-callbacks") return str @rule ((2, 7, 22), r"\tag #'(a b) -> \tag #'a \tag #'b") def conv (str): def sub_syms (m): - syms = m.group (1).split () - tags = ["\\tag #'%s" % s for s in syms] - return ' '.join (tags) + syms = m.group (1).split () + tags = ["\\tag #'%s" % s for s in syms] + return ' '.join (tags) str = re.sub (r"\\tag #'\(([^)]+)\)", sub_syms, str) return str @@ -2379,8 +2318,8 @@ def conv (str): @rule ((2, 7, 24), _ ('deprecate %s') % 'number-visibility') def conv (str): str = re.sub (r"#'number-visibility", - "#'number-visibility % number-visibility is deprecated. Tune the TupletNumber instead\n", - str) + "#'number-visibility % number-visibility is deprecated. Tune the TupletNumber instead\n", + str) return str @@ -2394,10 +2333,10 @@ def conv (str): def conv (str): for a in ['beamed-lengths', 'beamed-minimum-free-lengths', 'lengths', - 'beamed-extreme-minimum-free-lengths']: - str = re.sub (r"\\override\s+Stem\s+#'%s" % a, - r"\\override Stem #'details #'%s" % a, - str) + 'beamed-extreme-minimum-free-lengths']: + str = re.sub (r"\\override\s+Stem\s+#'%s" % a, + r"\\override Stem #'details #'%s" % a, + str) return str @@ -2410,55 +2349,55 @@ def conv (str): @rule ((2, 7, 31), "Foo_bar::bla_bla -> ly:foo-bar::bla-bla") def conv (str): def sub_cxx_id (m): - str = m.group(1) - return 'ly:' + str.lower ().replace ('_','-') + str = m.group(1) + return 'ly:' + str.lower ().replace ('_','-') str = re.sub (r'([A-Z][a-z_0-9]+::[a-z_0-9]+)', - sub_cxx_id, str) + sub_cxx_id, str) return str @rule ((2, 7, 32), _ ("foobar -> foo-bar for \paper, \layout")) def conv (str): identifier_subs = [ - ('inputencoding', 'input-encoding'), - ('printpagenumber', 'print-page-number'), - ('outputscale', 'output-scale'), - ('betweensystemspace', 'between-system-space'), - ('betweensystempadding', 'between-system-padding'), - ('pagetopspace', 'page-top-space'), - ('raggedlastbottom', 'ragged-last-bottom'), - ('raggedright', 'ragged-right'), - ('raggedlast', 'ragged-last'), - ('raggedbottom', 'ragged-bottom'), - ('aftertitlespace', 'after-title-space'), - ('beforetitlespace', 'before-title-space'), - ('betweentitlespace', 'between-title-space'), - ('topmargin', 'top-margin'), - ('bottommargin', 'bottom-margin'), - ('headsep', 'head-separation'), - ('footsep', 'foot-separation'), - ('rightmargin', 'right-margin'), - ('leftmargin', 'left-margin'), - ('printfirstpagenumber', 'print-first-page-number'), - ('firstpagenumber', 'first-page-number'), - ('hsize', 'paper-width'), - ('vsize', 'paper-height'), - ('horizontalshift', 'horizontal-shift'), - ('staffspace', 'staff-space'), - ('linethickness', 'line-thickness'), - ('ledgerlinethickness', 'ledger-line-thickness'), - ('blotdiameter', 'blot-diameter'), - ('staffheight', 'staff-height'), - ('linewidth', 'line-width'), - ('annotatespacing', 'annotate-spacing') - ] + ('inputencoding', 'input-encoding'), + ('printpagenumber', 'print-page-number'), + ('outputscale', 'output-scale'), + ('betweensystemspace', 'between-system-space'), + ('betweensystempadding', 'between-system-padding'), + ('pagetopspace', 'page-top-space'), + ('raggedlastbottom', 'ragged-last-bottom'), + ('raggedright', 'ragged-right'), + ('raggedlast', 'ragged-last'), + ('raggedbottom', 'ragged-bottom'), + ('aftertitlespace', 'after-title-space'), + ('beforetitlespace', 'before-title-space'), + ('betweentitlespace', 'between-title-space'), + ('topmargin', 'top-margin'), + ('bottommargin', 'bottom-margin'), + ('headsep', 'head-separation'), + ('footsep', 'foot-separation'), + ('rightmargin', 'right-margin'), + ('leftmargin', 'left-margin'), + ('printfirstpagenumber', 'print-first-page-number'), + ('firstpagenumber', 'first-page-number'), + ('hsize', 'paper-width'), + ('vsize', 'paper-height'), + ('horizontalshift', 'horizontal-shift'), + ('staffspace', 'staff-space'), + ('linethickness', 'line-thickness'), + ('ledgerlinethickness', 'ledger-line-thickness'), + ('blotdiameter', 'blot-diameter'), + ('staffheight', 'staff-height'), + ('linewidth', 'line-width'), + ('annotatespacing', 'annotate-spacing') + ] for (a,b) in identifier_subs: - ### for C++: - ## str = re.sub ('"%s"' % a, '"%s"' b, str) + ### for C++: + ## str = re.sub ('"%s"' % a, '"%s"' b, str) - str = re.sub (a, b, str) + str = re.sub (a, b, str) return str @@ -2478,9 +2417,9 @@ def conv (str): @rule ((2, 7, 40), "rehearsalMarkAlignSymbol/barNumberAlignSymbol -> break-align-symbol") def conv (str): str = re.sub (r'\\set\s+Score\s*\.\s*barNumberAlignSymbol\s*=', - r"\\override Score.BarNumber #'break-align-symbol = ", str) + r"\\override Score.BarNumber #'break-align-symbol = ", str) str = re.sub (r'\\set\s*Score\s*\.\s*rehearsalMarkAlignSymbol\s*=', - r"\\override Score.RehearsalMark #'break-align-symbol = ", str) + r"\\override Score.RehearsalMark #'break-align-symbol = ", str) return str @@ -2515,7 +2454,7 @@ def conv (str): if re.search ('tupletNumberFormatFunction', str): stderr_write ("\n") - stderr_write ("tupletNumberFormatFunction has been removed. Use #'text property on TupletNumber") + stderr_write ("tupletNumberFormatFunction has been removed. Use #'text property on TupletNumber") stderr_write ("\n") return str @@ -2540,7 +2479,7 @@ def conv (str): while dur > 1 : dur /= 2 log2 += 1 - + den = (1 << dots) * (1 << log2) num = ((1 << (dots+1)) - 1) @@ -2553,7 +2492,7 @@ def conv (str): } """ % (num*count, den) - + str = re.sub (r'\\midi\s*{\s*\\tempo ([0-9]+)\s*([.]*)\s*=\s*([0-9]+)\s*}', sub_tempo, str) return str @@ -2574,6 +2513,12 @@ def conv (str): return re.sub ('ly:clone-parser', 'ly:parser-clone', str) +@rule ((2, 11, 3), "no-spacing-rods -> extra-spacing-width") +def conv (str): + str = re.sub (r"no-spacing-rods\s+=\s+##t", r"extra-spacing-width = #'(+inf.0 . -inf.0)", str) + str = re.sub (r"no-spacing-rods\s+=\s+##f", r"extra-spacing-width = #'(0 . 0)", str) + return str + @rule ((2, 11, 5), _ ("deprecate cautionary-style. Use AccidentalCautionary properties")) def conv (str): @@ -2590,10 +2535,10 @@ def conv (str): @rule ((2, 11, 6), _ ("Rename accidental glyphs, use glyph-name-alist.")) def conv (str): - + def sub_acc_name (m): idx = int (m.group (1).replace ('M','-')) - + return ["accidentals.doublesharp", "accidentals.sharp.slashslash.stemstemstem", "accidentals.sharp", @@ -2605,7 +2550,7 @@ def conv (str): "accidentals.flatflat"][4-idx] str = re.sub (r"accidentals[.](M?[-0-9]+)", - sub_acc_name, str) + sub_acc_name, str) str = re.sub (r"(KeySignature|Accidental[A-Za-z]*)\s*#'style\s*=\s*#'([a-z]+)", r"\1 #'glyph-name-alist = #alteration-\2-glyph-name-alist", str) ## FIXME: standard vs default, alteration-FOO vs FOO-alteration @@ -2643,14 +2588,15 @@ def conv (str): str) if re.search ('edge-text', str): - stderr_write (NOT_SMART % _ ("edge-text settings for TextSpanner.")) - stderr_write (_ ("Use\n\n%s") % + stderr_write (NOT_SMART % _ ("edge-text settings for TextSpanner")) + stderr_write (_ ("Use\n\n%s") % "\t\\override TextSpanner #'bound-details #'right #'text = \n" "\t\\override TextSpanner #'bound-details #'left #'text = \n") return str -@rule ((2, 11, 15), "#'edge-height -> #'bound-details #'right/left #'text = ...") +@rule ((2, 11, 15), "TextSpanner #'edge-height -> #'bound-details #'right/left #'text = ...\n\ +Remove 'forced-distance for fixed spacing between staves in a PianoStaff.") def conv (str): def sub_edge_height (m): s = '' @@ -2658,20 +2604,27 @@ def conv (str): ('right', m.group (4))]: if h and float (h): - once = m.group(1) + once = m.group (1) if not once: once = '' - - s += (r"%s \override %s #'bound-details #'%s #'text = \markup { \draw-line #'(0 . %s) }" - % (once, m.group (2), var, h)) + context = m.group (2) + if not context: + context = '' + + s += (r"%s \override %sTextSpanner #'bound-details #'%s #'text = \markup { \draw-line #'(0 . %s) }" + % (once, context, var, h)) s += '\n' - + return s - - - str = re.sub (r"(\\once)?\s*\\override\s*([a-zA-Z.]+)\s*#'edge-height\s*=\s*#'\(([0-9.-]+)\s+[.]\s+([0-9.-]+)\)", - sub_edge_height, str) + + + str = re.sub (r"(\\once)?\s*\\override\s*([a-zA-Z]+\s*[.]\s*)?TextSpanner\s*#'edge-height\s*=\s*#'\(\s*([0-9.-]+)\s+[.]\s+([0-9.-]+)\s*\)", sub_edge_height, str) + if re.search (r"#'forced-distance", str): + stderr_write (NOT_SMART % "VerticalAlignment #'forced-distance") + stderr_write (_ ("Use the `alignment-offsets' sub-property of\n")) + stderr_write (_ ("NonMusicalPaperColumn #'line-break-system-details\n")) + stderr_write (_ ("to set fixed distances between staves.\n")) return str @@ -2689,9 +2642,9 @@ def conv (str): r"scripts.caesura.curved", str) if re.search ('dash-fraction', str): - stderr_write (NOT_SMART % _ ("all settings related to dashed lines.\n")) - stderr_write (_ ("Use \\override ... #'style = #'line for solid lines and\n")) - stderr_write (_ ("\t\\override ... #'style = #'dashed-line for dashed lines.")) + stderr_write (NOT_SMART % _ ("all settings related to dashed lines")) + stderr_write (_ ("Use \\override ... #'style = #'line for solid lines and\n")) + stderr_write (_ ("\t\\override ... #'style = #'dashed-line for dashed lines.")) return str @@ -2727,18 +2680,19 @@ def conv (str): return str -@rule ((2, 11, 50), "metronomeMarkFormatter uses text markup as second argument") +@rule ((2, 11, 50), _ ("metronomeMarkFormatter uses text markup as second argument,\n\ +fret diagram properties moved to fret-diagram-details.")) def conv (str): + ## warning 1/2: metronomeMarkFormatter uses text markup as second argument if re.search ('metronomeMarkFormatter', str): - stderr_write (NOT_SMART % _ ("metronomeMarkFormatter got an additional text argument.\n")) - stderr_write (_ ("The function assigned to Score.metronomeMarkFunction now uses the signature\n%s") % + stderr_write (NOT_SMART % "metronomeMarkFormatter") + stderr_write (_ ("metronomeMarkFormatter got an additional text argument.\n")) + stderr_write (_ ("The function assigned to Score.metronomeMarkFunction now uses the signature\n%s") % "\t(format-metronome-markup text dur count context)\n") - return str -@rule ((2,11,50), "Fret diagram properties moved to fret-diagram-details") -def conv (str): - fret_props = ['barre-type', - 'dot-color', + ## warning 2/2: fret diagram properties moved to fret-diagram-details + fret_props = ['barre-type', + 'dot-color', 'dot-radius', 'finger-code', 'fret-count', @@ -2750,106 +2704,1009 @@ def conv (str): 'open-string', 'orientation'] for prop in fret_props: - if re.search ( prop, str): - stderr_write ('\n') - stderr_write (NOT_SMART % - prop + " in fret-diagram properties. Use fret-diagram-details.") - stderr_write ('\n') + if re.search (prop, str): + stderr_write (NOT_SMART % (_ ("%s in fret-diagram properties") % prop)) + stderr_write (_ ('Use %s\n') % "fret-diagram-details") return str -@rule ((2, 11, 51), "\\octave -> \\octaveCheck") +@rule ((2, 11, 51), "\\octave -> \\octaveCheck, \\arpeggioUp -> \\arpeggioArrowUp,\n\ +\\arpeggioDown -> \\arpeggioArrowDown, \\arpeggioNeutral -> \\arpeggioNormal,\n\ +\\setTextCresc -> \\crescTextCresc, \\setTextDecresc -> \\dimTextDecresc,\n\ +\\setTextDecr -> \\dimTextDecr, \\setTextDim -> \\dimTextDim,\n\ +\\setHairpinCresc -> \\crescHairpin, \\setHairpinDecresc -> \\dimHairpin,\n\ +\\sustainUp -> \\sustainOff, \\sustainDown -> \\sustainOn\n\ +\\sostenutoDown -> \\sostenutoOn, \\sostenutoUp -> \\sostenutoOff") def conv (str): - str = re.sub (r"\\octave", r"\\octaveCheck", str) + str = re.sub (r"\\octave(?![a-zA-Z])", r"\\octaveCheck", str) + str = re.sub (r"arpeggioUp", r"arpeggioArrowUp", str) + str = re.sub (r"arpeggioDown", r"arpeggioArrowDown", str) + str = re.sub (r"arpeggioNeutral", r"arpeggioNormal", str) + str = re.sub (r"setTextCresc", r"crescTextCresc", str) + str = re.sub (r"setTextDecresc", r"dimTextDecresc", str) + str = re.sub (r"setTextDecr", r"dimTextDecr", str) + str = re.sub (r"setTextDim", r"dimTextDim", str) + str = re.sub (r"setHairpinCresc", r"crescHairpin", str) + str = re.sub (r"setHairpinDecresc", r"dimHairpin", str) + str = re.sub (r"sustainUp", r"sustainOff", str) + str = re.sub (r"sustainDown", r"sustainOn", str) + str = re.sub (r"sostenutoDown", r"sostenutoOn", str) + str = re.sub (r"sostenutoUp", r"sostenutoOff", str) return str +@rule ((2, 11, 52), "\\setHairpinDim -> \\dimHairpin") +def conv (str): + str = str.replace ("setHairpinDim", "dimHairpin") + return str - +@rule ((2, 11, 53), "infinite-spacing-height -> extra-spacing-height") def conv (str): - str = re.sub (r"arpeggioUp", r"arpeggioArrowUp", str) - return str + str = re.sub (r"infinite-spacing-height\s+=\s+##t", r"extra-spacing-height = #'(-inf.0 . +inf.0)", str) + str = re.sub (r"infinite-spacing-height\s+=\s+##f", r"extra-spacing-height = #'(0 . 0)", str) + return str -conversions.append (((2, 11, 51), conv, """\\arpeggioUp -> \\arpeggioArrowUp""")) +@rule ((2, 11, 55), "#(set-octavation oct) -> \\ottava #oct,\n\ +\\put-adjacent markup axis dir markup -> \\put-adjacent axis dir markup markup") +def conv (str): + str = re.sub (r"#\(set-octavation (-*[0-9]+)\)", r"\\ottava #\1", str) + if re.search ('put-adjacent', str): + stderr_write (NOT_SMART % _ ("\\put-adjacent argument order")) + stderr_write (_ ("Axis and direction now come before markups:\n")) + stderr_write (_ ("\\put-adjacent axis dir markup markup.")) + stderr_write ("\n") + return str +@rule ((2, 11, 57), "\\center-align -> \\center-column, \\hcenter -> \\center-align") +def conv (str): + str = re.sub (r"([\\:]+)center-align", r"\1center-column", str) + str = re.sub (r"hcenter(\s+)", r"center-align\1", str) + return str +@rule ((2, 11, 60), "printallheaders -> print-all-headers") def conv (str): - str = re.sub (r"arpeggioDown", r"arpeggioArrowDown", str) - return str + str = re.sub (r"printallheaders", r"print-all-headers", str) + return str -conversions.append (((2, 11, 51), conv, """\\arpeggioDown -> \\arpeggioArrowDown""")) +@rule ((2, 11, 61), "gregorian-init.ly -> gregorian.ly") +def conv (str): + str = re.sub (r'\\include(\s+)"gregorian-init.ly"', r'\\include\1"gregorian.ly"', str) + return str +@rule ((2, 11, 62), "makam-init.ly -> makam.ly, \\bigger -> \\larger") +def conv (str): + str = re.sub (r'\\include(\s+)"makam-init.ly"', r'\\include\1"makam.ly"', str) + str = re.sub (r"([\\:])bigger", r"\1larger", str) + return str +@rule ((2, 11, 64), "systemSeparatorMarkup -> system-separator-markup,\n\ +InnerStaffGroup -> StaffGroup, InnerChoirStaff -> ChoirStaff") def conv (str): - str = re.sub (r"arpeggioNeutral", r"arpeggioNormal", str) - return str + str = re.sub (r'systemSeparatorMarkup', r'system-separator-markup', str) + if re.search (r'\\InnerStaffGroup', str): + stderr_write (NOT_SMART % _("re-definition of InnerStaffGroup")) + stderr_write (FROM_TO % ("InnerStaffGroup", "StaffGroup")) + stderr_write (UPDATE_MANUALLY) + raise FatalConversionError () + if re.search (r'\\InnerChoirStaff', str): + stderr_write (NOT_SMART % _("re-definition of InnerChoirStaff")) + stderr_write (FROM_TO % ("InnerChoirStaff", "ChoirStaff")) + stderr_write (UPDATE_MANUALLY) + raise FatalConversionError () + else: + str = re.sub ('InnerStaffGroup', 'StaffGroup', str) + str = re.sub ('InnerChoirStaff', 'ChoirStaff', str) + return str -conversions.append (((2, 11, 51), conv, """\\arpeggioNeutral -> \\arpeggioNormal""")) +@rule ((2, 12, 0), + _ ("Syntax changes for \\addChordShape and \\chord-shape") + "\n" + \ + _ ("bump version for release")) +def conv(str): + if re.search(r'\\addChordShape', str): + stderr_write (NOT_SMART % "addChordShape") + stderr_write (_ ("stringTuning must be added to addChordShape call.\n")) + stderr_write (UPDATE_MANUALLY) + raise FatalConversionError () + if re.search (r'\\chord-shape', str): + stderr_write (NOT_SMART % "chord-shape") + stderr_write (_ ("stringTuning must be added to chord-shape call.\n")) + stderr_write (UPDATE_MANUALLY) + raise FatalConversionError () + return str + +@rule ((2,12,3), + _ ("Remove oldaddlyrics")) +def conv(str): + if re.search(r'\\oldaddlyrics', str): + stderr_write (NOT_SMART % "oldaddlyrics") + stderr_write (_ ("oldaddlyrics is no longer supported. \n \ + Use addlyrics or lyrsicsto instead.\n")) + stderr_write (UPDATE_MANUALLY) + raise FatalConversionError () + return str +@rule ((2, 13, 0), _ ("keySignature property not reversed any more\n\ +MIDI 47: orchestral strings -> orchestral harp")) +def conv(str): + if re.search(r'\set Staff.keySignature', str): + stderr_write (NOT_SMART % "Staff.keySignature") + stderr_write (_ ("The alist for Staff.keySignature is no \ +longer in reversed order.\n")) + str = str.replace('"orchestral strings"', '"orchestral harp"') + return str -def conv (str): - str = re.sub (r"setTextCresc", r"crescTextCresc", str) - return str +@rule ((2, 13, 1), + _ ("\\bar \".\" now produces a thick barline\n\ +ly:hairpin::after-line-breaking -> ly:spanner::kill-zero-spanned-time\n\ +Dash parameters for slurs and ties are now in dash-definition")) +def conv(str): + if re.search(r'\\bar\s*"\."', str): + stderr_write (NOT_SMART % "\\bar \".\"") + stderr_write (_ ("\\bar \".\" now produces a thick barline.\n")) + stderr_write (UPDATE_MANUALLY) + str = re.sub (r'ly:hairpin::after-line-breaking', r'ly:spanner::kill-zero-spanned-time', str) + if re.search("(Slur|Tie)\w+#\'dash-fraction", str) \ + or re.search("(Slur|Tie)\w+#\'dash-period", str): + stderr_write (NOT_SMART % "dash-fraction, dash-period") + stderr_write (_ ("Dash parameters for slurs and ties are now in \'dash-details.\n")) + stderr_write (UPDATE_MANUALLY) + return str + +@rule ((2, 13, 4), + _ ("Autobeaming rules have changed. override-auto-beam-setting and\n\ +revert-auto-beam-setting have been eliminated.\n\ +\\overrideBeamSettings has been added.\n\ +beatGrouping has been eliminated.\n\ +Different settings for vertical layout.\n\ +ly:system-start-text::print -> system-start-text::print\n\ +Beam #'thickness -> Beam #'beam-thickness\n\ +ly:note-head::brew-ez-stencil -> note-head::brew-ez-stencil\n\ +ly:ambitus::print -> ambitus::print\n\ +Explicit dynamics context definition from `Piano centered dynamics'\n\ +template replaced by new `Dynamics' context.")) +def conv(str): + if re.search("override-auto-beam-setting", str): + stderr_write (NOT_SMART % "override-auto-beam-setting") + stderr_write (_ (" \ + Autobeam settings are now overriden with \\overrideBeamSettings.\n")) + stderr_write (UPDATE_MANUALLY) + if re.search("revert-auto-beam-setting", str): + stderr_write (NOT_SMART % "override-auto-beam-setting") + stderr_write (_ (" \ + Autobeam settings are now reverted with \\revertBeamSettings.\n")) + stderr_write (UPDATE_MANUALLY) + str = re.sub(r"\\set\s+beatGrouping", r"\\setBeatGrouping", str) + if re.search(r"\w+\s*.\s*beatGrouping", str): + stderr_write (NOT_SMART % "beatGrouping") + stderr_write (_ (" \ + beatGrouping with a specified context must now be accomplished with\n\ + \\overrideBeamSettings.\n")) + stderr_write (UPDATE_MANUALLY) + if re.search(r'alignment-offsets', str): + stderr_write (NOT_SMART % "alignment-offsets") + stderr_write (_ ("alignment-offsets has been changed to alignment-distances: \ +you must now specify the distances between staves rather than the offset of staves.\n")) + stderr_write (UPDATE_MANUALLY) + str = re.sub ('ly:(system-start-text::print|note-head::brew-ez-stencil|ambitus::print)', + '\\1', str) + str = re.sub ('(\\bBeam\\s+#\')(?=thickness\\b)', '\\1beam-', str) + str = re.sub (r'(\\context\s*\{{1}[^\}]+\\type\s+\"?Engraver_group\"?\s+\\name\s+"*Dynamics"*[^\}]*\}{1})', + '% [Convert-ly] The Dynamics context is now included by default.', str) + return str + +@rule ((2, 13, 10), + _ ("Remove obsolete engravers/translators: Note_swallow_translator,\n\ +Rest_swallow_translator, Skip_event_swallow_translator, Swallow_engraver,\n\ +Swallow_performer and String_number_engraver.\n\ +New vertical spacing variables.")) +def conv(str): + str = re.sub (r'\\(consists|remove)\s+"*(Swallow_(engraver|performer)|' + '(Note|Rest|Skip_event)_swallow_translator|String_number_engraver)"*', + '', str) + + # match through the end of assignments in the form "x = 30", "x = 1 \in", or "x = #3" + str = re.sub (r"(page-top-space)\s*=\s*(([+-]?[.\d]*\s*\\[-\w]+)|(#?\s*[-+]?[.\d]+))", + r"obsolete-\g<0>" + r" top-system-spacing #'space = #(/ obsolete-\1 staff-space)", + str) + str = re.sub (r"(between-system-space)\s*=\s*(([+-]?[.\d]*\s*\\[-\w]+)|(#?\s*[-+]?[.\d]+))", + r"obsolete-\g<0>" + r" between-system-spacing #'space = #(/ obsolete-\1 staff-space)" + r" between-scores-system-spacing #'space = #(/ obsolete-\1 staff-space)", + str) + str = re.sub (r"(between-system-padding)\s*=\s*(([+-]?[.\d]*\s*\\[-\w]+)|(#?\s*[-+]?[.\d]+))", + r"obsolete-\g<0>" + r" between-system-spacing #'padding = #(/ obsolete-\1 staff-space)" + r" between-scores-system-spacing #'padding = #(/ obsolete-\1 staff-space)", + str) + str = re.sub (r"((before|between|after)-title-space)\s*=\s*(([+-]?[.\d]*\s*\\[-\w]+)|(#?\s*[-+]?[.\d]+))", + r"obsolete-\g<0>" + r" \2-title-spacing #'space = #(/ obsolete-\1 staff-space)", + str) -conversions.append (((2, 11, 51), conv, """\\setTextCresc -> \\crescTextCresc""")) + if re.search(r"VerticalAxisGroup\s*#\s*'minimum-Y-extent", str): + stderr_write (NOT_SMART % "minimum-Y-extent") + stderr_write (_ ("Vertical spacing no longer depends on the Y-extent of a VerticalAxisGroup.\n")) + stderr_write (UPDATE_MANUALLY) + return str -def conv (str): - str = re.sub (r"setTextDecresc", r"dimTextDecresc", str) - return str +@rule ((2, 13, 16), + _ ("Unify fetaNumber and fetaDynamic encodings")) +def conv(str): + return re.sub(r'\bfeta(Number|Dynamic)', 'fetaText', str) -conversions.append (((2, 11, 51), conv, """\\setTextDecresc -> \\dimTextDecresc""")) +@rule ((2, 13, 18), + _ ("\\RemoveEmpty*StaffContext -> \\*Staff \\RemoveEmptyStaves")) +def conv(str): + str = re.sub (r"\\RemoveEmpty(|Drum|Rhythmic|Tab)StaffContext", + r"\\\1Staff \\RemoveEmptyStaves", + str); + str = re.sub (r"\\AncientRemoveEmptyStaffContext", + r"\\VaticanaStaff \\RemoveEmptyStaves", + str); + return str +@rule ((2, 13, 20), + _ ("\\cresc etc. are now postfix operators")) +def conv (str): + str = re.sub (r'\\(cresc|dim|endcresc|enddim)\b', r'\\deprecated\1', str) + return str +@rule ((2, 13, 27), + ("interval-translate -> coord-translate")) def conv (str): - str = re.sub (r"setTextDecr", r"dimTextDecr", str) - return str + str = re.sub ('interval-translate', 'coord-translate', str) + return str + +@rule ((2, 13, 29), + _ ("Eliminate beamSettings, beatLength, \\setBeatGrouping, \\overrideBeamSettings and \\revertBeamSettings.\n\ +\"accordion.accEtcbase\" -> \"accordion.etcbass\"")) +def conv(str): + def sub_acc (m): + d = { + 'Dot': 'dot', + 'Discant': 'discant', + 'Bayanbase': 'bayanbass', + 'Stdbase': 'stdbass', + 'Freebase': 'freebass', + 'OldEE': 'oldEE' + } + return '"accordion.%s"' % d[m.group (1)] + + str = re.sub (r'"accordion\.acc([a-zA-Z]+)"', + sub_acc, str) + if re.search(r'overrideBeamSettings', str): + stderr_write (NOT_SMART % "\\overrideBeamSettings") + stderr_write (_ ("Use \\set beamExceptions or \\overrideTimeSignatureSettings.\n")) + stderr_write (UPDATE_MANUALLY) + if re.search(r'revertBeamSettings', str): + stderr_write (NOT_SMART % "\\revertBeamSettings") + stderr_write (_ ("Use \\set beamExceptions or \\revertTimeSignatureSettings.\n")) + stderr_write (UPDATE_MANUALLY) + if re.search(r'beamSettings', str): + stderr_write (NOT_SMART % "beamSettings") + stderr_write (_ ("Use baseMoment, beatStructure, and beamExceptions.\n")) + stderr_write (UPDATE_MANUALLY) + if re.search(r'beatLength', str): + stderr_write (NOT_SMART % "beatLength") + stderr_write (_ ("Use baseMoment and beatStructure.\n")) + stderr_write (UPDATE_MANUALLY) + if re.search(r'setBeatGrouping', str): + stderr_write (NOT_SMART % "setbeatGrouping") + stderr_write (_ ("Use baseMoment and beatStructure.\n")) + stderr_write (UPDATE_MANUALLY) + return str + +@rule ((2, 13, 31), + _ ("Woodwind diagrams: Move size, thickness, and graphic from argument list to properties.\n\ +Deprecate negative dash-period for hidden lines: use #'style = #'none instead.")) +def conv(str): + if re.search(r'woodwind-diagram', str): + stderr_write (NOT_SMART % "woodwind-diagrams") + stderr_write (_ ("Move size, thickness, and graphic to properties. Argument should be just the key list.\n")) + stderr_write (UPDATE_MANUALLY) + str = re.sub (r"dash-period\s+=\s*#\s*-[0-9.]+", + r"style = #'none", + str); + return str + +@rule ((2, 13, 36), + _ ("Rename vertical spacing variables.\n\ +Add fretboard-table argument to savePredefinedFretboard.")) +def conv(str): + str = re.sub ('after-title-spacing', 'markup-system-spacing', str) + str = re.sub ('before-title-spacing', 'score-markup-spacing', str) + str = re.sub ('between-scores-system-spacing', 'score-system-spacing', str) + # this rule also converts page-breaking-between-system-spacing: + str = re.sub ('between-system-spacing', 'system-system-spacing', str) + str = re.sub ('between-title-spacing', 'markup-markup-spacing', str) + str = re.sub ('bottom-system-spacing', 'last-bottom-spacing', str) + str = re.sub ('top-title-spacing', 'top-markup-spacing', str) + + str = re.sub (r"storePredefinedDiagram", + r"storePredefinedDiagram #default-fret-table", + str); + return str + +@rule ((2, 13, 39), + _ ("Rename vertical spacing grob properties.")) +def conv(str): + # this rule also converts default-next-staff-spacing: + str = re.sub ('next-staff-spacing', 'staff-staff-spacing', str) + # this is not a mistake: + # Both 'next- and 'between- become 'staff-staff-spacing. + # There is no conflict since they are in different grobs. + str = re.sub ('between-staff-spacing', 'staff-staff-spacing', str) + str = re.sub ('after-last-staff-spacing', 'staffgroup-staff-spacing', str) + str = re.sub ('inter-staff-spacing', 'nonstaff-relatedstaff-spacing', str) + str = re.sub ('non-affinity-spacing', 'nonstaff-unrelatedstaff-spacing', str) + str = re.sub ('inter-loose-line-spacing', 'nonstaff-nonstaff-spacing', str); -conversions.append (((2, 11, 51), conv, """\\setTextDecr -> \\dimTextDecr""")) + return str +@rule ((2, 13, 40), + _ ("Remove \\paper variables head-separation and foot-separation.")) +def conv(str): + if re.search (r'head-separation', str): + stderr_write (NOT_SMART % "head-separation") + stderr_write (_ ("Adjust settings for top-system-spacing instead.\n")) + stderr_write (UPDATE_MANUALLY) + if re.search (r'foot-separation', str): + stderr_write (NOT_SMART % "foot-separation") + stderr_write (_ ("Adjust settings for last-bottom-spacing instead.\n")) + stderr_write (UPDATE_MANUALLY); -def conv (str): - str = re.sub (r"setTextDim", r"dimTextDim", str) - return str + return str + +@rule ((2, 13, 42), + _ ("Rename space to basic-distance in various spacing alists.\n\ +Remove HarmonicParenthesesItem grob.")) +def conv(str): + str = re.sub (r'\(space\s+\.\s+([0-9]*\.?[0-9]*)\)', r'(basic-distance . \1)', str) + str = re.sub (r"#'space\s+=\s+#?([0-9]*\.?[0-9]*)", r"#'basic-distance = #\1", str) + if re.search (r'HarmonicParenthesesItem', str): + stderr_write (NOT_SMART % "HarmonicParenthesesItem") + stderr_write (_ ("HarmonicParenthesesItem has been eliminated.\n")) + stderr_write (_ ("Harmonic parentheses are part of the TabNoteHead grob.\n")) + stderr_write (UPDATE_MANUALLY); + return str + +@rule ((2, 13, 44), + _ ("Remove context from overrideTimeSignatureSettings and revertTimeSignatureSettings.\n")) + +def conv(str): + str = re.sub (r"\\(override|revert)TimeSignatureSettings(\s+[^#]*)(#[^#]*)#", r"\\\1TimeSignatureSettings\2#", str) + return str + +@rule ((2, 13, 46), + _ ("Change stringTunings from a list of semitones to a list of pitches.\n"\ + "Change tenor and baritone ukulele names in string tunings.\n"\ + "Generate messages for manual conversion of vertical spacing if required.")) + +def conv(str): + def semitones2pitch(semitones): + steps = [0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6] + alterations = ["NATURAL", "SHARP", "NATURAL", "SHARP", "NATURAL", "NATURAL", "SHARP", "NATURAL", "SHARP", "NATURAL", "SHARP", "NATURAL"] + octave = 0 + while semitones > 11: + octave += 1 + semitones -=12 + while semitones < 0: + octave -= 1 + semitones += 12 + pitchArgs = "%d %d %s" % (octave, steps[semitones], alterations[semitones]) + return pitchArgs + + def convert_tones (semitone_list): + tones = semitone_list.split () + res = "" + for tone in tones: + args = semitones2pitch(int(tone)) + res += ",(ly:make-pitch " + args + ") " + return res + + def new_tunings (matchobj): + return "stringTunings = #`(" + convert_tones(matchobj.group(1)) + ")" + str = re.sub (r"stringTunings\s*=\s*#'\(([\d\s-]*)\)", \ + new_tunings , str) + + str = re.sub (r"ukulele-(tenor|baritone)-tuning", r"\1-ukulele-tuning", str) + + if re.search (r"[^-]page-top-space", str): + stderr_write (NOT_SMART % "page-top-space") + stderr_write (UPDATE_MANUALLY) + if re.search (r"[^-]between-system-(space|padding)", str): + stderr_write (NOT_SMART % "between-system-space, -padding") + stderr_write (UPDATE_MANUALLY) + if re.search (r"[^-](before|between|after)-title-space", str): + stderr_write (NOT_SMART % "before-, between-, after-title-space") + stderr_write (UPDATE_MANUALLY) + if re.search (r"\\name\s", str): + stderr_write ("\n" + _("Vertical spacing changes might affect user-defined contexts.") + "\n") + stderr_write (UPDATE_MANUALLY) + + return str + +@rule ((2, 13, 48), + _ ("Replace bar-size with bar-extent.")) + +def conv(str): + def size_as_extent (matchobj): + half = "%g" % (float (matchobj.group (1)) / 2) + return "bar-extent = #'(-" + half + " . " + half + ")" + + str = re.sub (r"bar-size\s*=\s*#([0-9\.]+)", size_as_extent, str) -conversions.append (((2, 11, 51), conv, """\\setTextDim -> \\dimTextDim""")) + return str +@rule ((2, 13, 51), + _ ("Woodwind diagrams: Changes to the clarinet diagram.")) +def conv(str): + if re.search (r'\\woodwind-diagram\s*#[^#]*clarinet\s', str): + stderr_write (NOT_SMART % "woodwind-diagrams") + stderr_write (_ ("Clarinet fingering changed to reflect actual anatomy of instrument.\n")) + stderr_write (UPDATE_MANUALLY) + return str +@rule ((2, 14, 0), + _ ("bump version for release")) def conv (str): - str = re.sub (r"setHairpinCresc", r"crescHairpin", str) - return str + return str -conversions.append (((2, 11, 51), conv, """\\setHairpinCresc -> \\crescHairpin""")) +@rule ((2, 15, 7), + _ ("Handling of non-automatic footnotes.")) +def conv(str): + if re.search (r'\\footnote', str): + stderr_write (NOT_SMART % "\\footnote") + stderr_write (_ ("If you are using non-automatic footnotes, make sure to set footnote-auto-numbering = ##f in the paper block.\n")) + stderr_write (UPDATE_MANUALLY) + return str + +@rule ((2, 15, 9), + _ ("Change in internal property for MultiMeasureRest")) +def conv (str): + if re.search (r'use-breve-rest',str): + stderr_write (NOT_SMART % "use-breve-rest") + stderr_write (_ ("This internal property has been replaced by round-up-to-longer-rest, round-up-exceptions and usable-duration-logs.\n")) + stderr_write (UPDATE_MANUALLY) + return str +@rule ((2, 15, 10), + _ ("Creation of a Flag grob and moving of certain Stem properties to this grob")) +def conv (str): + str = re.sub (r"Stem\s+#'flag-style", r"Flag #'style", str) + str = re.sub (r"Stem\s+#'stroke-style", r"Flag #'stroke-style", str) + str = re.sub (r"Stem\s+#'flag", r"Flag #'stencil", str) + str = re.sub (r"(\s+(?:\\once\s*)?)\\override\s+Stem\s+#'transparent\s*=\s*##t", r"\g<1>\\override Stem #'transparent = ##t\g<1>\\override Flag #'transparent = ##t", str) + str = re.sub (r"(\s+(?:\\once\s*)?)\\revert\s*Stem\s+#'transparent", r"\g<1>\\revert Stem #'transparent\g<1>\\revert Flag #'transparent", str) + str = re.sub (r"(\s+(?:\\once\s*)?)\\override\s+Stem\s+#'stencil\s*=\s*##f", r"\g<1>\\override Stem #'stencil = ##f\g<1>\\override Flag #'stencil = ##f", str) + str = re.sub (r"(\s+(?:\\once\s*)?)\\revert\s*Stem\s+#'stencil", r"\g<1>\\revert Stem #'stencil\g<1>\\revert Flag #'stencil", str) + return str +@rule ((2, 15, 16), r"\makeStringTuning, \contextStringTuning -> \stringTuning") +def conv (str): + str = re.sub (r"(\s+)\\contextStringTuning(\s+)#'([-a-zA-Z]+)(\s+<[^<>]+>)", + r"""\g<1>#(define \g<3> #{ \\stringTuning\g<4> #})\g<1>\\set stringTunings = #\g<3>""", + str) + str = re.sub (r""" +\\makeStringTuning(\s+)#'([-a-zA-Z]+)""", + r""" +"\g<2>" = \\stringTuning""", str) + str = re.sub (r"\\makeStringTuning(\s+)#'([-a-zA-Z]+)(\s+<[^<>]+>)", + r"#(define \g<2> #{ \\stringTuning\g<3> #})", str) + return str + +@rule ((2, 15, 17), "\\markuplines -> \\markuplist\n\ +Change Beam broken slope syntax.") +def conv (str): + str = re.sub (r""" +\\markuplines( +)([^ ].*) + \1([^ ])""", r""" +\\markuplist\g<1>\g<2> + \g<1>\g<3>""", str) + str = re.sub (r"\\markuplines", r"\\markuplist", str) + str = re.sub (r"@funindex markuplines", r"@funindex markuplist", str) + if re.search (r'consistent-broken-slope', str): + stderr_write (NOT_SMART % "consistent-broken-slope") + stderr_write (_ ("consistent-broken-slope is now handled through the positions callback.\n")) + stderr_write (_ ("input/regression/beam-broken-classic.ly shows how broken beams are now handled.\n")) + stderr_write (UPDATE_MANUALLY) + return str + +def paren_matcher (n): + # poor man's matched paren scanning, gives up + # after n+1 levels. Matches any string with balanced + # parens inside; add the outer parens yourself if needed. + # Nongreedy. + return r"[^()]*?(?:\("*n+r"[^()]*?"+r"\)[^()]*?)*?"*n + return + +def undollar_scm (m): + return re.sub (r"\$(.?)", r"\1", m.group (0)) + +def undollar_embedded (m): + str = re.sub (r"#\$", "#", m.group (1)) + # poor man's matched paren scanning after #, gives up + # after 25 levels. + str = re.sub ("#`?\("+paren_matcher (25)+"\)", undollar_scm, str) + return m.string[m.start (0):m.start (1)] + str + m.string[m.end (1):m.end (0)] + +def strip_export (str): + return re.sub (r"\(ly:export\s+(" + paren_matcher (25) + r")\)", + r"\1", str) + +def export_puller (m): + if not re.search (r"ly:export\s+", m.group (0)): + return m.group (0) + return "$" + strip_export (m.string[m.start (0)+1:m.end (0)]) + +def ugly_function_rewriter (m): + return m.string[m.start(0):m.start(1)] + strip_export (m.group (1)) + m.string[m.end(1):m.end(0)] + +should_really_be_music_function = "(?:\ +set-time-signature|empty-music|add-grace-property|\ +remove-grace-property|set-accidental-style)" + +def record_ugly (m): + global should_really_be_music_function + if not re.match (should_really_be_music_function, m.group (1)) \ + and re.search (r"ly:export\s+", m.group (2)): + should_really_be_music_function = \ + should_really_be_music_function[:-1] + "|" + m.group (1) + ")" + return m.group (0) + +@rule ((2, 15, 18), "#$ -> #, ly:export -> $") +def conv (str): + str = re.sub (r"(?s)#@?\{(.*?)#@?\}", undollar_embedded, str) + str = re.sub (r"#\(define(?:-public)?\s+\(([-a-zA-Z]+)" + + r"\b[^()]*?\)(" + paren_matcher (25) + + r")\)", record_ugly, str) + str = re.sub (r"\(define(?:-public)?\s+\(" + should_really_be_music_function + + r"\b[^()]*\)(" + paren_matcher (25) + + r")\)", ugly_function_rewriter, str) + str = re.sub (r"#(?=\(" + should_really_be_music_function + ")", "$", str) + str = re.sub (r"#\(markup\*(?=\s)", r"$(markup", str) + str = re.sub ("#\("+paren_matcher (25)+"\)", export_puller, str) + if re.search (r"\(ly:export\s+", str): + stderr_write (NOT_SMART % "ly:export") + return str + +@rule ((2, 15, 19), r"$(set-time-signature ...) -> \time") +def conv (str): + str = re.sub (r"\$\(set-time-signature\s+([0-9]+)\s+([0-9]+)\s*\)", + r"\\time \1/\2", str) + str = re.sub (r"\$\(set-time-signature\s+([0-9]+)\s+([0-9]+)\s+(" + + paren_matcher (5) + r")\)", r"\\time #\3 \1/\2", str) + if re.search (r"\(set-time-signature\s+", str): + stderr_write (NOT_SMART % "set-time-signature") + return str + +@rule ((2, 15, 20), r"$(set-accidental-style ...) -> \accidentalStyle") +def conv (str): + str = re.sub (r"\$\(set-accidental-style\s+'([-a-z]+)\)", + r'\\accidentalStyle "\1"', str) + str = re.sub (r"\$\(set-accidental-style\s+'([-a-z]+)\s+'([-A-Za-z]+)\s*\)", + r'''\\accidentalStyle #'\2 "\1"''', str) + str = re.sub (r"(@funindex\s+)set-accidental-style", + r"\1\\accidentalStyle", str) + return str + +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): - str = re.sub (r"setHairpinDecresc", r"dimHairpin", str) - return 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) -conversions.append (((2, 11, 51), conv, """\\setHairpinDecresc -> \\dimHairpin""")) + 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"sustainUp", r"sustainOff", str) - return str + str = re.sub (r"(\\set\s+)stringTuning", r"\1Staff.stringTuning", str) + return str -conversions.append (((2, 11, 51), conv, """\\sustainUp -> \\sustainOff""")) +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): - str = re.sub (r"sustainDown", r"sustainOn", str) - return str + return str -conversions.append (((2, 11, 51), conv, """\\sustainDown -> \\sustainOn""")) +@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"sostenutoDown", r"sostenutoOn", str) - return 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 + +@rule ((2, 17, 11), r"""\times -> \tuplet, \set tupletSpannerDuration -> \tupletSpan +(ly:make-moment 1 4) -> (ly:make-moment 1/4) +(ly:make-duration 0 0 1 2) -> (ly:make-duration 0 0 1/2)""") +def conv(str): + def sub_dur (m): + num = int (m.group (1)) + den = int (m.group (2)) + +# if den is no power of 2, don't even try to use an unscaled duration + if (den & (den - 1)) != 0 : + return (r"\tupletSpan 1*%d/%d" % (num, den)) + + if den >= 4 and num == 7 : + return (r"\tupletSpan %d.." % (den/4)) + + if den >= 2 and num == 3 : + return (r"\tupletSpan %d." % (den/2)) + + if num == 1 : + return (r"\tupletSpan %d" % den) + + return (r"\tupletSpan 1*%d/%d" % (num, den)) + + str = re.sub (r"\\set\s+tupletSpannerDuration\s*=\s*" + + r"#\(ly:make-moment\s+([0-9]+)\s+([0-9]+)\s*\)", + sub_dur, str) + str = re.sub (r"\\unset tupletSpannerDuration", + r"\\tupletSpan \\default", str) + str = re.sub (r"\\times(\s*)([0-9]+)/([0-9]+)", + r"\\tuplet\1\3/\2", str) + + str = re.sub (r"(\(ly:make-moment\s+-?[0-9]+)\s+([1-9][0-9]*\))", + r"\1/\2", str) + str = re.sub (r"(\(ly:make-moment\s+-?[0-9]+)\s+([0-9]+\s+-?[0-9]+)\s([0-9]+\))", + r"\1/\2/\3", str) + str = re.sub (r"(\(ly:make-duration\s+-?[0-9]+\s+[0-9]+\s+[0-9]+)\s+([0-9]+\))", + r"\1/\2", str) + return str + +@rule((2, 17, 14), r"\accepts ... -> \accepts ... \defaultchild ...") +def conv(str): + def matchaccepts(m): + # First weed out definitions starting from an existing + # definition: we assume that the inherited \defaultchild is + # good enough for our purposes. Heuristic: starts with a + # backslash and an uppercase letter. + if re.match (r"\s*\\[A-Z]", m.group (1)): + return m.group (0) + # existing defaultchild obviously trumps all + if re.search (r"\\defaultchild[^-_a-zA-Z]", m.group (1)): + return m.group (0) + # take the first \\accepts if any and replicate it + return re.sub ("(\r?\n[ \t]*|[ \t]+)" + + r"""\\accepts(\s+(?:#?".*?"|[-_a-zA-Z]+))""", + r"\g<0>\1\\defaultchild\2", + m.group (0), 1) + + str = re.sub (r"\\context\s*@?\{(" + brace_matcher (20) + ")\}", + matchaccepts, str) + return str + +@rule((2, 17, 15), r"""#(ly:set-option 'old-relative) +\relative -> \relative c'""") +def conv(str): + if re.search (r"[#$]\(ly:set-option\s+'old-relative", str): + stderr_write (NOT_SMART % "#(ly:set-option 'old-relative)") + stderr_write (UPDATE_MANUALLY) + raise FatalConversionError (); + # If the file contains a language switch to a language where the + # name of c is not "c", we can't reliably know which parts of the + # file will need "c" and which need "do". + m = re.search (r'\\language\s(?!\s*#?"(?:nederlands|deutsch|english|norsk|suomi|svenska))"', str) + if m: + # Heuristic: if there is a non-commented { before the language + # selection, we can't be sure. + # Also if there is any selection of a non-do language. + if (re.search ("^[^%\n]*\\{", m.string[:m.start()], re.M) + or re.search ('\\language\s(?!\s*#?"(?:catalan|espanol|español|italiano|français|portugues|vlaams))"', str)): + do = "$(ly:make-pitch 0 0)" + else: + do = "do'" + else: + do = "c'" + str = re.sub (r"(\\relative)(\s+(\{|[\\<]))", + r"\1 " + do + r"\2", str) + return str + +@rule ((2, 17, 18), + "Rename OctavateEight to ClefModifier, rename related properties.") +def conv(str): + str = re.sub ('OctavateEight', 'ClefModifier', str) + str = re.sub ('octavate-eight-interface', 'clef-modifier-interface', str) + str = re.sub ('clefOctavation', 'clefTransposition', str) + str = re.sub ('clefOctavationFormatter', 'clefTranspositionFormatter', str) + str = re.sub ('clefOctavationStyle', 'clefTranspositionStyle', str) + str = re.sub ('cueClefOctavation', 'cueClefTransposition', str) + str = re.sub ('cueClefOctavationFormatter', 'cueClefTranspositionFormatter', str) + str = re.sub ('cueClefOctavationStyle', 'cueClefTranspositionStyle', str) + return str + +@rule((2, 17, 19), r"\column { \vspace #2 } -> \column { \combine \null \vspace #2 }") +def conv(str): + def vspace_replace(m): + +# vspace now always adds space and does not, for example, change the +# impact of either baselineskip or descenders on the line above. +# +# We can't simulate the old behavior in a simpler manner. A command +# of its own is not really warranted since this behavior combines +# badly enough with other spacing considerations (like baselineskip +# and descenders) as to make it not all that useful. So this +# conversion rule is here more for compatibility's sake rather than +# preserving desirable behavior. + + str = re.sub (r"(\\\\?)vspace(\s)", r"\1combine \1null \1vspace\2", m.group(0)) + return str + + str = re.sub (r"\\(?:left-|right-|center-|)column\s*\{" + brace_matcher (20) + r"\}", + vspace_replace, str) + return str + +@rule((2, 17, 20), _(r"Flag.transparent and Flag.color inherit from Stem")) +def conv(str): + str = re.sub (r"(((?:\\once\s*)?)\\override\s+((?:\w+\.)?)Stem\.(transparent|color)\s*=\s*(#\S+))\s+\2\\override\s+\3Flag\.\4\s*=\s*\5", + r"\1", str) + str = re.sub (r"(((?:\\once\s*)?)\\revert\s+((?:\w+\.)?)Stem\.(transparent|color))\s+\2\\revert\s+\3Flag\.\4", + r"\1", str) + str = re.sub (r"(\\tweak\s+((?:\w+\.)?)Stem\.(transparent|color)\s+(#\S+))\s+\\tweak\s+\2Flag\.\3\s+\4", + r"\1", str) + return str -conversions.append (((2, 11, 51), conv, """\\sostenutoDown -> \\sostenutoOn""")) +@rule((2, 17, 25), r'''\tempo 4. = 50~60 -> \tempo 4. = 50-60 +-| -> -! +pipeSymbol, escapedParenthesisOpenSymbol ... -> "|", "\\(" ...''') +def conv(str): +# This goes for \tempo commands ending with a range, like +# = 50 ~ 60 +# and uses - instead. We don't explicitly look for \tempo since the +# complete syntax has a large number of variants, and this is quite +# unlikely to occur in other contexts + str = re.sub (r"(=\s*[0-9]+\s*)~(\s*[0-9]+\s)", r"\1-\2", str) +# Match strings, and articulation shorthands that end in -^_ +# so that we leave alone -| in quoted strings and c4--| + def subnonstring(m): + if m.group (1): + return m.group (1)+"!" + return m.group (0) + str = re.sub (r"([-^_])\||" + matchstring + r"|[-^_][-^_]", subnonstring, str) + str = re.sub (r"\bdashBar\b", "dashBang", str) + orig = [ "pipeSymbol", + "bracketOpenSymbol", + "bracketCloseSymbol", + "tildeSymbol", + "parenthesisOpenSymbol", + "parenthesisCloseSymbol", + "escapedExclamationSymbol", + "escapedParenthesisOpenSymbol", + "escapedParenthesisCloseSymbol", + "escapedBiggerSymbol", + "escapedSmallerSymbol" ] + repl = [ r'"|"', + r'"["', + r'"]"', + r'"~"', + r'"("', + r'")"', + r'"\\!"', + r'"\\("', + r'"\\)"', + r'"\\>"', + r'"\\<"'] + words = r"\b(?:(" + ")|(".join (orig) + r"))\b" + def wordreplace(m): + def instring(m): + return re.sub (r'["\\]',r'\\\g<0>',repl[m.lastindex-1]) + if m.lastindex: + return repl[m.lastindex-1] + return '"' + re.sub (words, instring, m.group(0)[1:-1]) + '"' + str = re.sub (words + "|" + matchstring, wordreplace, str) + return str + +@rule((2, 17, 27), r'''\stringTuning \notemode -> \stringTuning''') +def conv(str): + str = re.sub (r"\\stringTuning\s*\\notemode(\s*)@?\{\s*(.*?)\s*@?}", + r"\\stringTuning\1\2", str) + if re.search (r'[^-\w]staff-padding[^-\w]', str): + stderr_write (NOT_SMART % "staff-padding") + stderr_write (_ ("Staff-padding now controls the distance to the baseline, not the nearest point.")) + return str + +@rule((2, 17, 29), r'''Dynamic_engraver -> New_dynamic_engraver+Dynamic_align_engraver +New_dynamic_engraver -> Dynamic_engraver''') +def conv(str): + str = re.sub ("(\r?\n?[ \t]*\\\\(?:consists|remove)\\s*)(\"?)Dynamic_engraver\\2", + r"\1\2New_dynamic_engraver\2\1\2Dynamic_align_engraver\2", + str) +# Should we warn about any remaining Dynamic_engraver? Possibly it +# will do the job just fine. + str = re.sub ("New_dynamic_engraver", "Dynamic_engraver", str) + return str +@rule ((2, 17, 97), r'''(make-relative (a b) b ...) -> make-relative (a b) #{ a b #}...''') +def conv (str): + str = re.sub (r"(\(make-relative\s+\(\s*(([A-Za-z][-_A-Za-z0-9]*)" + + r"(?:\s+[A-Za-z][-_A-Za-z0-9]*)*)\s*\)\s*)\3(?=\s)", + r"\1(make-event-chord (list \2))", str) + str = re.sub (r"(\(make-relative\s+\(\s*([A-Za-z][-_A-Za-z0-9]*" + + r"(?:\s+([A-Za-z][-_A-Za-z0-9]*))+)\s*\)\s*)\3(?=\s)", + r"\1(make-sequential-music (list \2))", str) + return str +@rule ((2, 18, 0), + _ ("bump version for release")) def conv (str): - str = re.sub (r"sostenutoUp", r"sostenutoOff", str) - return str + return str -conversions.append (((2, 11, 51), conv, """\\sostenutoUp -> \\sostenutoOff""")) +# 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, +# concatenate them into a single "conv" function; +# +# - enclose strings to be localized with `_(' and `)'; +# +# - write rule for bumping major stable version with +# +# _ ("bump version for release") +# +# as exact description.