]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/convert-ly.py
* scm/grob-description.scm (all-grob-descriptions): set
[lilypond.git] / scripts / convert-ly.py
index e24b537299a9908d3d7751726ba92cde65cc9b70..14049d621fd4fa1360be87da498273d7df89e41c 100644 (file)
@@ -28,6 +28,8 @@ import time
 # lilypond_version_re_str = '\\\\version *\"(.*)\"'
 lilypond_version_re_str = '\\\\(mudela-)?version *\"(.*)\"'
 lilypond_version_re = re.compile (lilypond_version_re_str)
+add_version = 1
+
 
 def program_id ():
        return '%s (GNU LilyPond) %s' %(program_name,  version);
@@ -45,9 +47,10 @@ Options:
   -a, --assume-old       apply all conversions to unversioned files
   -h, --help             print this help
   -e, --edit             in place edit
-  -f, --from=VERSION     start from version
+  -f, --from=VERSION     start from version. Overrides \version found in file.
   -s, --show-rules       print all rules.
   -t, --to=VERSION       target version
+  -n, --no-version       don't add new version stamp.
       --version          print program version
 
 Report bugs to bugs-gnu-music@gnu.org
@@ -525,10 +528,8 @@ if 1:
 
 
 
-################ TODO: lots of other syntax change should be done here as well
-
-
 
+# TODO: lots of other syntax change should be done here as well
 if 1:
        def conv (str):
                str = re.sub ('basicCollisionProperties', 'NoteCollision', str)
@@ -623,7 +624,7 @@ if 1:
        conversions.append (((1,3,97), conv, 'ChordName -> ChordNames'))
 
 
-## TODO: add lots of these
+# TODO: add lots of these
        
 if 1:
        def conv (str):
@@ -675,6 +676,7 @@ if 1:
                str = re.sub ('LyricVoice', 'LyricsVoice', str)
                # old fix
                str = re.sub ('Chord[Nn]ames*.Chord[Nn]ames*', 'ChordNames.ChordName', str)
+               str = re.sub ('Chord[Nn]ames([ \t\n]+\\\\override)', 'ChordName\\1', str)
                return str
        
        conversions.append (((1,3,113), conv, 'LyricVoice -> LyricsVoice'))
@@ -704,7 +706,7 @@ if 1:
                def regularize_assignment (match):
                        return '\n' + regularize_id (match.group (1)) + ' = '
                str = re.sub ('\$([^\t\n ]+)', regularize_dollar_reference, str)
-               str = re.sub ('\n([^ \t\n]+) = ', regularize_assignment, str)
+               str = re.sub ('\n([^ \t\n]+)[ \t]*= *', regularize_assignment, str)
                return str
        
        conversions.append (((1,3,117), conv, 'identifier names: $!foo_bar_123 -> xfooBarABC'))
@@ -775,14 +777,172 @@ if 1:
 
 if 1:
        def conv (str):
-               str = re.sub ('([Cc])horda', '\\1orda', str)
+               str = re.sub ('([Cc])hord([ea])', '\\1ord\\2', str)
                return str
        
        conversions.append (((1,3,144), conv, 'Chorda -> Corda'))
 
 
