]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/convert-ly.py
Changed scripts/* to use sys.argv[0]
[lilypond.git] / scripts / convert-ly.py
index 4272e0fb65f56bddf050ddd015d93dccb531aa44..b683a293f33bfffdd4c98816fff3525620332825 100644 (file)
@@ -15,9 +15,6 @@
 # 0.2
 #  - rewrite in python
 
-program_name = 'convert-ly'
-version = '@TOPLEVEL_VERSION@'
-
 import os
 import sys
 import __main__
@@ -26,9 +23,13 @@ import  string
 import re
 import time
 
+program_name = sys.argv[0]
+
+version = '@TOPLEVEL_VERSION@'
+
 # Did we ever have \mudela-version?  I doubt it.
 # lilypond_version_re_str = '\\\\version *\"(.*)\"'
-lilypond_version_re_str = '\\\\(mudela-)?version *\"(.*)\"'
+lilypond_version_re_str = '\\\\(mudela-)?version *\"([^"]+)\"'
 lilypond_version_re = re.compile (lilypond_version_re_str)
 add_version = 1
 
@@ -148,7 +149,7 @@ if 1:                                       # need new a namespace
                return str
 
        conversions.append ((
-               ((0,1,20), conv, 'deprecated \\textstyle, new \key syntax')))
+               ((0,1,20), conv, 'deprecated \\textstyle, new \\key syntax')))
 
 
 if 1:
@@ -402,7 +403,7 @@ if 1:
                return str
 
        conversions.append (((1,3,4), conv,
-                '\\cadenza -> \cadenza{On|Off}'))
+                '\\cadenza -> \\cadenza{On|Off}'))
 
 if 1:
        def conv (str):
@@ -1406,6 +1407,17 @@ if 1:
                str = re.sub (r'@ACCENT@', '>', str)
                return str
 
+       def text_markup (str):
+               str = re.sub (r"""([-_^]) *# *' *\( *music *(\"[^"]*\") *\)""",
+                               r"\1\\markup { \\musicglyph #\2 }", str)
+               str = re.sub (r"""([-_^]) *# *' *\( *([a-z]+) *([^()]*)\)""",
+                               r"\1\\markup { \\\2 \3 }", str)
+               str = re.sub (r"""\\mark *# *' *\( *music *(\"[^"]*\") *\)""",
+                               r"\\mark \\markup { \\musicglyph #\1 }", str)
+               str = re.sub (r"""\\mark *# *' *\( *([a-z]+) *([^()]*)\)""",
+                               r"\\mark \\markup { \\\1 \2 }", str)
+               return str      
+
        def articulation_substitute (str):
                str = re.sub (r"""([^-])\[ *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
                              r"\1 \2[", str)
@@ -1428,13 +1440,14 @@ if 1:
                str =  conv_relative (str)
                str = sub_chords (str)
 
+               str = text_markup (str)
                str = articulation_substitute (str)
                str = re.sub ("@SCM_EOL@", "#'()", str)
                
                return str
        
        conversions.append (((1,9,0), conv, """New relative mode,
-Postfix articulations, new chord syntax."""))
+Postfix articulations, new text markup syntax, new chord syntax."""))
 
 if 1:
        def conv (str):
@@ -1613,7 +1626,7 @@ def conv (str):
        def func(match):
                return "#'font-size = #%d" % (2*string.atoi (match.group (1))) 
                
-       str =re.sub (r"#'font-relative-size\s*=\s*#([0-9-]+)", func, str)
+       str =re.sub (r"#'font-relative-size\s*=\s*#\+?([0-9-]+)", func, str)
        str =re.sub (r"#'font-family\s*=\s*#'ancient",
                     r"#'font-family = #'music", str)
        
@@ -1977,7 +1990,7 @@ def conv (str):
                elif o >= 0:
                        str += "'" * (o + 1)
                        
-               return '\\tuning %s ' % str
+               return '\\transposition %s ' % str
 
        
        str = re.sub (r"\\set ([A-Za-z]+\s*\.\s*)?transposing\s*=\s*#([-0-9]+)",
@@ -2070,6 +2083,118 @@ def conv (str):
 conversions.append (((2,2, 0), conv,
                     '''clean up version. '''))
 
+def conv (str):
+       return re.sub (r'\\apply\b', r'\\applymusic', str)
+
+conversions.append (((2, 3, 1), conv,
+                    '''\\apply -> \\applymusic'''))
+
+def conv (str):
+       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)
+               
+               
+       str = re.sub (r'\\([a-zA-Z]+)Context\b', func, str)
+
+       str = re.sub ('ly:paper-lookup', 'ly:output-def-lookup', str)
+       return str
+
+conversions.append (((2, 3, 2), conv,
+                    '''\\FooContext -> \\Foo'''))
+
+def conv (str):
+       str = re.sub (r'\\notes\b', '', str)
+       
+       return str
+
+conversions.append (((2, 3, 4), conv,
+                    '''remove \\notes'''))
+
+
+
+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)
+       return str
+
+conversions.append (((2, 3, 8), conv,
+                    '''remove \\consistsend, strip \\lyrics from \\lyricsto.'''))
+
+def conv (str):
+       str = re.sub (r'neo_mensural', 'neomensural', str)
+       str = re.sub (r'if-text-padding', 'bound-padding', str)
+       return str
+
+conversions.append (((2, 3, 9), conv,
+                    '''neo_mensural -> neomensural, if-text-padding -> bound-padding'''))
+
+
+
+def conv (str):
+       str = re.sub (r'\\addlyrics', r'\\oldaddlyrics', str)
+       str = re.sub (r'\\newlyrics', r'\\addlyrics', str)
+       return str
+
+conversions.append (((2, 3, 10), conv,
+                    '''\\addlyrics -> \\oldaddlyrics, \\newlyrics -> \\addlyrics'''))
+
+def conv (str):
+       str = re.sub (r'\\setMmRestFermata\s+(R[0-9.*/]*)',
+                     r'\1^\\fermataMarkup', str)
+       return str
+
+conversions.append (((2, 3, 11), conv,
+                    '''\\setMmRestFermata -> ^\\fermataMarkup'''))
+
+def conv (str):
+       str = re.sub (r'\\newpage', r'\\pageBreak', str)
+       str = re.sub (r'\\scriptUp', r"""{
+  \\override TextScript  #'direction = #1
+  \\override Script  #'direction = #1
+}""", str)
+       str = re.sub (r'\\scriptDown', r"""{
+  \\override TextScript  #'direction = #-1
+  \\override Script  #'direction = #-1
+}""", str)
+       str = re.sub (r'\\scriptBoth', r"""{
+  \\revert TextScript  #'direction
+  \\override Script  #'direction
+}""", str)
+       str = re.sub ('soloADue', 'printPartCombineTexts', str)
+       str = re.sub (r'\\applymusic\s*#notes-to-clusters',
+                     '\\makeClusters', str)
+       return str
+
+conversions.append (((2, 3, 12), conv,
+                    '''\\newpage -> \\pageBreak, junk \\script{up,down,both},
+soloADue -> printPartCombineTexts, #notes-to-clusters -> \\makeClusters
+'''))
+
+
+def conv_mode_experiment (str):
+       str = re.sub (r'\\chords\b', r'\\chordmode', str)
+       str = re.sub (r'\\lyrics\b', r'\\lyricmode', str)
+       str = re.sub (r'\\figures\b', r'\\figuremode', str)
+       str = re.sub (r'\\drums\b', r'\\drummode', str)
+       str = re.sub (r'\\chordmode\s*\\new ChordNames', r'\\chords', str)
+       str = re.sub (r'\\new ChordNames\s*\\chordmode', r'\\chords', str)
+       str = re.sub (r'\\new FiguredBass\s*\\figuremode', r'\\figures', str)
+       str = re.sub (r'\\figuremode\s*\new FiguredBass', r'\\figures', str)
+       str = re.sub (r'\\new DrumStaff\s*\\drummode', r'\\drums', str)
+       str = re.sub (r'\\drummode\s*\\new DrumStaff', r'\\drums', str)
+
+       return str
+
+#conversions.append (((2, 3, 9), conv,
+#                   '''fold \new FooContext \foomode into \foo.'''))
+
 ################################
 #      END OF CONVERSIONS      
 ################################