]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/convert-ly.py
($(outdir)/%.pdf): add DVIPS_FLAGS. This will
[lilypond.git] / scripts / convert-ly.py
index f961537f412d9e39344d28b45db30089d4cf87c6..07f0a387b3189d8c56345cb50eab038d427f98db 100644 (file)
@@ -4,7 +4,7 @@
 #
 # source file of the GNU LilyPond music typesetter
 #
-# (c)  1998--2003  Han-Wen Nienhuys <hanwen@cs.uu.nl>
+# (c) 1998--2004  Han-Wen Nienhuys <hanwen@cs.uu.nl>
 #                 Jan Nieuwenhuizen <janneke@gnu.org>
 
 
@@ -1265,11 +1265,11 @@ if 1:
                        return origstr
 
                durs = []
-               def sub_durs (m):
+               def sub_durs (m, durs = durs):
                        durs.append(m.group(2))
                        return m.group (1)
 
-               str = re.sub ("([a-z]+[,'!? ]*)([0-9.]+)", sub_durs, str)
+               str = re.sub (r"([a-z]+[,'!? ]*)([0-9]+\.*)", sub_durs, str)
                dur_str = ''
 
                for d in durs:
@@ -1285,7 +1285,8 @@ if 1:
                last_str = ''
                while last_str <> str:
                        last_str = str
-                       def sub_tremolos (m):
+
+                       def sub_tremolos (m, slur_strs = slur_strs):
                                tr = m.group (2)
                                if tr not in slur_strs:
                                        slur_strs.append (tr)
@@ -1294,31 +1295,31 @@ if 1:
                        str = re.sub (r"([a-z]+[',!? ]*)(:[0-9]+)",
                                      sub_tremolos, str)
 
-                       def sub_dyn_end (m):
+                       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):
+                       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):
+                       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):
+                       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):
+                       def sub_begin_p_slurs(m, slur_strs = slur_strs):
                                if '-\(' not in slur_strs:
                                        slur_strs.append ('\(')
                                return m.group(1)
@@ -1326,7 +1327,7 @@ if 1:
                        str = re.sub (r"([a-z]+[,'!?0-9 ]*)\\\(",
                                sub_begin_p_slurs, str)
 
-                       def sub_dyns (m):
+                       def sub_dyns (m, slur_strs = slur_strs):
                                s = m.group(0)
                                if s == '@STARTCRESC@':
                                        slur_strs.append ("\\<")
@@ -1339,7 +1340,7 @@ if 1:
                        str = re.sub (r'@STARTCRESC@', sub_dyns, str)
                        str = re.sub (r'-?\\!', sub_dyns, str)
 
-                       def sub_articulations (m):
+                       def sub_articulations (m, slur_strs = slur_strs):
                                a = m.group(1)
                                if a not in slur_strs:
                                        slur_strs.append (a)
@@ -1351,8 +1352,10 @@ if 1:
                                      str)
                        str = re.sub (r"([_^-][>_.+|^-])", sub_articulations,
                                      str)
+                       str = re.sub (r'([_^-]"[^"]+")', sub_articulations,
+                                     str)
 
-                       def sub_pslurs(m):
+                       def sub_pslurs(m, slur_strs = slur_strs):
                                slur_strs.append (' \\)')
                                return m.group(1)
                        str = re.sub (r"\\\)[ ]*([a-z]+)", sub_pslurs, str)