-############################
+if 1:
+       def conv (str):
+               str = re.sub ('([A-Za-z]+)MinimumVerticalExtent', 'MinimumV@rticalExtent', str)
+               str = re.sub ('([A-Za-z]+)ExtraVerticalExtent', 'ExtraV@rticalExtent', str)
+               str = re.sub ('([A-Za-z]+)VerticalExtent', 'VerticalExtent', str)
+               str = re.sub ('ExtraV@rticalExtent', 'ExtraVerticalExtent', str)
+               str = re.sub ('MinimumV@rticalExtent', 'MinimumVerticalExtent', str)            
+               return str
+
+       conversions.append (((1,3,145), conv,
+       'ContextNameXxxxVerticalExtent -> XxxxVerticalExtent'))
+
+if 1:
+       def conv (str):
+               str = re.sub ('\\\\key[ \t]*;', '\\key \\default;', str)
+               str = re.sub ('\\\\mark[ \t]*;', '\\mark \\default;', str)
+
+               # Make sure groups of more than one ; have space before
+               # them, so that non of them gets removed by next rule
+               str = re.sub ("([^ \n\t;]);(;+)", "\\1 ;\\2", str)
+               
+               # Only remove ; that are not after spaces, # or ;
+               # Otherwise  we interfere with Scheme comments,
+               # which is badbadbad.
+               str = re.sub ("([^ \t;#]);", "\\1", str)
+
+               return str
+       conversions.append (((1,3,146), conv, 'semicolons removed'))
+
+if 1:
+       def conv (str):
+               str = re.sub ('default-neutral-direction', 'neutral-direction',str)
+               return str
+       conversions.append (((1,3,147), conv, 'default-neutral-direction -> neutral-direction'))
+
+if 1:
+       def conv (str):
+               str = re.sub ('\(align', '(axis', str)
+               str = re.sub ('\(rows', '(columns', str)
+               return str
+       conversions.append (((1,3,148), conv, '"(align" -> "(axis", "(rows" -> "(columns"'))
+
+
+if 1:
+       def conv (str):
+               str = re.sub ('SystemStartDelimiter', 'systemStartDelimiter', str)
+               return str
+       conversions.append (((1,5,33), conv, 'SystemStartDelimiter -> systemStartDelimiter'))
+
+if 1:
+       def conv (str):
+               str = re.sub ('arithmetic-multiplier', 'spacing-increment', str)
+               str = re.sub ('arithmetic-basicspace', 'shortest-duration-space', str)          
+               return str
        
+       conversions.append (((1,5,38), conv, 'SystemStartDelimiter -> systemStartDelimiter'))
+
+if 1:
+       def conv (str):
+               str = re.sub ('noAutoBeaming *= *##f', 'autoBeaming = ##t', str)
+               str = re.sub ('noAutoBeaming *= *##t', 'autoBeaming = ##f', str)
+               return str
+       
+       conversions.append (((1,5,49), conv, 'noAutoBeaming -> autoBeaming'))
+
+if 1:
+       def conv (str):
+               str = re.sub ('tuplet-bracket-visibility', 'bracket-visibility', str)
+               str = re.sub ('tuplet-number-visibility', 'number-visibility', str)             
+               return str
+       
+       conversions.append (((1,5,52), conv, 'tuplet-X-visibility -> X-visibility'))
+
+if 1:
+       def conv (str):
+               str = re.sub ('Pitch::transpose', 'ly-transpose-pitch', str)
+
+               return str
+       
+       conversions.append (((1,5,56), conv, 'Pitch::transpose -> ly-transpose-pitch'))
+
+if 1:
+       def conv (str):
+               str = re.sub ('textNonEmpty *= *##t', "TextScript \\set #'no-spacing-rods = ##f", str)
+               str = re.sub ('textNonEmpty *= *##f', "TextScript \\set #'no-spacing-rods = ##t", str)
+               return str
+       
+       conversions.append (((1,5,58), conv, 'deprecate textNonEmpty'))
+
+
+if 1:
+       def conv (str):
+               str = re.sub ('MinimumVerticalExtent', 'MinimumV@rticalExtent', str)
+               str = re.sub ('ExtraVerticalExtent', 'ExtraV@rticalExtent', str)
+               str = re.sub ('VerticalExtent', 'verticalExtent', str)
+               str = re.sub ('ExtraV@rticalExtent', 'extraVerticalExtent', str)
+               str = re.sub ('MinimumV@rticalExtent', 'minimumVerticalExtent', str)            
+               return str
+
+       conversions.append (((1,5,59), conv,
+       'XxxxVerticalExtent -> xxxVerticalExtent'))
+
+if 1:
+       def conv (str):
+               str = re.sub ('visibility-lambda', 'break-visibility', str)
+               return str
+
+       conversions.append (((1,5,62), conv,
+       'visibility-lambda -> break-visibility'))
+       
+
+if 1:
+       def conv (str):
+               if re.search (r'\addlyrics',str) \
+                      and re.search ('automaticMelismata', str)  == None:
+                       sys.stderr.write  ('automaticMelismata is turned on by default since 1.5.67. Please fix this by hand.')
+                       raise FatalConversionError()
+               return str
+
+       conversions.append (((1,5,67), conv,
+                            'automaticMelismata turned on by default'))
+
+if 1:
+       def conv (str):
+               str = re.sub ('ly-set-grob-property', 'ly-set-grob-property!', str)
+               str = re.sub ('ly-set-mus-property', 'ly-set-mus-property!', str)               
+               return str
+       
+       conversions.append (((1,5,68), conv, 'ly-set-X-property -> ly-set-X-property!'))
+
+if 1:
+       def conv (str):
+               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"
+               }
+               def func(match):
+                       props =  m.group (1)
+                       for (k,v) in break_dict.items():
+                               props = re.sub (k, v, props)
+
+                       
+                       return  "breakAlignOrder = #'( %s )" % props
+               str = re.sub (r"breakAlignOrder *= *#'\(([a-z_A-Z ]+)\)", func, str)
+               return str
+
+       # 40 ? 
+       conversions.append (((1,5,40), conv, 'breakAlignOrder property names'))
+       
+
+################################
+#      END OF CONVERSIONS      
+################################
 
 def get_conversions (from_version, to_version):
        def version_b (v, f = from_version, t = to_version):
