3 # convert-ly.py -- Update old LilyPond input files (fix name?)
5 # source file of the GNU LilyPond music typesetter
7 # (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 # Jan Nieuwenhuizen <janneke@gnu.org>
18 localedir = '@localedir@'
21 gettext.bindtextdomain ('lilypond', localedir)
22 gettext.textdomain ('lilypond')
29 program_name = os.path.basename (sys.argv[0])
30 version = '@TOPLEVEL_VERSION@'
32 FROM_TO = _ ( "%s has been replaced by %s")
33 NOT_SMART = _ ("Not smart enough to convert %s")
34 UPDATE_MANUALLY = _ ("Please refer to the manual for details, and update manually.")
36 # Did we ever have \mudela-version? I doubt it.
37 # lilypond_version_re_str = '\\\\version *\"(.*)\"'
38 lilypond_version_re_str = '\\\\(mudela-)?version *\"([^"]+)\"'
39 lilypond_version_re = re.compile (lilypond_version_re_str)
44 return '%s (GNU LilyPond) %s' % (program_name, version)
47 sys.stderr.write (program_id () + '\n')
50 sys.stdout.write (_ ("Usage: %s [OPTION]... [FILE]..." \
52 sys.stdout.write ('\n\n')
53 sys.stdout.write (_ ("""\
54 Update LilyPond input to newer version. By default, update from the
55 version taken from the \\version command, to the current LilyPond version."""))
56 sys.stdout.write ('\n\n')
57 sys.stdout.write (_ ("Options:"))
58 sys.stdout.write ('\n')
59 sys.stdout.write (_ ("""\
60 -e, --edit edit in place
61 -f, --from=VERSION start from VERSION [default: \\version found in file]
62 -h, --help print this help
63 -n, --no-version do not add \\version command if missing
64 -s, --show-rules print rules [default: --from=0, --to=@TOPLEVEL_VERSION@]
65 -t, --to=VERSION convert to VERSION [default: @TOPLEVEL_VERSION@]
66 -v, --version print program version"""))
67 sys.stdout.write ('\n\n')
68 sys.stdout.write (_ ("Report bugs to %s.") % "bug-lilypond@gnu.org")
69 sys.stdout.write ('\n')
73 sys.stdout.write (program_id ())
74 sys.stdout.write ('\n')
75 sys.stdout.write (_ ("""\
76 This program is free software. It is covered by the GNU General Public
77 License and you are welcome to change it and/or distribute copies of it
78 under certain conditions. Invoke as `%s --warranty' for more
83 return tuple (map (string.atoi, string.split (s, '.')))
86 return string.join (map (lambda x: '%s' % x, list (t)), '.')
88 def version_cmp (t1, t2):
94 def guess_lilypond_version (filename):
95 s = open (filename).read ()
96 m = lilypond_version_re.search (s)
102 class FatalConversionError:
107 def show_rules (file):
108 for x in conversions:
109 if (not from_version or x[0] > from_version) \
110 and (not to_version or x[0] <= to_version):
111 file.write ('%s: %s\n' % (tup_to_str (x[0]), x[2]))
113 ############################
117 if re.search ('\\\\multi', str):
118 sys.stderr.write ('\n')
119 sys.stderr.write (NOT_SMART % "\\multi")
122 conversions.append (((0,1,9), conv, '\\header { key = concat + with + operator }'))
126 if re.search ('\\\\octave', str):
127 sys.stderr.write ('\n')
128 sys.stderr.write (NOT_SMART % "\\octave")
129 sys.stderr.write ('\n')
130 sys.stderr.write (UPDATE_MANUALLY)
131 sys.stderr.write ('\n')
132 # raise FatalConversionError ()
136 conversions.append ((
137 ((0,1,19), conv, 'deprecated \\octave; cannot convert automatically')))
142 str = re.sub ('\\\\textstyle([^;]+);',
143 '\\\\property Lyrics . textstyle = \\1', str)
144 # harmful to current .lys
145 # str = re.sub ('\\\\key([^;]+);', '\\\\accidentals \\1;', str)
149 conversions.append ((
150 ((0,1,20), conv, 'deprecated \\textstyle, new \\key syntax')))
155 str = re.sub ('\\\\musical_pitch', '\\\\musicalpitch',str)
156 str = re.sub ('\\\\meter', '\\\\time',str)
160 conversions.append ((
161 ((0,1,21), conv, '\\musical_pitch -> \\musicalpitch, '+
162 '\\meter -> \\time')))
168 conversions.append ((
169 ((1,0,0), conv, '0.1.21 -> 1.0.0 ')))
174 str = re.sub ('\\\\accidentals', '\\\\keysignature',str)
175 str = re.sub ('specialaccidentals *= *1', 'keyoctaviation = 0',str)
176 str = re.sub ('specialaccidentals *= *0', 'keyoctaviation = 1',str)
180 conversions.append ((
181 ((1,0,1), conv, '\\accidentals -> \\keysignature, ' +
182 'specialaccidentals -> keyoctaviation')))
186 if re.search ('\\\\header', str):
187 sys.stderr.write ('\n')
188 sys.stderr.write (NOT_SMART % "new \\header format")
191 conversions.append (((1,0,2), conv, '\\header { key = concat + with + operator }'))
195 str = re.sub ('\\\\melodic([^a-zA-Z])', '\\\\notes\\1',str)
198 conversions.append (((1,0,3), conv, '\\melodic -> \\notes'))
202 str = re.sub ('default_paper *=', '',str)
203 str = re.sub ('default_midi *=', '',str)
206 conversions.append (((1,0,4), conv, 'default_{paper,midi}'))
210 str = re.sub ('ChoireStaff', 'ChoirStaff',str)
211 str = re.sub ('\\\\output', 'output = ',str)
215 conversions.append (((1,0,5), conv, 'ChoireStaff -> ChoirStaff'))
219 if re.search ('[a-zA-Z]+ = *\\translator',str):
220 sys.stderr.write ('\n')
221 sys.stderr.write (NOT_SMART % "\\translator syntax")
222 # raise FatalConversionError ()
225 conversions.append (((1,0,6), conv, 'foo = \\translator {\\type .. } ->\\translator {\\type ..; foo; }'))
230 str = re.sub ('\\\\lyrics*', '\\\\lyrics',str)
234 conversions.append (((1,0,7), conv, '\\lyric -> \\lyrics'))
238 str = re.sub ('\\\\\\[/3+', '\\\\times 2/3 { ',str)
239 str = re.sub ('\\[/3+', '\\\\times 2/3 { [',str)
240 str = re.sub ('\\\\\\[([0-9/]+)', '\\\\times \\1 {',str)
241 str = re.sub ('\\[([0-9/]+)', '\\\\times \\1 { [',str)
242 str = re.sub ('\\\\\\]([0-9/]+)', '}', str)
243 str = re.sub ('\\\\\\]', '}',str)
244 str = re.sub ('\\]([0-9/]+)', '] }', str)
247 conversions.append (((1,0,10), conv, '[2/3 ]1/1 -> \\times 2/3 '))
252 conversions.append (((1,0,12), conv, 'Chord syntax stuff'))
259 str = re.sub ('<([^>~]+)~([^>]*)>','<\\1 \\2> ~', str)
263 conversions.append (((1,0,13), conv, '<a ~ b> c -> <a b> ~ c'))
267 str = re.sub ('<\\[','[<', str)
268 str = re.sub ('\\]>','>]', str)
272 conversions.append (((1,0,14), conv, '<[a b> <a b]>c -> [<a b> <a b>]'))
277 str = re.sub ('\\\\type([^\n]*engraver)','\\\\TYPE\\1', str)
278 str = re.sub ('\\\\type([^\n]*performer)','\\\\TYPE\\1', str)
279 str = re.sub ('\\\\type','\\\\context', str)
280 str = re.sub ('\\\\TYPE','\\\\type', str)
281 str = re.sub ('textstyle','textStyle', str)
285 conversions.append (((1,0,16), conv, '\\type -> \\context, textstyle -> textStyle'))
290 if re.search ('\\\\repeat',str):
291 sys.stderr.write ('\n')
292 sys.stderr.write (NOT_SMART % "\\repeat")
293 # raise FatalConversionError ()
296 conversions.append (((1,0,18), conv,
297 '\\repeat NUM Music Alternative -> \\repeat FOLDSTR Music Alternative'))
301 str = re.sub ('SkipBars','skipBars', str)
302 str = re.sub ('fontsize','fontSize', str)
303 str = re.sub ('midi_instrument','midiInstrument', str)
307 conversions.append (((1,0,19), conv,
308 'fontsize -> fontSize, midi_instrument -> midiInstrument, SkipBars -> skipBars'))
313 str = re.sub ('tieydirection','tieVerticalDirection', str)
314 str = re.sub ('slurydirection','slurVerticalDirection', str)
315 str = re.sub ('ydirection','verticalDirection', str)
319 conversions.append (((1,0,20), conv,
320 '{,tie,slur}ydirection -> {v,tieV,slurV}erticalDirection'))
325 str = re.sub ('hshift','horizontalNoteShift', str)
329 conversions.append (((1,0,21), conv,
330 'hshift -> horizontalNoteShift'))
335 str = re.sub ('\\\\grouping[^;]*;','', str)
339 conversions.append (((1,1,52), conv,
340 'deprecate \\grouping'))
345 str = re.sub ('\\\\wheel','\\\\coda', str)
349 conversions.append (((1,1,55), conv,
350 '\\wheel -> \\coda'))
354 str = re.sub ('keyoctaviation','keyOctaviation', str)
355 str = re.sub ('slurdash','slurDash', str)
359 conversions.append (((1,1,65), conv,
360 'slurdash -> slurDash, keyoctaviation -> keyOctaviation'))
364 str = re.sub ('\\\\repeat *\"?semi\"?','\\\\repeat "volta"', str)
368 conversions.append (((1,1,66), conv,
374 str = re.sub ('\"?beamAuto\"? *= *\"?0?\"?','noAutoBeaming = "1"', str)
378 conversions.append (((1,1,67), conv,
379 'beamAuto -> noAutoBeaming'))
383 str = re.sub ('automaticMelismas', 'automaticMelismata', str)
387 conversions.append (((1,2,0), conv,
388 'automaticMelismas -> automaticMelismata'))
392 str = re.sub ('dynamicDir\\b', 'dynamicDirection', str)
396 conversions.append (((1,2,1), conv,
397 'dynamicDir -> dynamicDirection'))
401 str = re.sub ('\\\\cadenza *0 *;', '\\\\cadenzaOff', str)
402 str = re.sub ('\\\\cadenza *1 *;', '\\\\cadenzaOn', str)
406 conversions.append (((1,3,4), conv,
407 '\\cadenza -> \\cadenza{On|Off}'))
411 str = re.sub ('"?beamAuto([^"=]+)"? *= *"([0-9]+)/([0-9]+)" *;*',
412 'beamAuto\\1 = #(make-moment \\2 \\3)',
416 conversions.append (((1,3,5), conv, 'beamAuto moment properties'))
420 str = re.sub ('stemStyle',
425 conversions.append (((1,3,17), conv, 'stemStyle -> flagStyle'))
429 str = re.sub ('staffLineLeading',
434 conversions.append (((1,3,18), conv, 'staffLineLeading -> staffSpace'))
439 if re.search ('\\\\repetitions',str):
440 sys.stderr.write ('\n')
441 sys.stderr.write (NOT_SMART % "\\repetitions")
442 # raise FatalConversionError ()
445 conversions.append (((1,3,23), conv,
446 '\\\\repetitions feature dropped'))
451 str = re.sub ('textEmptyDimension *= *##t',
452 'textNonEmpty = ##f',
454 str = re.sub ('textEmptyDimension *= *##f',
455 'textNonEmpty = ##t',
459 conversions.append (((1,3,35), conv, 'textEmptyDimension -> textNonEmpty'))
463 str = re.sub ("([a-z]+)[ \t]*=[ \t]*\\\\musicalpitch *{([- 0-9]+)} *\n",
464 "(\\1 . (\\2))\n", str)
465 str = re.sub ("\\\\musicalpitch *{([0-9 -]+)}",
466 "\\\\musicalpitch #'(\\1)", str)
467 if re.search ('\\\\notenames',str):
468 sys.stderr.write ('\n')
469 sys.stderr.write (NOT_SMART % "new \\notenames format")
472 conversions.append (((1,3,38), conv, '\musicalpitch { a b c } -> #\'(a b c)'))
477 return '\\key %s;' % string.lower (match.group (1))
479 str = re.sub ("\\\\key ([^;]+);", replace, str)
482 conversions.append (((1,3,39), conv, '\\key A ; ->\\key a;'))
486 if re.search ('\\[:',str):
487 sys.stderr.write ('\n')
488 sys.stderr.write (NOT_SMART % "new tremolo format")
491 conversions.append (((1,3,41), conv,
492 '[:16 c4 d4 ] -> \\repeat "tremolo" 2 { c16 d16 }'))
496 str = re.sub ('Staff_margin_engraver' , 'Instrument_name_engraver', str)
499 conversions.append (((1,3,42), conv,
500 'Staff_margin_engraver deprecated, use Instrument_name_engraver'))
504 str = re.sub ('note[hH]eadStyle\\s*=\\s*"?(\\w+)"?' , "noteHeadStyle = #'\\1", str)
507 conversions.append (((1,3,49), conv,
508 'noteHeadStyle value: string -> symbol'))
512 if re.search ('\\\\keysignature', str):
513 sys.stderr.write ('\n')
514 sys.stderr.write (NOT_SMART % "new tremolo format")
518 conversions.append (((1,3,58), conv,
519 'noteHeadStyle value: string -> symbol'))
523 str = re.sub (r"""\\key *([a-z]+) *;""", r"""\\key \1 \major;""",str);
525 conversions.append (((1,3,59), conv,
526 '\key X ; -> \key X major; '))
530 str = re.sub (r'latexheaders *= *"\\\\input ',
534 conversions.append (((1,3,68), conv, 'latexheaders = "\\input global" -> latexheaders = "global"'))
539 # TODO: lots of other syntax change should be done here as well
542 str = re.sub ('basicCollisionProperties', 'NoteCollision', str)
543 str = re.sub ('basicVoltaSpannerProperties' , "VoltaBracket", str)
544 str = re.sub ('basicKeyProperties' , "KeySignature", str)
546 str = re.sub ('basicClefItemProperties' ,"Clef", str)
549 str = re.sub ('basicLocalKeyProperties' ,"Accidentals", str)
550 str = re.sub ('basicMarkProperties' ,"Accidentals", str)
551 str = re.sub ('basic([A-Za-z_]+)Properties', '\\1', str)
553 str = re.sub ('Repeat_engraver' ,'Volta_engraver', str)
556 conversions.append (((1,3,92), conv, 'basicXXXProperties -> XXX, Repeat_engraver -> Volta_engraver'))
560 # Ugh, but meaning of \stemup changed too
561 # maybe we should do \stemup -> \stemUp\slurUp\tieUp ?
562 str = re.sub ('\\\\stemup', '\\\\stemUp', str)
563 str = re.sub ('\\\\stemdown', '\\\\stemDown', str)
564 str = re.sub ('\\\\stemboth', '\\\\stemBoth', str)
566 str = re.sub ('\\\\slurup', '\\\\slurUp', str)
567 str = re.sub ('\\\\slurboth', '\\\\slurBoth', str)
568 str = re.sub ('\\\\slurdown', '\\\\slurDown', str)
569 str = re.sub ('\\\\slurdotted', '\\\\slurDotted', str)
570 str = re.sub ('\\\\slurnormal', '\\\\slurNoDots', str)
572 str = re.sub ('\\\\shiftoff', '\\\\shiftOff', str)
573 str = re.sub ('\\\\shifton', '\\\\shiftOn', str)
574 str = re.sub ('\\\\shiftonn', '\\\\shiftOnn', str)
575 str = re.sub ('\\\\shiftonnn', '\\\\shiftOnnn', str)
577 str = re.sub ('\\\\onevoice', '\\\\oneVoice', str)
578 str = re.sub ('\\\\voiceone', '\\\\voiceOne', str)
579 str = re.sub ('\\\\voicetwo', '\\\\voiceTwo', str)
580 str = re.sub ('\\\\voicethree', '\\\\voiceThree', str)
581 str = re.sub ('\\\\voicefour', '\\\\voiceFour', str)
583 # I don't know exactly when these happened...
584 # ugh, we loose context setting here...
585 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\stemUp\\\\slurUp\\\\tieUp', str)
586 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\stemDown\\\\slurDown\\\\tieDown', str)
587 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\stemBoth\\\\slurBoth\\\\tieBoth', str)
589 str = re.sub ('verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #1', str)
590 str = re.sub ('verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #-1', str)
591 str = re.sub ('verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #0', str)
593 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\\\1Up', str)
594 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\\\1Down', str)
595 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\\\1Both', str)
597 # (lacks capitalisation slur -> Slur)
598 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\1 \\\\override #\'direction = #1', str)
599 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\1 \\override #\'direction = #-1', str)
600 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\1 \\\\override #\'direction = #0', str)
603 str = re.sub ('\\\\property *[^ .]*[.]?dynamicDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\dynamicUp', str)
604 str = re.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\dynamicDown', str)
605 str = re.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?(0|(\\\\center))"?', '\\\\dynamicBoth', str)
607 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?(0|(""))"?', '\\\\\\1NoDots', str)
608 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?([1-9]+)"?', '\\\\\\1Dotted', str)
610 str = re.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?(0|(""))"?', '\\\\autoBeamOn', str)
611 str = re.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?([1-9]+)"?', '\\\\autoBeamOff', str)
617 conversions.append (((1,3,93), conv,
618 'property definiton case (eg. onevoice -> oneVoice)'))
623 str = re.sub ('ChordNames*', 'ChordNames', str)
624 if re.search ('\\\\textscript "[^"]* *"[^"]*"', str):
625 sys.stderr.write ('\n')
626 sys.stderr.write (NOT_SMART % "new \\textscript markup text")
628 str = re.sub ('\\textscript +("[^"]*")', '\\textscript #\\1', str)
632 conversions.append (((1,3,97), conv, 'ChordName -> ChordNames'))
635 # TODO: add lots of these
639 str = re.sub ('\\\\property *"?Voice"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Voice.TextScript \\\\set #\'font-style = #\'\\1', str)
640 str = re.sub ('\\\\property *"?Lyrics"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Lyrics.LyricText \\\\set #\'font-style = #\'\\1', str)
642 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?timeSignatureStyle"? *= *"([^"]*)"', '\\\\property \\1.TimeSignature \\\\override #\'style = #\'\\2', str)
644 str = re.sub ('"?timeSignatureStyle"? *= *#?""', 'TimeSignature \\\\override #\'style = ##f', str)
646 str = re.sub ('"?timeSignatureStyle"? *= *#?"([^"]*)"', 'TimeSignature \\\\override #\'style = #\'\\1', str)
648 str = re.sub ('#\'style *= #*"([^"])"', '#\'style = #\'\\1', str)
650 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?horizontalNoteShift"? *= *"?#?([-0-9]+)"?', '\\\\property \\1.NoteColumn \\\\override #\'horizontal-shift = #\\2', str)
653 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *""', '\\\\property \\1.Stem \\\\override #\'flag-style = ##f', str)
655 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *"([^"]*)"', '\\\\property \\1.Stem \\\\override #\'flag-style = #\'\\2', str)
658 conversions.append (((1,3,98), conv, 'CONTEXT.textStyle -> GROB.#font-style '))
662 str = re.sub ('"?beamAutoEnd_([0-9]*)"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end 1 \\1 * *) = \\2', str)
663 str = re.sub ('"?beamAutoBegin_([0-9]*)"? *= *(#\\([^)]*\))', 'autoBeamSettings \\push #\'(begin 1 \\1 * *) = \\2', str)
664 str = re.sub ('"?beamAutoEnd"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end * * * *) = \\1', str)
665 str = re.sub ('"?beamAutoBegin"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(begin * * * *) = \\1', str)
670 conversions.append (((1,3,102), conv, 'beamAutoEnd -> autoBeamSettings \\push (end * * * *)'))
675 str = re.sub ('\\\\push', '\\\\override', str)
676 str = re.sub ('\\\\pop', '\\\\revert', str)
680 conversions.append (((1,3,111), conv, '\\push -> \\override, \\pop -> \\revert'))
684 str = re.sub ('LyricVoice', 'LyricsVoice', str)
686 str = re.sub ('Chord[Nn]ames*.Chord[Nn]ames*', 'ChordNames.ChordName', str)
687 str = re.sub ('Chord[Nn]ames([ \t\n]+\\\\override)', 'ChordName\\1', str)
690 conversions.append (((1,3,113), conv, 'LyricVoice -> LyricsVoice'))
692 def regularize_id (str):
699 elif x in string.digits:
700 x = chr(ord (x) - ord ('0') +ord ('A'))
701 elif x not in string.letters:
703 elif x in string.lowercase and lastx == '_':
712 def regularize_dollar_reference (match):
713 return regularize_id (match.group (1))
714 def regularize_assignment (match):
715 return '\n' + regularize_id (match.group (1)) + ' = '
716 str = re.sub ('\$([^\t\n ]+)', regularize_dollar_reference, str)
717 str = re.sub ('\n([^ \t\n]+)[ \t]*= *', regularize_assignment, str)
720 conversions.append (((1,3,117), conv, 'identifier names: $!foo_bar_123 -> xfooBarABC'))
725 def regularize_paper (match):
726 return regularize_id (match.group (1))
728 str = re.sub ('(paper_[a-z]+)', regularize_paper, str)
729 str = re.sub ('sustainup', 'sustainUp', str)
730 str = re.sub ('nobreak', 'noBreak', str)
731 str = re.sub ('sustaindown', 'sustainDown', str)
732 str = re.sub ('sostenutoup', 'sostenutoUp', str)
733 str = re.sub ('sostenutodown', 'sostenutoDown', str)
734 str = re.sub ('unachorda', 'unaChorda', str)
735 str = re.sub ('trechorde', 'treChorde', str)
739 conversions.append (((1,3,120), conv, 'paper_xxx -> paperXxxx, pedalup -> pedalUp.'))
743 str = re.sub ('drarnChords', 'chordChanges', str)
744 str = re.sub ('\\musicalpitch', '\\pitch', str)
747 conversions.append (((1,3,122), conv, 'drarnChords -> chordChanges, \\musicalpitch -> \\pitch'))
751 str = re.sub ('ly-([sg])et-elt-property', 'ly-\\1et-grob-property', str)
754 conversions.append (((1,3,136), conv, 'ly-X-elt-property -> ly-X-grob-property'))
758 str = re.sub ('point-and-click +#t', 'point-and-click line-column-location', str)
761 conversions.append (((1,3,138), conv, 'point-and-click argument changed to procedure.'))
765 str = re.sub ('followThread', 'followVoice', str)
766 str = re.sub ('Thread.FollowThread', 'Voice.VoiceFollower', str)
767 str = re.sub ('FollowThread', 'VoiceFollower', str)
770 conversions.append (((1,3,138), conv, 'followThread -> followVoice.'))
774 str = re.sub ('font-point-size', 'font-design-size', str)
777 conversions.append (((1,3,139), conv, 'font-point-size -> font-design-size.'))
781 str = re.sub ('([a-zA-Z]*)NoDots', '\\1Solid', str)
784 conversions.append (((1,3,141), conv, 'xNoDots -> xSolid'))
788 str = re.sub ('([Cc])hord([ea])', '\\1ord\\2', str)
791 conversions.append (((1,3,144), conv, 'Chorda -> Corda'))
796 str = re.sub ('([A-Za-z]+)MinimumVerticalExtent', 'MinimumV@rticalExtent', str)
797 str = re.sub ('([A-Za-z]+)ExtraVerticalExtent', 'ExtraV@rticalExtent', str)
798 str = re.sub ('([A-Za-z]+)VerticalExtent', 'VerticalExtent', str)
799 str = re.sub ('ExtraV@rticalExtent', 'ExtraVerticalExtent', str)
800 str = re.sub ('MinimumV@rticalExtent', 'MinimumVerticalExtent', str)
803 conversions.append (((1,3,145), conv,
804 'ContextNameXxxxVerticalExtent -> XxxxVerticalExtent'))
808 str = re.sub ('\\\\key[ \t]*;', '\\key \\default;', str)
809 str = re.sub ('\\\\mark[ \t]*;', '\\mark \\default;', str)
811 # Make sure groups of more than one ; have space before
812 # them, so that non of them gets removed by next rule
813 str = re.sub ("([^ \n\t;]);(;+)", "\\1 ;\\2", str)
815 # Only remove ; that are not after spaces, # or ;
816 # Otherwise we interfere with Scheme comments,
817 # which is badbadbad.
818 str = re.sub ("([^ \t;#]);", "\\1", str)
821 conversions.append (((1,3,146), conv, 'semicolons removed'))
825 str = re.sub ('default-neutral-direction', 'neutral-direction',str)
827 conversions.append (((1,3,147), conv, 'default-neutral-direction -> neutral-direction'))
831 str = re.sub ('\(align', '(axis', str)
832 str = re.sub ('\(rows', '(columns', str)
834 conversions.append (((1,3,148), conv, '"(align" -> "(axis", "(rows" -> "(columns"'))
839 str = re.sub ('SystemStartDelimiter', 'systemStartDelimiter', str)
841 conversions.append (((1,5,33), conv, 'SystemStartDelimiter -> systemStartDelimiter'))
845 str = re.sub ('arithmetic-multiplier', 'spacing-increment', str)
846 str = re.sub ('arithmetic-basicspace', 'shortest-duration-space', str)
849 conversions.append (((1,5,38), conv, 'SystemStartDelimiter -> systemStartDelimiter'))
857 "Instrument_name": "instrument-name",
858 "Left_edge_item": "left-edge",
859 "Span_bar": "span-bar",
860 "Breathing_sign": "breathing-sign",
861 "Staff_bar": "staff-bar",
863 "Key_item": "key-signature",
864 "Time_signature": "time-signature",
867 props = match.group (1)
868 for (k,v) in break_dict.items():
869 props = re.sub (k, v, props)
870 return "breakAlignOrder = #'(%s)" % props
872 str = re.sub ("breakAlignOrder *= *#'\\(([a-z_\n\tA-Z ]+)\\)",
877 conversions.append (((1,5,40), conv, 'breakAlignOrder property names'))
882 str = re.sub ('noAutoBeaming *= *##f', 'autoBeaming = ##t', str)
883 str = re.sub ('noAutoBeaming *= *##t', 'autoBeaming = ##f', str)
886 conversions.append (((1,5,49), conv, 'noAutoBeaming -> autoBeaming'))
890 str = re.sub ('tuplet-bracket-visibility', 'bracket-visibility', str)
891 str = re.sub ('tuplet-number-visibility', 'number-visibility', str)
894 conversions.append (((1,5,52), conv, 'tuplet-X-visibility -> X-visibility'))
898 str = re.sub ('Pitch::transpose', 'ly-transpose-pitch', str)
902 conversions.append (((1,5,56), conv, 'Pitch::transpose -> ly-transpose-pitch'))
906 str = re.sub ('textNonEmpty *= *##t', "TextScript \\set #'no-spacing-rods = ##f", str)
907 str = re.sub ('textNonEmpty *= *##f', "TextScript \\set #'no-spacing-rods = ##t", str)
910 conversions.append (((1,5,58), conv, 'deprecate textNonEmpty'))
915 str = re.sub ('MinimumVerticalExtent', 'minimumV@rticalExtent', str)
916 str = re.sub ('minimumVerticalExtent', 'minimumV@rticalExtent', str)
917 str = re.sub ('ExtraVerticalExtent', 'extraV@rticalExtent', str)
918 str = re.sub ('extraVerticalExtent', 'extraV@rticalExtent', str)
919 str = re.sub ('VerticalExtent', 'verticalExtent', str)
920 str = re.sub ('extraV@rticalExtent', 'extraVerticalExtent', str)
921 str = re.sub ('minimumV@rticalExtent', 'minimumVerticalExtent', str)
924 conversions.append (((1,5,59), conv,
925 'XxxxVerticalExtent -> xxxVerticalExtent'))
929 str = re.sub ('visibility-lambda', 'break-visibility', str)
932 conversions.append (((1,5,62), conv,
933 'visibility-lambda -> break-visibility'))
938 if re.search (r'\addlyrics',str) \
939 and re.search ('automaticMelismata', str) == None:
940 sys.stderr.write ('\n')
941 sys.stderr.write (NOT_SMART % "automaticMelismata; turned on by default since 1.5.67.")
942 raise FatalConversionError ()
945 conversions.append (((1,5,67), conv,
946 'automaticMelismata turned on by default'))
950 str = re.sub ('ly-set-grob-property([^!])', 'ly-set-grob-property!\1', str)
951 str = re.sub ('ly-set-mus-property([^!])', 'ly-set-mus-property!\1', str)
954 conversions.append (((1,5,68), conv, 'ly-set-X-property -> ly-set-X-property!'))
958 str = re.sub ('extent-X', 'X-extent', str)
959 str = re.sub ('extent-Y', 'Y-extent', str)
962 conversions.append (((1,5,71), conv, 'extent-[XY] -> [XY]-extent'))
967 str = re.sub ("""#\(set! +point-and-click +line-column-location\)""",
968 """#(set-point-and-click! \'line-column)""", str)
969 str = re.sub ("""#\(set![ \t]+point-and-click +line-location\)""",
970 '#(set-point-and-click! \'line)', str)
971 str = re.sub ('#\(set! +point-and-click +#f\)',
972 '#(set-point-and-click! \'none)', str)
975 conversions.append (((1,5,72), conv, 'set! point-and-click -> set-point-and-click!'))
980 str = re.sub ('flag-style', 'stroke-style', str)
981 str = re.sub (r"""Stem([ ]+)\\override #'style""", r"""Stem \\override #'flag-style""", str);
982 str = re.sub (r"""Stem([ ]+)\\set([ ]+)#'style""", r"""Stem \\set #'flag-style""", str);
985 conversions.append (((1,6,5), conv, 'Stems: flag-style -> stroke-style; style -> flag-style'))
989 def subst_req_name (match):
990 return "(make-music-by-name \'%sEvent)" % regularize_id (match.group(1))
993 str = re.sub ('\\(ly-make-music *\"([A-Z][a-z_]+)_req\"\\)', subst_req_name, str)
994 str = re.sub ('Request_chord', 'EventChord', str)
997 conversions.append (((1,7,1), conv, 'ly-make-music foo_bar_req -> make-music-by-name FooBarEvent'))
1002 "text" : 'TextSpanEvent',
1003 "decrescendo" : 'DecrescendoEvent',
1004 "crescendo" : 'CrescendoEvent',
1005 "Sustain" : 'SustainPedalEvent',
1006 "slur" : 'SlurEvent',
1007 "UnaCorda" : 'UnaCordaEvent',
1008 "Sostenuto" : 'SostenutoEvent',
1010 def subst_ev_name (match):
1012 if re.search ('start', match.group(1)):
1015 mtype = spanner_subst[match.group(2)]
1016 return "(make-span-event '%s %s)" % (mtype , stype)
1018 def subst_definition_ev_name(match):
1019 return ' = #%s' % subst_ev_name (match)
1020 def subst_inline_ev_name (match):
1021 s = subst_ev_name (match)
1022 return '#(ly-export %s)' % s
1023 def subst_csp_definition (match):
1024 return ' = #(make-event-chord (list %s))' % subst_ev_name (match)
1025 def subst_csp_inline (match):
1026 return '#(ly-export (make-event-chord (list %s)))' % subst_ev_name (match)
1029 str = re.sub (r' *= *\\spanrequest *([^ ]+) *"([^"]+)"', subst_definition_ev_name, str)
1030 str = re.sub (r'\\spanrequest *([^ ]+) *"([^"]+)"', subst_inline_ev_name, str)
1031 str = re.sub (r' *= *\\commandspanrequest *([^ ]+) *"([^"]+)"', subst_csp_definition, str)
1032 str = re.sub (r'\\commandspanrequest *([^ ]+) *"([^"]+)"', subst_csp_inline, str)
1033 str = re.sub (r'ly-id ', 'ly-import ', str)
1035 str = re.sub (r' *= *\\script "([^"]+)"', ' = #(make-articulation "\\1")', str)
1036 str = re.sub (r'\\script "([^"]+)"', '#(ly-export (make-articulation "\\1"))', str)
1039 conversions.append (((1,7,2), conv, '\\spanrequest -> #(make-span-event .. ), \script -> #(make-articulation .. )'))
1043 str = re.sub (r'\(ly-', '(ly:', str)
1053 'music-duration-length',
1055 'duration-dotcount',
1058 'transpose-key-alist',
1062 'set-point-and-click!',
1071 'music-duration-compress',
1072 'set-point-and-click!'
1075 origre = r'\b(%s)' % string.join (changed, '|')
1077 str = re.sub (origre, r'ly:\1',str)
1078 str = re.sub ('set-point-and-click!', 'set-point-and-click', str)
1082 conversions.append (((1,7,3), conv, 'ly- -> ly:'))
1086 if re.search ('new-chords-done',str):
1089 str = re.sub (r'<<', '< <', str)
1090 str = re.sub (r'>>', '> >', str)
1093 conversions.append (((1,7,4), conv, '<< >> -> < < > >'))
1097 str = re.sub (r"\\transpose", r"\\transpose c'", str)
1098 str = re.sub (r"\\transpose c' *([a-z]+)'", r"\\transpose c \1", str)
1100 conversions.append (((1,7,5), conv, '\\transpose TO -> \\transpose FROM TO'))
1118 origstr = string.join (kws, '|')
1119 str = re.sub (r'([^_^-])\\(%s)\b' % origstr, r'\1-\\\2', str)
1121 conversions.append (((1,7,6), conv, 'note\\script -> note-\script'))
1126 str = re.sub (r"\\property *ChordNames *\. *ChordName *\\(set|override) *#'style *= *#('[a-z]+)",
1127 r"#(set-chord-name-style \2)", str)
1128 str = re.sub (r"\\property *ChordNames *\. *ChordName *\\revert *#'style",
1131 conversions.append (((1,7,10), conv, "\property ChordName #'style -> #(set-chord-name-style 'style)"))
1137 str = re.sub (r"ly:transpose-pitch", "ly:pitch-transpose", str)
1140 conversions.append (((1,7,11), conv, "transpose-pitch -> pitch-transpose"))
1144 str = re.sub (r"ly:get-molecule-extent", "ly:molecule-get-extent", str)
1145 str = re.sub (r"ly:set-molecule-extent!", "ly:molecule-set-extent!", str)
1146 str = re.sub (r"ly:add-molecule", "ly:molecule-add", str)
1147 str = re.sub (r"ly:combine-molecule-at-edge", "ly:molecule-combine-at-edge", str)
1148 str = re.sub (r"ly:align-to!", "ly:molecule-align-to!", str)
1152 conversions.append (((1,7,13), conv, "ly:XX-molecule-YY -> ly:molecule-XX-YY"))
1156 str = re.sub (r"linewidth *= *-[0-9.]+ *(\\mm|\\cm|\\in|\\pt)?", 'raggedright = ##t', str )
1159 conversions.append (((1,7,15), conv, "linewidth = -1 -> raggedright = ##t"))
1163 str = re.sub ("divisiomaior",
1164 "divisioMaior", str)
1165 str = re.sub ("divisiominima",
1166 "divisioMinima", str)
1167 str = re.sub ("divisiomaxima",
1168 "divisioMaxima", str)
1171 conversions.append (((1,7,16), conv, "divisiomaior -> divisioMaior"))
1175 str = re.sub ("Skip_req_swallow_translator",
1176 "Skip_event_swallow_translator", str)
1179 conversions.append (((1,7,17), conv, "Skip_req -> Skip_event"))
1183 str = re.sub ("groupOpen",
1185 str = re.sub ("groupClose",
1187 str = re.sub ("#'outer",
1188 "#'enclose-bounds", str)
1192 conversions.append (((1,7,18), conv,
1193 """groupOpen/Close -> start/stopGroup,
1194 #'outer -> #'enclose-bounds
1199 if re.search( r'\\GraceContext', str):
1200 sys.stderr.write ('\n')
1201 sys.stderr.write (NOT_SMART % "GraceContext")
1202 sys.stderr.write (FROM_TO \
1203 % ("GraceContext", "#(add-to-grace-init .. )"))
1204 sys.stderr.write ('\n')
1205 sys.stderr.write (UPDATE_MANUALLY)
1206 sys.stderr.write ('\n')
1207 raise FatalConversionError ()
1209 str = re.sub ('HaraKiriStaffContext', 'RemoveEmptyStaffContext', str)
1212 conversions.append (((1,7,19), conv,"remove GraceContext"))
1219 r"(set|override|revert) *#'type",
1224 conversions.append (((1,7,22), conv,"#'type -> #'style"))
1229 "barNonAuto *= *##t",
1230 "automaticBars = ##f",
1233 "barNonAuto *= *##f",
1234 "automaticBars = ##t",
1238 conversions.append (((1,7,23), conv,"barNonAuto -> automaticBars"))
1243 if re.search( r'-(start|stop)Cluster', str):
1244 sys.stderr.write ('\n')
1245 sys.stderr.write (NOT_SMART % "Cluster syntax")
1246 sys.stderr.write ('\n')
1247 sys.stderr.write (UPDATE_MANUALLY)
1248 sys.stderr.write ('\n')
1250 raise FatalConversionError ()
1254 conversions.append (((1,7,24), conv,"cluster syntax"))
1258 str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\(override|set) *#'pedal-type *",
1259 r"\property Staff.pedal\1Style ", str)
1260 str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\revert *#'pedal-type", '', str)
1263 conversions.append (((1,7,28), conv,"new Pedal style syntax"))
1272 origstr = '<%s>' % str
1273 if re.search (r'\\\\', str):
1276 if re.search (r'\\property', str):
1279 if re.match (r'^\s*\)?\s*\\[a-zA-Z]+', str):
1283 def sub_durs (m, durs = durs):
1284 durs.append(m.group(2))
1287 str = re.sub (r"([a-z]+[,'!? ]*)([0-9]+\.*)", sub_durs, str)
1294 return '<%s>' % m.group (1)
1301 while last_str <> str:
1304 def sub_tremolos (m, slur_strs = slur_strs):
1306 if tr not in slur_strs:
1307 slur_strs.append (tr)
1310 str = re.sub (r"([a-z]+[',!? ]*)(:[0-9]+)",
1313 def sub_dyn_end (m, dyns = dyns):
1315 return ' ' + m.group(2)
1317 str = re.sub (r'(\\!)\s*([a-z]+)', sub_dyn_end, str)
1318 def sub_slurs(m, slur_strs = slur_strs):
1319 if '-)' not in slur_strs:
1320 slur_strs.append (')')
1323 def sub_p_slurs(m, slur_strs = slur_strs):
1324 if '-\)' not in slur_strs:
1325 slur_strs.append ('\)')
1328 str = re.sub (r"\)[ ]*([a-z]+)", sub_slurs, str)
1329 str = re.sub (r"\\\)[ ]*([a-z]+)", sub_p_slurs, str)
1330 def sub_begin_slurs(m, slur_strs = slur_strs):
1331 if '-(' not in slur_strs:
1332 slur_strs.append ('(')
1335 str = re.sub (r"([a-z]+[,'!?0-9 ]*)\(",
1336 sub_begin_slurs, str)
1337 def sub_begin_p_slurs(m, slur_strs = slur_strs):
1338 if '-\(' not in slur_strs:
1339 slur_strs.append ('\(')
1342 str = re.sub (r"([a-z]+[,'!?0-9 ]*)\\\(",
1343 sub_begin_p_slurs, str)
1345 def sub_dyns (m, slur_strs = slur_strs):
1347 if s == '@STARTCRESC@':
1348 slur_strs.append ("\\<")
1349 elif s == '@STARTDECRESC@':
1350 slur_strs.append ("\\>")
1352 slur_strs.append ('\\!')
1355 str = re.sub (r'@STARTCRESC@', sub_dyns, str)
1356 str = re.sub (r'-?\\!', sub_dyns, str)
1358 def sub_articulations (m, slur_strs = slur_strs):
1360 if a not in slur_strs:
1361 slur_strs.append (a)
1364 str = re.sub (r"([_^-]\@ACCENT\@)", sub_articulations,
1366 str = re.sub (r"([_^-]\\[a-z]+)", sub_articulations,
1368 str = re.sub (r"([_^-][>_.+|^-])", sub_articulations,
1370 str = re.sub (r'([_^-]"[^"]+")', sub_articulations,
1373 def sub_pslurs(m, slur_strs = slur_strs):
1374 slur_strs.append (' \\)')
1376 str = re.sub (r"\\\)[ ]*([a-z]+)", sub_pslurs, str)
1380 suffix = string.join (slur_strs, '') + string.join (pslur_strs,
1382 + string.join (dyns, '')
1384 return '@STARTCHORD@%s@ENDCHORD@%s%s' % (str , dur_str, suffix)
1388 def sub_chords (str):
1393 marker_str = '%% new-chords-done %%'
1395 if re.search (marker_str,str):
1397 str = re.sub ('<<', '@STARTCHORD@', str)
1398 str = re.sub ('>>', '@ENDCHORD@', str)
1400 str = re.sub (r'\\<', '@STARTCRESC@', str)
1401 str = re.sub (r'\\>', '@STARTDECRESC@', str)
1402 str = re.sub (r'([_^-])>', r'\1@ACCENT@', str)
1403 str = re.sub (r'<([^<>{}]+)>', sub_chord, str)
1405 # add dash: -[, so that [<<a b>> c d] becomes
1407 # and gets skipped by articulation_substitute
1408 str = re.sub (r'\[ *(@STARTCHORD@[^@]+@ENDCHORD@[0-9.]*)',
1410 str = re.sub (r'\\! *(@STARTCHORD@[^@]+@ENDCHORD@[0-9.]*)',
1413 str = re.sub (r'<([^?])', r'%s\1' % simstart, str)
1414 str = re.sub (r'>([^?])', r'%s\1' % simend, str)
1415 str = re.sub ('@STARTCRESC@', r'\\<', str)
1416 str = re.sub ('@STARTDECRESC@', r'\\>' ,str)
1417 str = re.sub (r'\\context *Voice *@STARTCHORD@',
1418 '@STARTCHORD@', str)
1419 str = re.sub ('@STARTCHORD@', chordstart, str)
1420 str = re.sub ('@ENDCHORD@', chordend, str)
1421 str = re.sub (r'@ACCENT@', '>', str)
1424 def text_markup (str):
1425 str = re.sub (r"""([-_^]) *# *' *\( *music *(\"[^"]*\") *\)""",
1426 r"\1\\markup { \\musicglyph #\2 }", str)
1427 str = re.sub (r"""([-_^]) *# *' *\( *([a-z]+) *([^()]*)\)""",
1428 r"\1\\markup { \\\2 \3 }", str)
1429 str = re.sub (r"""\\mark *# *' *\( *music *(\"[^"]*\") *\)""",
1430 r"\\mark \\markup { \\musicglyph #\1 }", str)
1431 str = re.sub (r"""\\mark *# *' *\( *([a-z]+) *([^()]*)\)""",
1432 r"\\mark \\markup { \\\1 \2 }", str)
1435 def articulation_substitute (str):
1436 str = re.sub (r"""([^-])\[ *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
1438 str = re.sub (r"""([^-])\\\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
1440 str = re.sub (r"""([^-\\])\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
1442 str = re.sub (r"""([^-])\\! *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
1446 def conv_relative(str):
1447 if re.search (r"\\relative", str):
1448 str= "#(ly:set-option 'old-relative)\n" + str
1453 str = re.sub (r"#'\(\)", "@SCM_EOL@", str)
1454 str = conv_relative (str)
1455 str = sub_chords (str)
1457 str = text_markup (str)
1458 str = articulation_substitute (str)
1459 str = re.sub ("@SCM_EOL@", "#'()", str)
1463 conversions.append (((1,9,0), conv, """New relative mode,
1464 Postfix articulations, new text markup syntax, new chord syntax."""))
1468 if re.search ("font-style",str):
1469 sys.stderr.write ('\n')
1470 sys.stderr.write (NOT_SMART % "font-sytle")
1471 sys.stderr.write ('\n')
1472 sys.stderr.write (UPDATE_MANUALLY)
1473 sys.stderr.write ('\n')
1475 raise FatalConversionError ()
1477 str = re.sub (r'-\\markup', r'@\\markup', str)
1478 str = re.sub (r'-\\', r'\\', str)
1479 str = re.sub (r'-\)', ')', str)
1480 str = re.sub (r'-\(', '(', str)
1481 str = re.sub ('-\[', '[', str)
1482 str = re.sub ('-\]', ']', str)
1483 str = re.sub ('-~', '~', str)
1484 str = re.sub (r'@\\markup', r'-\\markup', str)
1487 conversions.append (((1,9,1), conv, """Remove - before articulation"""))
1490 str = re.sub ('ly:set-context-property',
1491 'ly:set-context-property!', str)
1492 str = re.sub ('\\\\newcontext', '\\\\new', str)
1493 str = re.sub ('\\\\grace[\t\n ]*([^{ ]+)',
1494 r'\\grace { \1 }', str)
1495 str = re.sub ("\\\\grace[\t\n ]*{([^}]+)}",
1497 \\property Voice.Stem \\override #'stroke-style = #"grace"
1499 \\property Voice.Stem \\revert #'stroke-style }
1504 conversions.append (((1,9,2), conv, """\\newcontext -> \\new"""))
1508 str = re.sub ('accacciatura',
1509 'acciaccatura', str)
1511 if re.search ("context-spec-music", str):
1512 sys.stderr.write ('\n')
1513 sys.stderr.write (NOT_SMART % "context-spec-music")
1514 sys.stderr.write ('\n')
1515 sys.stderr.write (UPDATE_MANUALLY)
1516 sys.stderr.write ('\n')
1518 raise FatalConversionError ()
1520 str = re.sub ('fingerHorizontalDirection *= *#(LEFT|-1)',
1521 "fingeringOrientations = #'(up down left)", str)
1522 str = re.sub ('fingerHorizontalDirection *= *#(RIGHT|1)',
1523 "fingeringOrientations = #'(up down right)", str)
1527 conversions.append (((1,9,3), conv,
1528 """\\acciaccatura misspelling, fingerHorizontalDirection -> fingeringOrientations"""))
1532 if re.search ('\\figures', str):
1533 sys.stderr.write ("Warning: attempting automatic \\figures conversion. Check results!");
1536 def figures_replace (m):
1538 s = re.sub ('<', '@FIGOPEN@',s)
1539 s = re.sub ('>', '@FIGCLOSE@',s)
1540 return '\\figures { %s }' % s
1542 str = re.sub (r'\\figures[ \t\n]*{([^}]+)}', figures_replace, str)
1543 str = re.sub (r'\\<', '@STARTCRESC@', str)
1544 str = re.sub (r'\\>', '@STARTDECRESC@', str)
1545 str = re.sub (r'([-^_])>', r'\1@ACCENT@', str)
1546 str = re.sub (r'<<', '@STARTCHORD@', str)
1547 str = re.sub (r'>>', '@ENDCHORD@', str)
1548 str = re.sub (r'>', '@ENDSIMUL@', str)
1549 str = re.sub (r'<', '@STARTSIMUL@', str)
1550 str = re.sub ('@STARTDECRESC@', '\\>', str)
1551 str = re.sub ('@STARTCRESC@', '\\<', str)
1552 str = re.sub ('@ACCENT@', '>', str)
1553 str = re.sub ('@ENDCHORD@', '>', str)
1554 str = re.sub ('@STARTCHORD@', '<', str)
1555 str = re.sub ('@STARTSIMUL@', '<<', str)
1556 str = re.sub ('@ENDSIMUL@', '>>', str)
1557 str = re.sub ('@FIGOPEN@', '<', str)
1558 str = re.sub ('@FIGCLOSE@', '>', str)
1562 conversions.append (((1,9,4), conv, 'Swap < > and << >>'))
1566 str = re.sub ('HaraKiriVerticalGroup', 'RemoveEmptyVerticalGroup', str)
1570 conversions.append (((1,9,5), conv, 'HaraKiriVerticalGroup -> RemoveEmptyVerticalGroup'))
1573 if re.search ("ly:get-font", str) :
1574 sys.stderr.write ('\n')
1575 sys.stderr.write (NOT_SMART % "(ly:-get-font")
1576 sys.stderr.write ('\n')
1577 sys.stderr.write (FROM_TO \
1578 % ("(ly:paper-get-font (ly:grob-get-paper foo) .. )",
1579 "(ly:paper-get-font (ly:grob-get-paper foo) .. )"))
1580 sys.stderr.write (UPDATE_MANUALLY)
1581 sys.stderr.write ('\n')
1582 raise FatalConversionError ()
1584 if re.search ("\\pitch *#", str) :
1585 sys.stderr.write ('\n')
1586 sys.stderr.write (NOT_SMART % "\\pitch")
1587 sys.stderr.write ('\n')
1588 sys.stderr.write ("Use Scheme code to construct arbitrary note events.")
1590 raise FatalConversionError ()
1595 conversions.append (((1,9,6), conv, 'ly:get-font deprecated.'))
1598 def sub_alteration (m):
1602 '-2': 'DOUBLE-FLAT',
1605 '2': 'DOUBLE-SHARP',
1608 return '(ly:make-pitch %s %s %s)' % (m.group(1), m.group (2),
1611 str =re.sub ("\\(ly:make-pitch *([0-9-]+) *([0-9-]+) *([0-9-]+) *\\)",
1612 sub_alteration, str)
1615 str = re.sub ("ly:verbose", "ly:get-option 'verbose", str)
1617 m= re.search ("\\\\outputproperty #([^#]+)[\t\n ]*#'([^ ]+)", str)
1620 r"""\outputproperty found,
1621 Please hand-edit, using
1623 \applyoutput #(outputproperty-compatibility %s '%s <GROB PROPERTY VALUE>)
1625 as a substitution text.""" % (m.group (1), m.group (2)) )
1626 raise FatalConversionError ()
1628 if re.search ("ly:(make-pitch|pitch-alteration)", str) \
1629 or re.search ("keySignature", str):
1630 sys.stderr.write ('\n')
1631 sys.stderr.write (NOT_SMART % "pitches")
1632 sys.stderr.write ('\n')
1634 """The alteration field of Scheme pitches was multiplied by 2
1635 to support quarter tone accidentals. You must update the following constructs by manually:
1637 * calls of ly:make-pitch and ly:pitch-alteration
1638 * keySignature settings made with \property
1640 raise FatalConversionError ()
1643 conversions.append (((1,9,7), conv,
1644 '''use symbolic constants for alterations,
1645 remove \\outputproperty, move ly:verbose into ly:get-option'''))
1649 if re.search ("dash-length",str):
1650 sys.stderr.write ('\n')
1651 sys.stderr.write (NOT_SMART % "dash-length")
1652 sys.stderr.write ('\n')
1653 sys.stderr.write (FROM_TO % ("dash-length", "dash-fraction"))
1654 sys.stderr.write ('\n')
1655 sys.stderr.write (UPDATE_MANUALLY)
1656 sys.stderr.write ('\n')
1657 raise FatalConversionError ()
1660 conversions.append (((1,9,8), conv, """dash-length -> dash-fraction"""))
1665 return "#'font-size = #%d" % (2*string.atoi (match.group (1)))
1667 str =re.sub (r"#'font-relative-size\s*=\s*#\+?([0-9-]+)", func, str)
1668 str =re.sub (r"#'font-family\s*=\s*#'ancient",
1669 r"#'font-family = #'music", str)
1673 conversions.append (((2,1,1), conv, """font-relative-size -> font-size"""))
1676 str =re.sub (r"ly:get-music-length", "ly:music-length", str)
1679 conversions.append (((2,1,2), conv, """ly:get-music-length -> ly:music-length"""))
1682 str =re.sub (r"\.\s+stz=", ". instr ", str)
1685 conversions.append (((2,1,3), conv, """stanza -> instrument"""))
1696 return r" \property %s.melismaBusyProperties \unset" % c
1698 return r"\property %s.melismaBusyProperties = #'(melismaBusy)" % c
1700 str = re.sub (r"\\property ([a-zA-Z]+)\s*\.\s*automaticMelismata\s*=\s*##([ft])", func, str)
1703 conversions.append (((2,1,4), conv, """removal of automaticMelismata; use melismaBusyProperties instead."""))
1708 str =re.sub (r"\\translator\s+([a-zA-Z]+)", r"\\change \1", str)
1711 conversions.append (((2,1,7), conv, """\\translator Staff -> \\change Staff"""))
1714 str =re.sub (r"\\newaddlyrics", r"\\lyricsto", str)
1717 conversions.append (((2,1,10), conv, """\\newaddlyrics -> \\lyricsto"""))
1720 str = re.sub (r'\\include\s*"paper([0-9]+)(-init)?.ly"',
1721 r"#(set-staff-size \1)", str)
1723 def sub_note (match):
1725 log = string.atoi (match.group (1))
1726 dots = string.atoi (match.group (2))
1729 dur = '%d' % (1 << log)
1731 dur = { -1 : 'breve',
1737 return r'\note #"%s" #%s' % (dur, match.group (3))
1739 str = re.sub (r'\\note\s+#([0-9-]+)\s+#([0-9]+)\s+#([0-9.-]+)',
1743 conversions.append (((2,1,11), conv, """\\include "paper16.ly" -> #(set-staff-size 16)
1744 \\note #3 #1 #1 -> \\note #"8." #1
1749 str =re.sub (r"OttavaSpanner", r"OttavaBracket", str)
1752 conversions.append (((2,1,12), conv, """OttavaSpanner -> OttavaBracket"""))
1756 str =re.sub (r"\(set-staff-size ", r"(set-global-staff-size ", str)
1759 conversions.append (((2,1,13), conv, """set-staff-size -> set-global-staff-size"""))
1762 str =re.sub (r"#'style\s*=\s*#'dotted-line",
1763 r"#'dash-fraction = #0.0 ", str)
1766 conversions.append (((2,1,14), conv, """style = dotted -> dash-fraction = 0"""))
1769 str =re.sub (r'LyricsVoice\s*\.\s*instrument\s*=\s*("[^"]*")',
1770 r'LyricsVoice . vocalName = \1', str)
1772 str =re.sub (r'LyricsVoice\s*\.\s*instr\s*=\s*("[^"]*")',
1773 r'LyricsVoice . vocNam = \1', str)
1776 conversions.append (((2,1,15), conv, """LyricsVoice . instr(ument) -> vocalName"""))
1790 return '\\%s' % d[m.group (1)]
1792 str = re.sub (r'\\musicglyph\s*#"accidentals-([0-9-]+)"',
1796 conversions.append (((2,1,16), conv, """\\musicglyph #"accidentals-NUM" -> \\sharp/flat/etc."""))
1801 if re.search (r'\\partcombine', str):
1802 sys.stderr.write ('\n')
1803 sys.stderr.write (NOT_SMART % "\\partcombine")
1804 sys.stderr.write ('\n')
1805 sys.stderr.write (UPDATE_MANUALLY)
1806 sys.stderr.write ('\n')
1807 raise FatalConversionError ()
1809 # this rule doesn't really work,
1810 # too lazy to figure out why.
1811 str = re.sub (r'\\context\s+Voice\s*=\s*one\s*\\partcombine\s+Voice\s*\\context\s+Thread\s*=\s*one(.*)\s*'
1812 + r'\\context\s+Thread\s*=\s*two',
1813 '\\\\newpartcombine\n\\1\n', str)
1818 conversions.append (((2,1,17), conv, """\\partcombine syntax change to \\newpartcombine"""))
1822 str = re.sub (r'\\newpartcombine', r'\\partcombine', str)
1823 str = re.sub (r'\\autochange\s+Staff', r'\\autochange ', str)
1826 conversions.append (((2,1,18), conv, """\\newpartcombine -> \\partcombine,
1827 \\autochange Staff -> \\autochange
1834 str = re.sub (r'\\include "drumpitch-init.ly"','', str)
1835 str = re.sub (r'\\pitchnames ','pitchnames = ', str)
1836 str = re.sub (r'\\chordmodifiers ','chordmodifiers = ', str)
1837 str = re.sub (r'\bdrums\b\s*=','drumContents = ', str)
1838 str = re.sub (r'\\drums\b','\\drumContents ', str)
1841 if re.search ('drums->paper', str):
1842 sys.stderr.write ("\nDrum notation found. Check file manually!")
1844 str = re.sub (r"""\\apply\s+#\(drums->paper\s+'([a-z]+)\)""",
1845 r"""\property DrumStaff.drumStyleTable = #\1-style""",
1848 if re.search ('Thread', str):
1849 sys.stderr.write ("\nThread found. Check file manually!\n");
1851 str = re.sub (r"""(\\once\s*)?\\property\s+Thread\s*\.\s*NoteHead\s*"""
1852 + r"""\\(set|override)\s*#'style\s*=\s*#'harmonic"""
1853 + r"""\s+([a-z]+[,'=]*)([0-9]*\.*)"""
1854 ,r"""<\3\\harmonic>\4""", str)
1856 str = re.sub (r"""\\new Thread""", """\context Voice""", str)
1857 str = re.sub (r"""Thread""", """Voice""", str)
1859 if re.search ('\bLyrics\b', str):
1860 sys.stderr.write ("\nLyrics found. Check file manually!\n");
1862 str = re.sub (r"""LyricsVoice""", r"""L@ricsVoice""", str)
1863 str = re.sub (r"""\bLyrics\b""", r"""LyricsVoice""", str)
1864 str = re.sub (r"""LyricsContext""", r"""LyricsVoiceContext""", str)
1865 str = re.sub (r"""L@ricsVoice""", r"""LyricsVoice""",str)
1870 conversions.append (((2,1,19), conv, """Drum notation changes, Removing \\chordmodifiers, \\notenames.
1871 Harmonic notes. Thread context removed. Lyrics context removed."""))
1874 str = re.sub (r'nonevent-skip', 'skip-music', str)
1877 conversions.append (((2,1,20), conv, """nonevent-skip -> skip-music""" ))
1880 str = re.sub (r'molecule-callback', 'print-function', str)
1881 str = re.sub (r'brew_molecule', 'print', str)
1882 str = re.sub (r'brew-new-markup-molecule', 'Text_item::print', str)
1883 str = re.sub (r'LyricsVoice', 'Lyrics', str)
1884 str = re.sub (r'tupletInvisible',
1885 r"TupletBracket \\set #'transparent", str)
1886 # str = re.sub (r'molecule', 'collage', str)
1887 #molecule -> collage
1888 str = re.sub (r"\\property\s+[a-zA-Z]+\s*\.\s*[a-zA-Z]+\s*"
1889 + r"\\set\s*#'X-extent-callback\s*=\s*#Grob::preset_extent",
1894 conversions.append (((2,1,21), conv, """molecule-callback -> print-function,
1895 brew_molecule -> print
1896 brew-new-markup-molecule -> Text_item::print
1897 LyricsVoice -> Lyrics
1898 tupletInvisible -> TupletBracket \set #'transparent
1899 Grob::preset_extent removed.
1904 str = re.sub (r'(\\property[^=]+)=\s*([-0-9]+)',
1906 str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\=]+)\s*\\(set|override)',
1907 r"\\overrid@ \1.\2 ", str)
1908 str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*=\s*',
1909 r'\\s@t \1.\2 = ', str)
1910 str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*\\unset',
1911 r'\\uns@t \1.\2 ', str)
1912 str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*\\revert'
1913 + r"\s*#'([-a-z0-9_]+)",
1914 r"\\rev@rt \1.\2 #'\3", str)
1915 str = re.sub (r'Voice\.', '', str)
1916 str = re.sub (r'Lyrics\.', '', str)
1917 str = re.sub (r'ChordNames\.', '', str)
1919 str = re.sub ('rev@rt', 'revert',str)
1920 str = re.sub ('s@t', 'set',str)
1921 str = re.sub ('overrid@', 'override',str)
1923 str = re.sub ('molecule', 'stencil', str)
1924 str = re.sub ('Molecule', 'Stencil', str)
1927 conversions.append (((2,1,22), conv, """new syntax for property settings:
1928 \\set A.B = #C , \\unset A.B
1929 \\override A.B #C = #D, \\revert A.B #C
1934 def subst_in_trans (match):
1936 s = re.sub (r'\s([a-zA-Z]+)\s*\\override',
1937 r' \\override \1', s)
1938 s = re.sub (r'\s([a-zA-Z]+)\s*\\set',
1939 r' \\override \1', s)
1940 s = re.sub (r'\s([a-zA-Z]+)\s*\\revert',
1943 str = re.sub (r'\\(translator|with)\s*{[^}]+}', subst_in_trans, str)
1947 context = m.group ('context')
1950 context = " '%s" % context[:-1] # -1: remove .
1954 d['context'] = context
1956 return r"""#(override-auto-beam-setting %(prop)s %(num)s %(den)s%(context)s)""" % d
1958 str = re.sub (r"""\\override\s*(?P<context>[a-zA-Z]+\s*\.\s*)?autoBeamSettings"""
1959 +r"""\s*#(?P<prop>[^=]+)\s*=\s*#\(ly:make-moment\s+(?P<num>\d+)\s+(?P<den>\d)\s*\)""",
1964 conversions.append (((2,1,23), conv, """Property setting syntax in \\translator{ }"""))
1966 str = re.sub (r'music-list\?', 'ly:music-list?', str)
1967 str = re.sub (r'\|\s*~', '~ |', str)
1970 conversions.append (((2,1,24), conv, """music-list? -> ly:music-list?"""))
1973 str = re.sub (r'ly:get-spanner-bound', 'ly:spanner-get-bound', str)
1974 str = re.sub (r'ly:get-extent', 'ly:grob-extent', str)
1975 str = re.sub (r'ly:get-system', 'ly:grob-system', str)
1976 str = re.sub (r'ly:get-original', 'ly:grob-original', str)
1977 str = re.sub (r'ly:get-parent', 'ly:grob-parent', str)
1978 str = re.sub (r'ly:get-broken-into', 'ly:spanner-broken-into', str)
1979 str = re.sub (r'Melisma_engraver', 'Melisma_translator', str)
1980 if re.search ("ly:get-paper-variable", str):
1981 sys.stderr.write ('\n')
1982 sys.stderr.write (NOT_SMART % "ly:paper-get-variable")
1983 sys.stderr.write ('\n')
1984 sys.stderr.write ('use (ly:paper-lookup (ly:grob-paper ))')
1985 raise FatalConversionError ()
1987 str = re.sub (r'\\defaultAccidentals', "#(set-accidental-style 'default)", str)
1988 str = re.sub (r'\\voiceAccidentals', "#(set-accidental-style 'voice)", str)
1989 str = re.sub (r'\\modernAccidentals', "#(set-accidental-style 'modern)", str)
1990 str = re.sub (r'\\modernCautionaries', "#(set-accidental-style 'modern-cautionary)", str)
1991 str = re.sub (r'\\modernVoiceAccidental', "#(set-accidental-style 'modern-voice)", str)
1992 str = re.sub (r'\\modernVoiceCautionaries', "#(set-accidental-style 'modern-voice-cautionary)", str)
1993 str = re.sub (r'\\pianoAccidentals', "#(set-accidental-style 'piano)", str)
1994 str = re.sub (r'\\pianoCautionaries', "#(set-accidental-style 'piano-cautionary)", str)
1995 str = re.sub (r'\\forgetAccidentals', "#(set-accidental-style 'forget)", str)
1996 str = re.sub (r'\\noResetKey', "#(set-accidental-style 'no-reset)", str)
2000 conversions.append (((2,1,25), conv, """Scheme grob function renaming"""))
2004 str = re.sub ('ly:set-grob-property!', 'ly:grob-set-property!',str)
2005 str = re.sub ('ly:set-mus-property!', 'ly:music-set-property!',str)
2006 str = re.sub ('ly:set-context-property!', 'ly:context-set-property!', str)
2007 str = re.sub ('ly:get-grob-property', 'ly:grob-property',str)
2008 str = re.sub ('ly:get-mus-property', 'ly:music-property',str)
2009 str = re.sub ('ly:get-context-property', 'ly:context-property',str)
2013 conversions.append (((2,1,26), conv, """More Scheme function renaming"""))
2017 g = string.atoi (m.group (2))
2025 lower_pitches = filter (lambda x : x <= g, [0, 2, 4, 5, 7, 9, 11, 12])
2026 s = len (lower_pitches) -1
2027 a = g - lower_pitches [-1]
2030 print s , lower_pitches, g, a, s
2032 str += ['eses', 'es', '', 'is', 'isis'][a + 2]
2034 str += ',' * (-o - 1)
2036 str += "'" * (o + 1)
2038 return '\\transposition %s ' % str
2041 str = re.sub (r"\\set ([A-Za-z]+\s*\.\s*)?transposing\s*=\s*#([-0-9]+)",
2045 conversions.append (((2,1,27), conv, """property transposing -> tuning"""))
2048 str = re.sub (r'make-music-by-name', 'make-music', str)
2049 str = re.sub (r"\\override\s+.*Arpeggio\s+#.print-function\s+=\s+\\arpeggioBracket", r"\\arpeggioBracket", str)
2052 conversions.append (((2,1,28), conv,
2053 """make-music-by-name -> make-music,
2054 new syntax for setting \\arpeggioBracket"""))
2057 str = re.sub (r'\\center([^-])', '\\center-align\\1', str)
2058 str = re.sub (r'\\translator', '\\context', str)
2061 conversions.append (((2,1,29), conv,
2062 '\\center -> \\center-align, \\translator -> \\context'))
2066 str = re.sub (r'\\threeq(flat|sharp)', r'\\sesqui\1', str)
2067 str = re.sub (r'ly:stencil-get-extent',
2068 'ly:stencil-extent', str)
2069 str = re.sub (r'ly:translator-find',
2070 'ly:context-find', str)
2071 str = re.sub ('ly:unset-context-property','ly:context-unset-property',
2074 str = re.sub (r'ly:get-mutable-properties',
2075 'ly:mutable-music-properties',str)
2076 str = re.sub (r'centralCPosition',
2077 'middleCPosition',str)
2080 conversions.append (((2,1,30), conv,
2081 '''\\threeq{flat,sharp} -> \\sesqui{flat,sharp}
2082 ly:get-mutable-properties -> ly:mutable-music-properties
2083 centralCPosition -> middleCPosition
2084 ly:unset-context-property -> ly:context-unset-property
2085 ly:translator-find -> ly:context-find
2086 ly:get-stencil-extent -> ly:stencil-extent
2091 str = re.sub (r'\\alias\s*"?Timing"?', '', str)
2094 conversions.append (((2,1,31), conv,
2095 '''remove \\alias Timing'''))
2098 str = re.sub (r"(\\set\s+)?(?P<context>(Score\.)?)breakAlignOrder\s*=\s*#'(?P<list>[^\)]+)",
2099 r"\n\\override \g<context>BreakAlignment #'break-align-orders = "
2100 + "#(make-vector 3 '\g<list>)", str)
2104 conversions.append (((2,1,33), conv,
2105 '''breakAlignOrder -> break-align-orders.'''))
2108 str = re.sub (r"\(set-paper-size",
2109 "(set-default-paper-size",str)
2112 conversions.append (((2,1,34), conv,
2113 '''set-paper-size -> set-default-paper-size.'''))
2116 str = re.sub (r"ly:mutable-music-properties",
2117 "ly:music-mutable-properties", str)
2120 conversions.append (((2,1, 36), conv,
2121 '''ly:mutable-music-properties -> ly:music-mutable-properties'''))
2128 conversions.append (((2, 2, 0), conv,
2129 '''clean up version. '''))
2132 return re.sub (r'\\apply\b', r'\\applymusic', str)
2134 conversions.append (((2, 3, 1), conv,
2135 '''\\apply -> \\applymusic'''))
2138 if re.search ('textheight', str):
2139 sys.stderr.write ('\n')
2140 sys.stderr.write (NOT_SMART % "tuning of textheight")
2141 sys.stderr.write ('\n')
2142 sys.stderr.write (UPDATE_MANUALLY)
2143 sys.stderr.write ('\n')
2145 str = re.sub (r'\\OrchestralScoreContext', '\\Score', str)
2147 if m.group(1) not in ['RemoveEmptyStaff',
2148 'AncientRemoveEmptyStaffContext',
2150 return '\\' + m.group (1)
2155 str = re.sub (r'\\([a-zA-Z]+)Context\b', func, str)
2156 str = re.sub ('ly:paper-lookup', 'ly:output-def-lookup', str)
2159 conversions.append (((2, 3, 2), conv,
2160 '''\\FooContext -> \\Foo'''))
2163 str = re.sub (r'\\notes\b', '', str)
2167 conversions.append (((2, 3, 4), conv,
2168 '''remove \\notes'''))
2173 str = re.sub (r'lastpagefill\s*=\s*"?1"', 'raggedlastbottom = ##t', str)
2176 conversions.append (((2, 3, 6), conv,
2177 '''lastpagefill -> raggedlastbottom'''))
2182 str = re.sub (r'\\consistsend', '\\consists', str)
2183 str = re.sub (r'\\lyricsto\s+("?[a-zA-Z]+"?)(\s*\\new Lyrics\s*)?\\lyrics',
2184 r'\\lyricsto \1 \2', str)
2187 conversions.append (((2, 3, 8), conv,
2188 '''remove \\consistsend, strip \\lyrics from \\lyricsto.'''))
2191 str = re.sub (r'neo_mensural', 'neomensural', str)
2192 str = re.sub (r'if-text-padding', 'bound-padding', str)
2195 conversions.append (((2, 3, 9), conv,
2196 '''neo_mensural -> neomensural, if-text-padding -> bound-padding'''))
2201 str = re.sub (r'\\addlyrics', r'\\oldaddlyrics', str)
2202 str = re.sub (r'\\newlyrics', r'\\addlyrics', str)
2203 if re.search (r"\\override\s*TextSpanner", str):
2204 sys.stderr.write ("\nWarning: TextSpanner has been split into DynamicTextSpanner and TextSpanner\n")
2207 conversions.append (((2, 3, 10), conv,
2208 '''\\addlyrics -> \\oldaddlyrics, \\newlyrics -> \\addlyrics'''))
2211 str = re.sub (r'\\setMmRestFermata\s+(R[0-9.*/]*)',
2212 r'\1^\\fermataMarkup', str)
2215 conversions.append (((2, 3, 11), conv,
2216 '''\\setMmRestFermata -> ^\\fermataMarkup'''))
2219 str = re.sub (r'\\newpage', r'\\pageBreak', str)
2220 str = re.sub (r'\\scriptUp', r"""{
2221 \\override TextScript #'direction = #1
2222 \\override Script #'direction = #1
2224 str = re.sub (r'\\scriptDown', r"""{
2225 \\override TextScript #'direction = #-1
2226 \\override Script #'direction = #-1
2228 str = re.sub (r'\\scriptBoth', r"""{
2229 \\revert TextScript #'direction
2230 \\revert Script #'direction
2232 str = re.sub ('soloADue', 'printPartCombineTexts', str)
2233 str = re.sub (r'\\applymusic\s*#notes-to-clusters',
2234 '\\makeClusters', str)
2236 str = re.sub (r'pagenumber\s*=', 'firstpagenumber', str)
2239 conversions.append (((2, 3, 12), conv,
2240 '''\\newpage -> \\pageBreak, junk \\script{up,down,both},
2241 soloADue -> printPartCombineTexts, #notes-to-clusters -> \\makeClusters
2246 str = re.sub (r'\\chords\b', r'\\chordmode', str)
2247 str = re.sub (r'\\lyrics\b', r'\\lyricmode', str)
2248 str = re.sub (r'\\figures\b', r'\\figuremode', str)
2249 str = re.sub (r'\\notes\b', r'\\notemode', str)
2250 str = re.sub (r'\\drums\b', r'\\drummode', str)
2251 str = re.sub (r'\\chordmode\s*\\new ChordNames', r'\\chords', str)
2252 str = re.sub (r'\\new ChordNames\s*\\chordmode', r'\\chords', str)
2253 str = re.sub (r'\\new FiguredBass\s*\\figuremode', r'\\figures', str)
2254 str = re.sub (r'\\figuremode\s*\new FiguredBass', r'\\figures', str)
2255 str = re.sub (r'\\new DrumStaff\s*\\drummode', r'\\drums', str)
2256 str = re.sub (r'\\drummode\s*\\new DrumStaff', r'\\drums', str)
2260 conversions.append (((2, 3, 16), conv,
2261 '''\foo -> \foomode (for chords, notes, etc.)
2262 fold \new FooContext \foomode into \foo.'''))
2265 str = re.sub (r'(slur|stem|phrasingSlur|tie|dynamic|dots|tuplet|arpeggio|)Both', r'\1Neutral', str)
2266 str = re.sub (r"\\applymusic\s*#\(remove-tag\s*'([a-z-0-9]+)\)",
2267 r"\\removeWithTag #'\1", str)
2270 conversions.append (((2, 3, 17), conv,
2271 '''\foo -> \foomode (for chords, notes, etc.)
2272 fold \new FooContext \foomode into \foo.'''))
2276 str = re.sub (r'Text_item', 'Text_interface', str)
2279 conversions.append (((2, 3, 18),
2281 '''Text_item -> Text_interface''' ))
2284 str = re.sub (r'\\paper', r'\\layout', str)
2285 str = re.sub (r'\\bookpaper', r'\\paper', str)
2286 if re.search ('paper-set-staff-size', str):
2287 sys.stderr.write ('''\nWarning: staff size should be changed at top-level
2290 #(set-global-staff-size <STAFF-HEIGHT-IN-POINT>)
2295 str = re.sub (r'#\(paper-set-staff-size', '%Use set-global-staff-size at toplevel\n% #(layout-set-staff-size', str)
2298 conversions.append (((2, 3, 22),
2301 bookpaper -> paper''' ))
2305 str = re.sub (r'\\context\s+([a-zA-Z]+)\s*=\s*([a-z]+)\s',
2306 r'\\context \1 = "\2" ',
2310 conversions.append (((2, 3, 23),
2312 '''\context Foo = NOTENAME -> \context Foo = "NOTENAME"'''))
2316 return regularize_id (m.group (1))
2317 str = re.sub (r'(maintainer_email|maintainer_web|midi_stuff|gourlay_maxmeasures)',
2321 conversions.append (((2, 3, 24),
2323 '''regularize other identifiers.'''))
2329 conversions.append (((2, 4, 0),
2335 str = re.sub (r'\\quote\s+"?([a-zA-Z0-9]+)"?\s+([0-9.*/]+)',
2336 r'\\quoteDuring #"\1" { \skip \2 }',
2341 conversions.append (((2, 5, 0),
2347 str = re.sub (r'ly:import-module',
2348 r'ly:module-copy', str)
2351 conversions.append (((2, 5, 1),
2353 'ly:import-module -> ly:module-copy'))
2356 str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>',
2358 str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>',
2360 str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>',
2364 s = re.sub (r'''((\\"|})\s*){''', '\2 \\line {', s)
2366 str = re.sub (r'\\markup\s*{([^}]|{[^}]*})*}', get_markup, str)
2369 conversions.append (((2, 5, 2),
2371 '\markup .. < .. > .. -> \markup .. { .. } ..'))
2374 str = re.sub ('ly:find-glyph-by-name', 'ly:font-get-glyph', str)
2375 str = re.sub ('"(scripts|clefs|accidentals)-', r'"\1.', str)
2376 str = re.sub ("'hufnagel-do-fa", "'hufnagel.do.fa", str)
2377 str = re.sub ("'(vaticana|hufnagel|medicaea|petrucci|neomensural|mensural)-", r"'\1.", str)
2380 conversions.append (((2, 5, 3),
2382 'ly:find-glyph-by-name -> ly:font-get-glyph, remove - from glyphnames.'))
2386 str = re.sub (r"\\override\s+(Voice\.)?Slur #'dashed\s*=\s*#\d*(\.\d+)?",
2387 r"\\slurDashed", str)
2390 conversions.append (((2, 5, 12),
2392 '\set Slur #\'dashed = #X -> \slurDashed'))
2395 input_encoding = 'latin1'
2397 encoding = match.group (1)
2399 # FIXME: automatic recoding of other than latin1?
2400 if encoding == 'latin1':
2401 return match.group (2)
2403 sys.stderr.write ('\n')
2404 sys.stderr.write (NOT_SMART % ("\\encoding: %s" % encoding))
2405 sys.stderr.write ('\n')
2406 sys.stderr.write (_ ("LilyPond source must be UTF-8"))
2407 sys.stderr.write ('\n')
2408 if encoding == 'TeX':
2409 sys.stderr.write (_ ("Try the texstrings backend"))
2410 sys.stderr.write ('\n')
2412 sys.stderr.write ( _("Do something like: %s") % \
2413 ("recode %s..utf-8 FILE" % encoding))
2414 sys.stderr.write ('\n')
2415 sys.stderr.write (_ ("Or save as UTF-8 in your editor"))
2416 sys.stderr.write ('\n')
2417 raise FatalConversionError ()
2419 return match.group (0)
2421 str = re.sub (r'\\encoding\s+"?([a-zA-Z0-9]+)"?(\s+)', func, str)
2424 de_ascii = codecs.getdecoder ('ascii')
2425 de_utf_8 = codecs.getdecoder ('utf_8')
2426 de_input = codecs.getdecoder (input_encoding)
2427 en_utf_8 = codecs.getencoder ('utf_8')
2430 # only in python >= 2.3
2431 # except UnicodeDecodeError:
2432 except UnicodeError:
2433 # do not re-recode UTF-8 input
2436 #except UnicodeDecodeError:
2437 except UnicodeError:
2438 str = en_utf_8 (de_input (str)[0])[0]
2442 str = re.sub (r"#\(ly:set-point-and-click '[a-z-]+\)", '', str)
2445 conversions.append (((2, 5, 13),
2447 '\\encoding: smart recode latin1..utf-8. Remove ly:point-and-click'))
2451 if re.search ("ly:stencil-set-extent!", str):
2452 sys.stderr.write ('\n')
2453 sys.stderr.write (NOT_SMART % "ly:stencil-set-extent!")
2454 sys.stderr.write ('\n')
2455 sys.stderr.write ('use (set! VAR (ly:make-stencil (ly:stencil-expr VAR) X-EXT Y-EXT))\n')
2456 raise FatalConversionError ()
2457 if re.search ("ly:stencil-align-to!", str):
2458 sys.stderr.write ('\n')
2459 sys.stderr.write (NOT_SMART % "ly:stencil-align-to!")
2460 sys.stderr.write ('\n')
2461 sys.stderr.write ('use (set! VAR (ly:stencil-aligned-to VAR AXIS DIR))\n')
2462 raise FatalConversionError ()
2465 conversions.append (((2, 5, 17),
2467 'ly:stencil-set-extent! removed'))
2470 str = re.sub (r"ly:warn\b", 'ly:warning', str)
2473 conversions.append (((2, 5, 18),
2475 'ly:warn -> ly:warning'))
2477 ################################
2478 # END OF CONVERSIONS
2479 ################################
2481 def get_conversions (from_version, to_version):
2482 def version_b (v, f = from_version, t = to_version):
2483 return version_cmp (v[0], f) > 0 and version_cmp (v[0], t) <= 0
2484 return filter (version_b, conversions)
2487 def latest_version ():
2488 return conversions[-1][0]
2490 def do_conversion (infile, from_version, outfile, to_version):
2491 conv_list = get_conversions (from_version, to_version)
2493 sys.stderr.write (_ ("Applying conversion: "))
2494 str = infile.read ()
2495 last_conversion = ()
2498 sys.stderr.write (tup_to_str (x[0]))
2500 last_conversion = x[0]
2501 if x != conv_list[-1]:
2502 sys.stderr.write (', ')
2504 except FatalConversionError:
2505 sys.stderr.write (_ ("%s: error while converting") \
2507 sys.stderr.write ('\n')
2508 sys.stderr.write (_ ("Aborting"))
2509 sys.stderr.write ('\n')
2512 new_ver = '\\version \"%s\"' % tup_to_str (last_conversion)
2514 if re.search (lilypond_version_re_str, str):
2515 str = re.sub (lilypond_version_re_str,
2516 '\\%s' % new_ver, str)
2518 str = new_ver + '\n' + str
2520 sys.stderr.write ('\n')
2523 return last_conversion
2525 class UnknownVersion:
2528 def do_one_file (infile_name):
2529 sys.stderr.write (_ ("Processing `%s\'... ") % infile_name)
2530 sys.stderr.write ('\n')
2533 outfile_name = infile_name + '.NEW'
2534 elif __main__.outfile_name:
2535 outfile_name = __main__.outfile_name
2537 if __main__.from_version:
2538 from_version = __main__.from_version
2540 guess = guess_lilypond_version (infile_name)
2542 raise UnknownVersion ()
2543 from_version = str_to_tuple (guess)
2545 if __main__.to_version:
2546 to_version = __main__.to_version
2548 to_version = latest_version ()
2552 infile = open (infile_name,'r')
2557 outfile = open (outfile_name, 'w')
2559 outfile = sys.stdout
2561 touched = do_conversion (infile, from_version, outfile, to_version)
2569 if __main__.edit and touched:
2571 os.remove(infile_name + '~')
2574 os.rename (infile_name, infile_name + '~')
2575 os.rename (infile_name + '.NEW', infile_name)
2586 (options, files) = getopt.getopt (sys.argv[1:], 'ao:f:t:senhv',
2587 ['no-version', 'version', 'output',
2588 'show-rules', 'help', 'edit',
2594 if o == '--help' or o == '-h':
2597 elif o == '--version' or o == '-v':
2600 elif o== '--from' or o=='-f':
2601 from_version = str_to_tuple (a)
2602 elif o== '--to' or o=='-t':
2603 to_version = str_to_tuple (a)
2604 elif o== '--edit' or o == '-e':
2606 elif o== '--show-rules' or o == '-s':
2608 elif o == '--output' or o == '-o':
2610 elif o == '--no-version' or o == '-n':
2616 # should parse files[] to read \version?
2618 show_rules (sys.stdout)
2625 elif not os.path.isfile (f):
2629 except UnknownVersion:
2630 sys.stderr.write ('\n')
2631 sys.stderr.write (_ ("%s: can't determine version for `%s'") \
2632 % (program_name, f))
2633 sys.stderr.write ('\n')
2636 from_version = (0, 0, 0)
2640 sys.stderr.write (_ ("%s: skipping: `%s'") \
2641 % (program_name, f))
2644 sys.stderr.write ('\n')