@@ -1406,7 +1409,9 @@ if 1:
        def articulation_substitute (str):
                str = re.sub (r"""([^-])\[ *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
                              r"\1 \2[", str)
-               str = re.sub (r"""([^-])\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
+               str = re.sub (r"""([^-])\\\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
+                             r"\1 \2\\)", str)
+               str = re.sub (r"""([^-\\])\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
                              r"\1 \2)", str)
                str = re.sub (r"""([^-])\\! *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
                              r"\1 \2\\!", str)
@@ -1695,11 +1700,179 @@ conversions.append (((2,1,12), conv, """OttavaSpanner -> OttavaBracket"""))
 
 
 def conv (str):
-       str =re.sub (r"\(set-staff-size ", r"(set-global-staff-size", str)
+       str =re.sub (r"\(set-staff-size ", r"(set-global-staff-size ", str)
        return str
 
 conversions.append (((2,1,13), conv, """set-staff-size -> set-global-staff-size"""))
 
+def conv (str):
+       str =re.sub (r"#'style\s*=\s*#'dotted-line",
+                    r"#'dash-fraction = #0.0 ", str)
+       return str
+
+conversions.append (((2,1,14), conv, """style = dotted -> dash-fraction = 0"""))
+
+def conv (str):
+       str =re.sub (r'LyricsVoice\s*\.\s*instrument\s*=\s*("[^"]*")',
+                    r'LyricsVoice . vocalName = \1', str)
+       
+       str =re.sub (r'LyricsVoice\s*\.\s*instr\s*=\s*("[^"]*")',
+                    r'LyricsVoice . vocNam = \1', str)
+       return str
+
+conversions.append (((2,1,15), conv, """LyricsVoice . instr(ument) -> vocalName"""))
+
+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)]
+                    
+       str = re.sub (r'\\musicglyph\s*#"accidentals-([0-9-]+)"',
+                     sub_acc, str)
+       return str
+
+conversions.append (((2,1,16), conv, """\\musicglyph #"accidentals-NUM" -> \\sharp/flat/etc."""))
+
+
+def conv (str):
+
+       if re.search (r'\\partcombine', str):
+               sys.stderr.write ('Warning: \\partcombine has been changed. '
+                                 +'Check conversion 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)
+       
+       
+       return str
+
+conversions.append (((2,1,17), conv, """\\partcombine syntax change to \\newpartcombine"""))
+
+
+def conv (str):
+       str = re.sub (r'\\newpartcombine', r'\\partcombine', str)
+       str = re.sub (r'\\autochange\s+Staff', r'\\autochange ', str)
+       return str
+
+conversions.append (((2,1,18), conv, """\\newpartcombine -> \\partcombine,
+\\autochange Staff -> \\autochange
+"""))
+
+
+
+
+def conv (str):
+       str = re.sub (r'\\include "drumpitch-init.ly"','', str)
+       str = re.sub (r'\\pitchnames ','pitchnames = ', str)
+       str = re.sub (r'\\chordmodifiers ','chordmodifiers = ', str)
+       str = re.sub (r'\bdrums\b\s*=','drumContents = ', str)
+       str = re.sub (r'\\drums\b','\\drumContents ', str)
+       
+
+       if re.search ('drums->paper', str):
+               sys.stderr.write ("\nDrum notation found. Check file manually!")
+               
+       str = re.sub (r"""\\apply\s+#\(drums->paper\s+'([a-z]+)\)""",
+                     r"""\property DrumStaff.drumStyleTable = #\1-style""",
+                     str)
+
+       if re.search ('Thread', str):
+               sys.stderr.write ("\nThread found. Check file manually!\n");
+
+       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)
+
+       str = re.sub (r"""\\new Thread""", """\context Voice""", str)
+       str = re.sub (r"""Thread""", """Voice""", str)
+
+       if re.search ('\bLyrics\b', str):
+               sys.stderr.write ("\nLyrics found. Check file manually!\n");
+
+       str = re.sub (r"""LyricsVoice""", r"""L@ricsVoice""", str)
+       str = re.sub (r"""\bLyrics\b""", r"""LyricsVoice""", str)
+       str = re.sub (r"""LyricsContext""", r"""LyricsVoiceContext""", str)
+       str = re.sub (r"""L@ricsVoice""", r"""LyricsVoice""",str)
+       
+       
+       return str
+
+conversions.append (((2,1,19), conv, """Drum notation changes, Removing \chordmodifiers, \notenames.
+Harmonic notes. Thread context removed. Lyrics context removed."""))
+
+def conv (str):
+       str = re.sub (r'nonevent-skip', 'skip-music', str)
+       return str
+
+conversions.append (((2,1,20), conv, """nonevent-skip -> skip-music""" ))
+
+def conv (str):
+       str = re.sub (r'molecule-callback', 'print-function', str)
+       str = re.sub (r'brew_molecule', 'print', 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)
+#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)
+
+       return str
+
+conversions.append (((2,1,21), conv, """molecule-callback -> print-function,
+brew_molecule -> print
+brew-new-markup-molecule -> Text_item::print
+LyricsVoice -> Lyrics
+tupletInvisible -> TupletBracket \set #'transparent
+Grob::preset_extent removed.
+""" ))
+
+
+def conv (str):
+       str = re.sub (r'\\property\s+([^.]+)\s*\.\s*([^\\=]+)\s*\\(set|override)',
+                     r"\\overrid@ \1.\2 ", str)
+       str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*=',
+                     r'\\s@t \1.\2 = ', str)
+       str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*\\unset',
+                     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)
+       str = re.sub (r'Voice\.', '', str)
+       str = re.sub (r'Lyrics\.', '', str)
+       str = re.sub (r'ChordNames\.', '', str)
+       
+       str = re.sub ('rev@rt', 'revert',str)
+       str = re.sub ('s@t', 'set',str)
+       str = re.sub ('overrid@', 'override',str)
+
+       str = re.sub ('molecule', 'stencil', str)
+       str = re.sub ('Molecule', 'Stencil', str)
+       return str
+
+conversions.append (((2,1,22), conv, """new syntax for property settings:
+       \set A.B = #C , \unset A.B
+       \override A.B #C = #D, \revert A.B #C
+
+"""))
+
 
 ################################
 #      END OF CONVERSIONS      
@@ -1835,7 +2008,7 @@ identify ()
 for f in files:
        if f == '-':
                f = ''
-       if not os.path.isfile (f):
+       elif not os.path.isfile (f):
                continue
        try:
                do_one_file (f)