@@ -811,13 +971,11 @@ def do_conversion (infile, from_version, outfile, to_version):
        if last_conversion:
                sys.stderr.write ('\n')
                new_ver =  '\\version \"%s\"' % tup_to_str (last_conversion)
-               # JUNKME?
-               # ugh: this all really doesn't help
-               # esp. as current conversion rules are soo incomplete
+
                if re.search (lilypond_version_re_str, str):
                        str = re.sub (lilypond_version_re_str,'\\'+new_ver , str)
-               #else:
-               #       str = new_ver + '\n' + str
+               elif add_version:
+                       str = new_ver + '\n' + str
 
                outfile.write(str)
 
@@ -884,7 +1042,7 @@ from_version = ()
 outfile_name = ''
 
 (options, files) = getopt.getopt (
-       sys.argv[1:], 'ao:f:t:seh', ['assume-old', 'version', 'output', 'show-rules', 'help', 'edit', 'from=', 'to='])
+       sys.argv[1:], 'ao:f:t:senh', ['no-version', 'assume-old', 'version', 'output', 'show-rules', 'help', 'edit', 'from=', 'to='])
 
 for opt in options:
        o = opt[0]
@@ -908,6 +1066,8 @@ for opt in options:
                outfile_name = a
        elif o == '--assume-old' or o == '-a':
                assume_old = 1
+       elif o == '--no-version' or o == '-n':
+               add_version = 0
        else:
                print o
                raise getopt.error
@@ -916,11 +1076,13 @@ identify ()
 for f in files:
        if f == '-':
                f = ''
+       if not os.path.isfile (f):
+               continue
        try:
                do_one_file (f)
        except UnknownVersion:
                sys.stderr.write ('\n')
-               sys.stderr.write ("%s: can't determine version for %s" % (program_name, f))
+               sys.stderr.write ("%s: can't determine version for `%s'" % (program_name, f))
                sys.stderr.write ('\n')
                if assume_old:
                        fv = from_version
@@ -928,6 +1090,6 @@ for f in files:
                        do_one_file (f)
                        from_version = fv
                else:
-                       sys.stderr.write ("%s: skipping: %s " % (program_name,  f))
+                       sys.stderr.write ("%s: skipping: `%s' " % (program_name,  f))
                pass
 sys.stderr.write ('\n')