]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/convert-ly.py
add verbs.
[lilypond.git] / scripts / convert-ly.py
index e24b537299a9908d3d7751726ba92cde65cc9b70..9326c6f399a654c6fd4d36a010fe0029e0457707 100644 (file)
@@ -1,10 +1,12 @@
 #!@PYTHON@
 #
-# convert-ly.py -- convertor for lilypond versions
+# convert-ly.py -- Update old LilyPond input files (fix name?)
 # 
 # source file of the GNU LilyPond music typesetter
 # 
-# (c) 1998--2001
+# (c)  1998--2003  Han-Wen Nienhuys <hanwen@cs.uu.nl>
+#                 Jan Nieuwenhuizen <janneke@gnu.org>
+
 
 # TODO
 #   use -f and -t for -s output
@@ -28,6 +30,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);
@@ -42,12 +46,12 @@ Try to convert to newer lilypond-versions.  The version number of the
 input is guessed by default from \version directive
 
 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
+  -e, --edit             edit in place
+  -f, --from=VERSION     start from version; overrides \version found in file
   -s, --show-rules       print all rules.
-  -t, --to=VERSION       target version
+  -t, --to=VERSION       show 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 +529,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 +625,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 +677,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 +707,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 +778,480 @@ 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):
+       
+               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
+
+               str = re.sub ("breakAlignOrder *= *#'\\(([a-z_\n\tA-Z ]+)\\)",
+                             func, str)
+               return str
+
+       # 40 ? 
+       conversions.append (((1,5,40), conv, 'breakAlignOrder property names'))
+       
+
+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 ('minimumVerticalExtent', 'minimumV@rticalExtent', str)            
+               str = re.sub ('ExtraVerticalExtent', 'extraV@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!\1', str)
+               str = re.sub ('ly-set-mus-property([^!])', 'ly-set-mus-property!\1', str)               
+               return str
+       
+       conversions.append (((1,5,68), conv, 'ly-set-X-property -> ly-set-X-property!'))
+
+if 1:
+       def conv (str):
+               str = re.sub ('extent-X', 'X-extent', str)
+               str = re.sub ('extent-Y', 'Y-extent', str)              
+               return str
+       
+       conversions.append (((1,5,71), conv, 'extent-[XY] -> [XY]-extent'))
+
+
+if 1:
+       def conv (str):
+               str = re.sub ("""#\(set! +point-and-click +line-column-location\)""",
+                             """#(set-point-and-click! \'line-column)""", str)
+               str = re.sub ("""#\(set![ \t]+point-and-click +line-location\)""",
+                             '#(set-point-and-click! \'line)', str)
+               str = re.sub ('#\(set! +point-and-click +#f\)',
+                             '#(set-point-and-click! \'none)', str)
+               return str
+       
+       conversions.append (((1,5,72), conv, 'set! point-and-click -> set-point-and-click!'))
+
+
+if 1:
+       def conv (str):
+               str = re.sub ('flag-style', 'stroke-style', str)
+               str = re.sub (r"""Stem([ ]+)\\override #'style""", r"""Stem \\override #'flag-style""", str);
+               str = re.sub (r"""Stem([ ]+)\\set([ ]+)#'style""", r"""Stem \\set #'flag-style""", str);
+               return str
+       
+       conversions.append (((1,6,5), conv, 'Stems: flag-style -> stroke-style; style -> flag-style'))
+
+
+if 1:
+       def subst_req_name (match):
+               return "(make-music-by-name \'%sEvent)" % regularize_id (match.group(1))
+
+       def conv (str):
+               str = re.sub ('\\(ly-make-music *\"([A-Z][a-z_]+)_req\"\\)', subst_req_name, str)
+               str = re.sub ('Request_chord', 'EventChord', str)
+               return str
        
+       conversions.append (((1,7,1), conv, 'ly-make-music foo_bar_req -> make-music-by-name FooBarEvent'))
+
+
+if 1:
+       spanner_subst ={
+               "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'
+
+               mtype = spanner_subst[match.group(2)]
+               return "(make-span-event '%s %s)" % (mtype , stype)
+
+       def subst_definition_ev_name(match):
+               return ' = #%s' % subst_ev_name (match) 
+       def subst_inline_ev_name (match):
+               s = subst_ev_name (match)
+               return '#(ly-export %s)' % s
+       def subst_csp_definition (match):
+               return ' = #(make-event-chord (list %s))' % subst_ev_name (match)
+       def subst_csp_inline (match):
+               return '#(ly-export (make-event-chord (list %s)))' % subst_ev_name (match)
+               
+       def conv (str):
+               str = re.sub (r' *= *\\spanrequest *([^ ]+) *"([^"]+)"', subst_definition_ev_name, str)
+               str = re.sub (r'\\spanrequest *([^ ]+) *"([^"]+)"', subst_inline_ev_name, str)
+               str = re.sub (r' *= *\\commandspanrequest *([^ ]+) *"([^"]+)"', subst_csp_definition, str)
+               str = re.sub (r'\\commandspanrequest *([^ ]+) *"([^"]+)"', subst_csp_inline, str)
+               str = re.sub (r'ly-id ', 'ly-import ', str)
+
+               str = re.sub (r' *= *\\script "([^"]+)"', ' = #(make-articulation "\\1")', str)
+               str = re.sub (r'\\script "([^"]+)"', '#(ly-export (make-articulation "\\1"))', str)
+               return str
+
+       conversions.append (((1,7,2), conv, '\\spanrequest -> #(make-span-event .. ), \script -> #(make-articulation .. )'))
+
+if 1:
+       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!'
+                       ]
+
+               origre = r'\b(%s)' % string.join (changed, '|')
+               
+               str = re.sub (origre, r'ly:\1',str)
+               str = re.sub ('set-point-and-click!', 'set-point-and-click', str)
+               
+               return str
+       
+       conversions.append (((1,7,3), conv, 'ly- -> ly:'))
+
+if 1:
+       def conv(str):
+               if re.search ('new-chords-done',str):
+                       return str
+               
+               str = re.sub (r'<<', '< <', str)
+               str = re.sub (r'>>', '> >', str)
+               return str
+       
+       conversions.append (((1,7,4), conv, '<< >> -> < <  > >'))
+
+if 1:
+       def conv(str):
+               str = re.sub (r"\\transpose", r"\\transpose c'", str)
+               str = re.sub (r"\\transpose c' *([a-z]+)'", r"\\transpose c \1", str)
+               return str
+       conversions.append (((1,7,5), conv, '\\transpose TO -> \\transpose FROM  TO'))
+
+if 1:
+       def conv(str):
+               kws =   ['arpeggio',
+                        'sustainDown',
+                        'sustainUp',
+                        'f',
+                        'p',
+                        'pp',
+                        'ppp',
+                        'fp',
+                        'ff',
+                        'mf',
+                        'mp',
+                        'sfz',
+                        ]
+
+               origstr = string.join (kws, '|')
+               str = re.sub (r'([^_^-])\\(%s)\b' % origstr, r'\1-\\\2', str)
+               return str
+       conversions.append (((1,7,6), conv, 'note\\script -> note-\script'))
+
+
+if 1:
+       def conv(str):
+               str = re.sub (r"\\property *ChordNames *\. *ChordName *\\(set|override) *#'style *= *#('[a-z]+)",
+                             r"#(set-chord-name-style \2)", str)
+               str = re.sub (r"\\property *ChordNames *\. *ChordName *\\revert *#'style",
+                             r"", str)
+               return str
+       conversions.append (((1,7,10), conv, "\property ChordName #'style -> #(set-chord-name-style 'style)"))
+       
+
+
+if 1:
+       def conv(str):
+               str = re.sub (r"ly:transpose-pitch", "ly:pitch-transpose", str)
+               
+               return str
+       conversions.append (((1,7,11), conv, "transpose-pitch -> pitch-transpose"))
+
+if 1:
+       def conv(str):
+               str = re.sub (r"ly:get-molecule-extent", "ly:molecule-get-extent", str)
+               str = re.sub (r"ly:set-molecule-extent!", "ly:molecule-set-extent!", str)
+               str = re.sub (r"ly:add-molecule", "ly:molecule-add", str)
+               str = re.sub (r"ly:combine-molecule-at-edge", "ly:molecule-combine-at-edge", str)
+               str = re.sub (r"ly:align-to!", "ly:molecule-align-to!", str)
+               
+               return str
+       
+       conversions.append (((1,7,13), conv, "ly:XX-molecule-YY -> ly:molecule-XX-YY")) 
+
+if 1:
+       def conv(str):
+               str = re.sub (r"linewidth *= *-[0-9.]+ *(\\mm|\\cm|\\in|\\pt)?", 'raggedright = ##t', str )
+               return str
+       
+       conversions.append (((1,7,15), conv, "linewidth = -1 -> raggedright = ##t"))    
+
+if 1:
+       def conv(str):
+               str = re.sub ("divisiomaior",
+                             "divisioMaior", str)
+               str = re.sub ("divisiominima",
+                             "divisioMinima", str)
+               str = re.sub ("divisiomaxima",
+                             "divisioMaxima", str)
+               return str
+       
+       conversions.append (((1,7,16), conv, "divisiomaior -> divisioMaior"))
+
+if 1:
+       def conv(str):
+               str = re.sub ("Skip_req_swallow_translator",
+                             "Skip_event_swallow_translator", str)
+               return str
+       
+       conversions.append (((1,7,17), conv, "Skip_req  -> Skip_event"))
+
+if 1:
+       def conv(str):
+               str = re.sub ("groupOpen",
+                             "startGroup", str)
+               str = re.sub ("groupClose",
+                             "stopGroup", str)
+               str = re.sub ("#'outer",
+                             "#'enclose-bounds", str)
+
+               return str
+       
+       conversions.append (((1,7,18), conv,
+                            """groupOpen/Close  -> start/stopGroup,
+                            #'outer  -> #'enclose-bounds
+                            """))
+
+if 1:
+       def conv(str):
+               if re.search( r'\\GraceContext', str):
+                       sys.stderr.write ("GraceContext has been removed")
+                       sys.stderr.write ("please use #(add-to-grace-init .. )")
+                       raise FatalConversionError()
+
+               str = re.sub ('HaraKiriStaffContext', 'RemoveEmptyStaffContext', str)
+               return str
+       
+       conversions.append (((1,7,19), conv,"remove GraceContext"))
+
+
+
+if 1:
+       def conv(str):
+               str = re.sub (
+                       r"(set|override|revert) *#'type",
+                       r"\1 #'style",
+                       str)
+               return str
+       
+       conversions.append (((1,7,22), conv,"remove GraceContext"))
+
+if 1:
+       def conv(str):
+               str = re.sub (
+                       "barNonAuto *= *##t",
+                       "automaticBars = ##f",
+                       str)
+               str = re.sub (
+                       "barNonAuto *= *##f",
+                       "automaticBars = ##t",
+                       str)
+               return str
+       
+       conversions.append (((1,7,23), conv,"barNonAuto -> automaticBars"))
+       
+
+if 1:
+       def conv(str):
+               if re.search( r'-(start|stop)Cluster', str):
+                       sys.stderr.write ("""Cluster syntax has been changed.
+Please refer to the manual for details, and convert manually.
+""")
+                       
+                       raise FatalConversionError()
+
+               return str
+       
+       conversions.append (((1,7,24), conv,"cluster syntax"))
+
+if 1:
+       def conv(str):
+               str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\(override|set) *#'pedal-type *",
+                               r"\property Staff.pedal\1Style ", str)
+               str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\revert *#'pedal-type", '', str)
+               return str
+       
+       conversions.append (((1,7,28), conv,"new Pedal style syntax"))
+
+
+
+################################
+#      END OF CONVERSIONS      
+################################
 
 def get_conversions (from_version, to_version):
        def version_b (v, f = from_version, t = to_version):
@@ -811,13 +1280,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 +1351,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', 'version', 'output', 'show-rules', 'help', 'edit', 'from=', 'to='])
 
 for opt in options:
        o = opt[0]
@@ -906,8 +1373,8 @@ for opt in options:
                sys.exit(0)
        elif o == '--output' or o == '-o':
                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 +1383,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 +1397,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')