]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/convert-ly.py
*** empty log message ***
[lilypond.git] / scripts / convert-ly.py
index b571c8330b4dc850686e630fa903202a7e0d5e7d..ec66a08af67c6e0e7fc7549f6a3d1617836c9cf6 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
@@ -44,7 +46,6 @@ 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. Overrides \version found in file.
@@ -966,6 +967,239 @@ if 1:
        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"))
+
+
+
 ################################
 #      END OF CONVERSIONS      
 ################################
@@ -1068,7 +1302,7 @@ from_version = ()
 outfile_name = ''
 
 (options, files) = getopt.getopt (
-       sys.argv[1:], 'ao:f:t:senh', ['no-version', '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]
@@ -1090,8 +1324,6 @@ 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: