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 (_ ('Examples'))
69 sys.stdout.write ('\n')
70 sys.stdout.write (' convert-ly -e *ly')
71 sys.stdout.write ('\n')
72 sys.stdout.write (' convert-ly --from=2.4.0 -e $(find . -name "*ly")')
73 sys.stdout.write ('\n\n')
74 sys.stdout.write (_ ("Report bugs to %s.") % "bug-lilypond@gnu.org")
75 sys.stdout.write ('\n')
79 sys.stdout.write (program_id ())
80 sys.stdout.write ('\n')
81 sys.stdout.write (_ ("""\
82 This program is free software. It is covered by the GNU General Public
83 License and you are welcome to change it and/or distribute copies of it
84 under certain conditions. Invoke as `%s --warranty' for more
89 return tuple (map (string.atoi, string.split (s, '.')))
92 return string.join (map (lambda x: '%s' % x, list (t)), '.')
94 def version_cmp (t1, t2):
100 def guess_lilypond_version (filename):
101 s = open (filename).read ()
102 m = lilypond_version_re.search (s)
108 class FatalConversionError:
113 def show_rules (file):
114 for x in conversions:
115 if (not from_version or x[0] > from_version) \
116 and (not to_version or x[0] <= to_version):
117 file.write ('%s: %s\n' % (tup_to_str (x[0]), x[2]))
119 ############################
123 if re.search ('\\\\multi', str):
124 sys.stderr.write ('\n')
125 sys.stderr.write (NOT_SMART % "\\multi")
126 sys.stderr.write ('\n')
129 conversions.append (((0,1,9), conv, '\\header { key = concat + with + operator }'))
133 if re.search ('\\\\octave', str):
134 sys.stderr.write ('\n')
135 sys.stderr.write (NOT_SMART % "\\octave")
136 sys.stderr.write ('\n')
137 sys.stderr.write (UPDATE_MANUALLY)
138 sys.stderr.write ('\n')
139 # raise FatalConversionError ()
143 conversions.append ((
144 ((0,1,19), conv, 'deprecated \\octave; cannot convert automatically')))
149 str = re.sub ('\\\\textstyle([^;]+);',
150 '\\\\property Lyrics . textstyle = \\1', str)
151 # harmful to current .lys
152 # str = re.sub ('\\\\key([^;]+);', '\\\\accidentals \\1;', str)
156 conversions.append ((
157 ((0,1,20), conv, 'deprecated \\textstyle, new \\key syntax')))
162 str = re.sub ('\\\\musical_pitch', '\\\\musicalpitch',str)
163 str = re.sub ('\\\\meter', '\\\\time',str)
167 conversions.append ((
168 ((0,1,21), conv, '\\musical_pitch -> \\musicalpitch, '+
169 '\\meter -> \\time')))
175 conversions.append ((
176 ((1,0,0), conv, '0.1.21 -> 1.0.0 ')))
181 str = re.sub ('\\\\accidentals', '\\\\keysignature',str)
182 str = re.sub ('specialaccidentals *= *1', 'keyoctaviation = 0',str)
183 str = re.sub ('specialaccidentals *= *0', 'keyoctaviation = 1',str)
187 conversions.append ((
188 ((1,0,1), conv, '\\accidentals -> \\keysignature, ' +
189 'specialaccidentals -> keyoctaviation')))
193 if re.search ('\\\\header', str):
194 sys.stderr.write ('\n')
195 sys.stderr.write (NOT_SMART % "new \\header format")
196 sys.stderr.write ('\n')
199 conversions.append (((1,0,2), conv, '\\header { key = concat + with + operator }'))
203 str = re.sub ('\\\\melodic([^a-zA-Z])', '\\\\notes\\1',str)
206 conversions.append (((1,0,3), conv, '\\melodic -> \\notes'))
210 str = re.sub ('default_paper *=', '',str)
211 str = re.sub ('default_midi *=', '',str)
214 conversions.append (((1,0,4), conv, 'default_{paper,midi}'))
218 str = re.sub ('ChoireStaff', 'ChoirStaff',str)
219 str = re.sub ('\\\\output', 'output = ',str)
223 conversions.append (((1,0,5), conv, 'ChoireStaff -> ChoirStaff'))
227 if re.search ('[a-zA-Z]+ = *\\translator',str):
228 sys.stderr.write ('\n')
229 sys.stderr.write (NOT_SMART % "\\translator syntax")
230 sys.stderr.write ('\n')
231 # raise FatalConversionError ()
234 conversions.append (((1,0,6), conv, 'foo = \\translator {\\type .. } ->\\translator {\\type ..; foo; }'))
239 str = re.sub ('\\\\lyrics*', '\\\\lyrics',str)
243 conversions.append (((1,0,7), conv, '\\lyric -> \\lyrics'))
247 str = re.sub ('\\\\\\[/3+', '\\\\times 2/3 { ',str)
248 str = re.sub ('\\[/3+', '\\\\times 2/3 { [',str)
249 str = re.sub ('\\\\\\[([0-9/]+)', '\\\\times \\1 {',str)
250 str = re.sub ('\\[([0-9/]+)', '\\\\times \\1 { [',str)
251 str = re.sub ('\\\\\\]([0-9/]+)', '}', str)
252 str = re.sub ('\\\\\\]', '}',str)
253 str = re.sub ('\\]([0-9/]+)', '] }', str)
256 conversions.append (((1,0,10), conv, '[2/3 ]1/1 -> \\times 2/3 '))
261 conversions.append (((1,0,12), conv, 'Chord syntax stuff'))
268 str = re.sub ('<([^>~]+)~([^>]*)>','<\\1 \\2> ~', str)
272 conversions.append (((1,0,13), conv, '<a ~ b> c -> <a b> ~ c'))
276 str = re.sub ('<\\[','[<', str)
277 str = re.sub ('\\]>','>]', str)
281 conversions.append (((1,0,14), conv, '<[a b> <a b]>c -> [<a b> <a b>]'))
286 str = re.sub ('\\\\type([^\n]*engraver)','\\\\TYPE\\1', str)
287 str = re.sub ('\\\\type([^\n]*performer)','\\\\TYPE\\1', str)
288 str = re.sub ('\\\\type','\\\\context', str)
289 str = re.sub ('\\\\TYPE','\\\\type', str)
290 str = re.sub ('textstyle','textStyle', str)
294 conversions.append (((1,0,16), conv, '\\type -> \\context, textstyle -> textStyle'))
299 if re.search ('\\\\repeat',str):
300 sys.stderr.write ('\n')
301 sys.stderr.write (NOT_SMART % "\\repeat")
302 sys.stderr.write ('\n')
303 # raise FatalConversionError ()
306 conversions.append (((1,0,18), conv,
307 '\\repeat NUM Music Alternative -> \\repeat FOLDSTR Music Alternative'))
311 str = re.sub ('SkipBars','skipBars', str)
312 str = re.sub ('fontsize','fontSize', str)
313 str = re.sub ('midi_instrument','midiInstrument', str)
317 conversions.append (((1,0,19), conv,
318 'fontsize -> fontSize, midi_instrument -> midiInstrument, SkipBars -> skipBars'))
323 str = re.sub ('tieydirection','tieVerticalDirection', str)
324 str = re.sub ('slurydirection','slurVerticalDirection', str)
325 str = re.sub ('ydirection','verticalDirection', str)
329 conversions.append (((1,0,20), conv,
330 '{,tie,slur}ydirection -> {v,tieV,slurV}erticalDirection'))
335 str = re.sub ('hshift','horizontalNoteShift', str)
339 conversions.append (((1,0,21), conv,
340 'hshift -> horizontalNoteShift'))
345 str = re.sub ('\\\\grouping[^;]*;','', str)
349 conversions.append (((1,1,52), conv,
350 'deprecate \\grouping'))
355 str = re.sub ('\\\\wheel','\\\\coda', str)
359 conversions.append (((1,1,55), conv,
360 '\\wheel -> \\coda'))
364 str = re.sub ('keyoctaviation','keyOctaviation', str)
365 str = re.sub ('slurdash','slurDash', str)
369 conversions.append (((1,1,65), conv,
370 'slurdash -> slurDash, keyoctaviation -> keyOctaviation'))
374 str = re.sub ('\\\\repeat *\"?semi\"?','\\\\repeat "volta"', str)
378 conversions.append (((1,1,66), conv,
384 str = re.sub ('\"?beamAuto\"? *= *\"?0?\"?','noAutoBeaming = "1"', str)
388 conversions.append (((1,1,67), conv,
389 'beamAuto -> noAutoBeaming'))
393 str = re.sub ('automaticMelismas', 'automaticMelismata', str)
397 conversions.append (((1,2,0), conv,
398 'automaticMelismas -> automaticMelismata'))
402 str = re.sub ('dynamicDir\\b', 'dynamicDirection', str)
406 conversions.append (((1,2,1), conv,
407 'dynamicDir -> dynamicDirection'))
411 str = re.sub ('\\\\cadenza *0 *;', '\\\\cadenzaOff', str)
412 str = re.sub ('\\\\cadenza *1 *;', '\\\\cadenzaOn', str)
416 conversions.append (((1,3,4), conv,
417 '\\cadenza -> \\cadenza{On|Off}'))
421 str = re.sub ('"?beamAuto([^"=]+)"? *= *"([0-9]+)/([0-9]+)" *;*',
422 'beamAuto\\1 = #(make-moment \\2 \\3)',
426 conversions.append (((1,3,5), conv, 'beamAuto moment properties'))
430 str = re.sub ('stemStyle',
435 conversions.append (((1,3,17), conv, 'stemStyle -> flagStyle'))
439 str = re.sub ('staffLineLeading',
444 conversions.append (((1,3,18), conv, 'staffLineLeading -> staffSpace'))
449 if re.search ('\\\\repetitions',str):
450 sys.stderr.write ('\n')
451 sys.stderr.write (NOT_SMART % "\\repetitions")
452 sys.stderr.write ('\n')
453 # raise FatalConversionError ()
456 conversions.append (((1,3,23), conv,
457 '\\\\repetitions feature dropped'))
462 str = re.sub ('textEmptyDimension *= *##t',
463 'textNonEmpty = ##f',
465 str = re.sub ('textEmptyDimension *= *##f',
466 'textNonEmpty = ##t',
470 conversions.append (((1,3,35), conv, 'textEmptyDimension -> textNonEmpty'))
474 str = re.sub ("([a-z]+)[ \t]*=[ \t]*\\\\musicalpitch *{([- 0-9]+)} *\n",
475 "(\\1 . (\\2))\n", str)
476 str = re.sub ("\\\\musicalpitch *{([0-9 -]+)}",
477 "\\\\musicalpitch #'(\\1)", str)
478 if re.search ('\\\\notenames',str):
479 sys.stderr.write ('\n')
480 sys.stderr.write (NOT_SMART % "new \\notenames format")
481 sys.stderr.write ('\n')
484 conversions.append (((1,3,38), conv, '\musicalpitch { a b c } -> #\'(a b c)'))
489 return '\\key %s;' % string.lower (match.group (1))
491 str = re.sub ("\\\\key ([^;]+);", replace, str)
494 conversions.append (((1,3,39), conv, '\\key A ; ->\\key a;'))
498 if re.search ('\\[:',str):
499 sys.stderr.write ('\n')
500 sys.stderr.write (NOT_SMART % "new tremolo format")
501 sys.stderr.write ('\n')
504 conversions.append (((1,3,41), conv,
505 '[:16 c4 d4 ] -> \\repeat "tremolo" 2 { c16 d16 }'))
509 str = re.sub ('Staff_margin_engraver' , 'Instrument_name_engraver', str)
512 conversions.append (((1,3,42), conv,
513 'Staff_margin_engraver deprecated, use Instrument_name_engraver'))
517 str = re.sub ('note[hH]eadStyle\\s*=\\s*"?(\\w+)"?' , "noteHeadStyle = #'\\1", str)
520 conversions.append (((1,3,49), conv,
521 'noteHeadStyle value: string -> symbol'))
525 if re.search ('\\\\keysignature', str):
526 sys.stderr.write ('\n')
527 sys.stderr.write (NOT_SMART % "new tremolo format")
528 sys.stderr.write ('\n')
532 conversions.append (((1,3,58), conv,
533 'noteHeadStyle value: string -> symbol'))
537 str = re.sub (r"""\\key *([a-z]+) *;""", r"""\\key \1 \major;""",str);
539 conversions.append (((1,3,59), conv,
540 '\key X ; -> \key X major; '))
544 str = re.sub (r'latexheaders *= *"\\\\input ',
548 conversions.append (((1,3,68), conv, 'latexheaders = "\\input global" -> latexheaders = "global"'))
553 # TODO: lots of other syntax change should be done here as well
556 str = re.sub ('basicCollisionProperties', 'NoteCollision', str)
557 str = re.sub ('basicVoltaSpannerProperties' , "VoltaBracket", str)
558 str = re.sub ('basicKeyProperties' , "KeySignature", str)
560 str = re.sub ('basicClefItemProperties' ,"Clef", str)
563 str = re.sub ('basicLocalKeyProperties' ,"Accidentals", str)
564 str = re.sub ('basicMarkProperties' ,"Accidentals", str)
565 str = re.sub ('basic([A-Za-z_]+)Properties', '\\1', str)
567 str = re.sub ('Repeat_engraver' ,'Volta_engraver', str)
570 conversions.append (((1,3,92), conv, 'basicXXXProperties -> XXX, Repeat_engraver -> Volta_engraver'))
574 # Ugh, but meaning of \stemup changed too
575 # maybe we should do \stemup -> \stemUp\slurUp\tieUp ?
576 str = re.sub ('\\\\stemup', '\\\\stemUp', str)
577 str = re.sub ('\\\\stemdown', '\\\\stemDown', str)
578 str = re.sub ('\\\\stemboth', '\\\\stemBoth', str)
580 str = re.sub ('\\\\slurup', '\\\\slurUp', str)
581 str = re.sub ('\\\\slurboth', '\\\\slurBoth', str)
582 str = re.sub ('\\\\slurdown', '\\\\slurDown', str)
583 str = re.sub ('\\\\slurdotted', '\\\\slurDotted', str)
584 str = re.sub ('\\\\slurnormal', '\\\\slurNoDots', str)
586 str = re.sub ('\\\\shiftoff', '\\\\shiftOff', str)
587 str = re.sub ('\\\\shifton', '\\\\shiftOn', str)
588 str = re.sub ('\\\\shiftonn', '\\\\shiftOnn', str)
589 str = re.sub ('\\\\shiftonnn', '\\\\shiftOnnn', str)
591 str = re.sub ('\\\\onevoice', '\\\\oneVoice', str)
592 str = re.sub ('\\\\voiceone', '\\\\voiceOne', str)
593 str = re.sub ('\\\\voicetwo', '\\\\voiceTwo', str)
594 str = re.sub ('\\\\voicethree', '\\\\voiceThree', str)
595 str = re.sub ('\\\\voicefour', '\\\\voiceFour', str)
597 # I don't know exactly when these happened...
598 # ugh, we loose context setting here...
599 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\stemUp\\\\slurUp\\\\tieUp', str)
600 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\stemDown\\\\slurDown\\\\tieDown', str)
601 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\stemBoth\\\\slurBoth\\\\tieBoth', str)
603 str = re.sub ('verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #1', str)
604 str = re.sub ('verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #-1', str)
605 str = re.sub ('verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #0', str)
607 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\\\1Up', str)
608 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\\\1Down', str)
609 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\\\1Both', str)
611 # (lacks capitalisation slur -> Slur)
612 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\1 \\\\override #\'direction = #1', str)
613 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\1 \\override #\'direction = #-1', str)
614 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\1 \\\\override #\'direction = #0', str)
617 str = re.sub ('\\\\property *[^ .]*[.]?dynamicDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\dynamicUp', str)
618 str = re.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\dynamicDown', str)
619 str = re.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?(0|(\\\\center))"?', '\\\\dynamicBoth', str)
621 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?(0|(""))"?', '\\\\\\1NoDots', str)
622 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?([1-9]+)"?', '\\\\\\1Dotted', str)
624 str = re.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?(0|(""))"?', '\\\\autoBeamOn', str)
625 str = re.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?([1-9]+)"?', '\\\\autoBeamOff', str)
631 conversions.append (((1,3,93), conv,
632 'property definiton case (eg. onevoice -> oneVoice)'))
637 str = re.sub ('ChordNames*', 'ChordNames', str)
638 if re.search ('\\\\textscript "[^"]* *"[^"]*"', str):
639 sys.stderr.write ('\n')
640 sys.stderr.write (NOT_SMART % "new \\textscript markup text")
641 sys.stderr.write ('\n')
643 str = re.sub ('\\textscript +("[^"]*")', '\\textscript #\\1', str)
647 conversions.append (((1,3,97), conv, 'ChordName -> ChordNames'))
650 # TODO: add lots of these
654 str = re.sub ('\\\\property *"?Voice"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Voice.TextScript \\\\set #\'font-style = #\'\\1', str)
655 str = re.sub ('\\\\property *"?Lyrics"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Lyrics.LyricText \\\\set #\'font-style = #\'\\1', str)
657 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?timeSignatureStyle"? *= *"([^"]*)"', '\\\\property \\1.TimeSignature \\\\override #\'style = #\'\\2', str)
659 str = re.sub ('"?timeSignatureStyle"? *= *#?""', 'TimeSignature \\\\override #\'style = ##f', str)
661 str = re.sub ('"?timeSignatureStyle"? *= *#?"([^"]*)"', 'TimeSignature \\\\override #\'style = #\'\\1', str)
663 str = re.sub ('#\'style *= #*"([^"])"', '#\'style = #\'\\1', str)
665 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?horizontalNoteShift"? *= *"?#?([-0-9]+)"?', '\\\\property \\1.NoteColumn \\\\override #\'horizontal-shift = #\\2', str)
668 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *""', '\\\\property \\1.Stem \\\\override #\'flag-style = ##f', str)
670 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *"([^"]*)"', '\\\\property \\1.Stem \\\\override #\'flag-style = #\'\\2', str)
673 conversions.append (((1,3,98), conv, 'CONTEXT.textStyle -> GROB.#font-style '))
677 str = re.sub ('"?beamAutoEnd_([0-9]*)"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end 1 \\1 * *) = \\2', str)
678 str = re.sub ('"?beamAutoBegin_([0-9]*)"? *= *(#\\([^)]*\))', 'autoBeamSettings \\push #\'(begin 1 \\1 * *) = \\2', str)
679 str = re.sub ('"?beamAutoEnd"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end * * * *) = \\1', str)
680 str = re.sub ('"?beamAutoBegin"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(begin * * * *) = \\1', str)
685 conversions.append (((1,3,102), conv, 'beamAutoEnd -> autoBeamSettings \\push (end * * * *)'))
690 str = re.sub ('\\\\push', '\\\\override', str)
691 str = re.sub ('\\\\pop', '\\\\revert', str)
695 conversions.append (((1,3,111), conv, '\\push -> \\override, \\pop -> \\revert'))
699 str = re.sub ('LyricVoice', 'LyricsVoice', str)
701 str = re.sub ('Chord[Nn]ames*.Chord[Nn]ames*', 'ChordNames.ChordName', str)
702 str = re.sub ('Chord[Nn]ames([ \t\n]+\\\\override)', 'ChordName\\1', str)
705 conversions.append (((1,3,113), conv, 'LyricVoice -> LyricsVoice'))
707 def regularize_id (str):
714 elif x in string.digits:
715 x = chr(ord (x) - ord ('0') +ord ('A'))
716 elif x not in string.letters:
718 elif x in string.lowercase and lastx == '_':
727 def regularize_dollar_reference (match):
728 return regularize_id (match.group (1))
729 def regularize_assignment (match):
730 return '\n' + regularize_id (match.group (1)) + ' = '
731 str = re.sub ('\$([^\t\n ]+)', regularize_dollar_reference, str)
732 str = re.sub ('\n([^ \t\n]+)[ \t]*= *', regularize_assignment, str)
735 conversions.append (((1,3,117), conv, 'identifier names: $!foo_bar_123 -> xfooBarABC'))
740 def regularize_paper (match):
741 return regularize_id (match.group (1))
743 str = re.sub ('(paper_[a-z]+)', regularize_paper, str)
744 str = re.sub ('sustainup', 'sustainUp', str)
745 str = re.sub ('nobreak', 'noBreak', str)
746 str = re.sub ('sustaindown', 'sustainDown', str)
747 str = re.sub ('sostenutoup', 'sostenutoUp', str)
748 str = re.sub ('sostenutodown', 'sostenutoDown', str)
749 str = re.sub ('unachorda', 'unaChorda', str)
750 str = re.sub ('trechorde', 'treChorde', str)
754 conversions.append (((1,3,120), conv, 'paper_xxx -> paperXxxx, pedalup -> pedalUp.'))
758 str = re.sub ('drarnChords', 'chordChanges', str)
759 str = re.sub ('\\musicalpitch', '\\pitch', str)
762 conversions.append (((1,3,122), conv, 'drarnChords -> chordChanges, \\musicalpitch -> \\pitch'))
766 str = re.sub ('ly-([sg])et-elt-property', 'ly-\\1et-grob-property', str)
769 conversions.append (((1,3,136), conv, 'ly-X-elt-property -> ly-X-grob-property'))
773 str = re.sub ('point-and-click +#t', 'point-and-click line-column-location', str)
776 conversions.append (((1,3,138), conv, 'point-and-click argument changed to procedure.'))
780 str = re.sub ('followThread', 'followVoice', str)
781 str = re.sub ('Thread.FollowThread', 'Voice.VoiceFollower', str)
782 str = re.sub ('FollowThread', 'VoiceFollower', str)
785 conversions.append (((1,3,138), conv, 'followThread -> followVoice.'))
789 str = re.sub ('font-point-size', 'font-design-size', str)
792 conversions.append (((1,3,139), conv, 'font-point-size -> font-design-size.'))
796 str = re.sub ('([a-zA-Z]*)NoDots', '\\1Solid', str)
799 conversions.append (((1,3,141), conv, 'xNoDots -> xSolid'))
803 str = re.sub ('([Cc])hord([ea])', '\\1ord\\2', str)
806 conversions.append (((1,3,144), conv, 'Chorda -> Corda'))
811 str = re.sub ('([A-Za-z]+)MinimumVerticalExtent', 'MinimumV@rticalExtent', str)
812 str = re.sub ('([A-Za-z]+)ExtraVerticalExtent', 'ExtraV@rticalExtent', str)
813 str = re.sub ('([A-Za-z]+)VerticalExtent', 'VerticalExtent', str)
814 str = re.sub ('ExtraV@rticalExtent', 'ExtraVerticalExtent', str)
815 str = re.sub ('MinimumV@rticalExtent', 'MinimumVerticalExtent', str)
818 conversions.append (((1,3,145), conv,
819 'ContextNameXxxxVerticalExtent -> XxxxVerticalExtent'))
823 str = re.sub ('\\\\key[ \t]*;', '\\key \\default;', str)
824 str = re.sub ('\\\\mark[ \t]*;', '\\mark \\default;', str)
826 # Make sure groups of more than one ; have space before
827 # them, so that non of them gets removed by next rule
828 str = re.sub ("([^ \n\t;]);(;+)", "\\1 ;\\2", str)
830 # Only remove ; that are not after spaces, # or ;
831 # Otherwise we interfere with Scheme comments,
832 # which is badbadbad.
833 str = re.sub ("([^ \t;#]);", "\\1", str)
836 conversions.append (((1,3,146), conv, 'semicolons removed'))
840 str = re.sub ('default-neutral-direction', 'neutral-direction',str)
842 conversions.append (((1,3,147), conv, 'default-neutral-direction -> neutral-direction'))
846 str = re.sub ('\(align', '(axis', str)
847 str = re.sub ('\(rows', '(columns', str)
849 conversions.append (((1,3,148), conv, '"(align" -> "(axis", "(rows" -> "(columns"'))
854 str = re.sub ('SystemStartDelimiter', 'systemStartDelimiter', str)
856 conversions.append (((1,5,33), conv, 'SystemStartDelimiter -> systemStartDelimiter'))
860 str = re.sub ('arithmetic-multiplier', 'spacing-increment', str)
861 str = re.sub ('arithmetic-basicspace', 'shortest-duration-space', str)
864 conversions.append (((1,5,38), conv, 'SystemStartDelimiter -> systemStartDelimiter'))
872 "Instrument_name": "instrument-name",
873 "Left_edge_item": "left-edge",
874 "Span_bar": "span-bar",
875 "Breathing_sign": "breathing-sign",
876 "Staff_bar": "staff-bar",
878 "Key_item": "key-signature",
879 "Time_signature": "time-signature",
882 props = match.group (1)
883 for (k,v) in break_dict.items():
884 props = re.sub (k, v, props)
885 return "breakAlignOrder = #'(%s)" % props
887 str = re.sub ("breakAlignOrder *= *#'\\(([a-z_\n\tA-Z ]+)\\)",
892 conversions.append (((1,5,40), conv, 'breakAlignOrder property names'))
897 str = re.sub ('noAutoBeaming *= *##f', 'autoBeaming = ##t', str)
898 str = re.sub ('noAutoBeaming *= *##t', 'autoBeaming = ##f', str)
901 conversions.append (((1,5,49), conv, 'noAutoBeaming -> autoBeaming'))
905 str = re.sub ('tuplet-bracket-visibility', 'bracket-visibility', str)
906 str = re.sub ('tuplet-number-visibility', 'number-visibility', str)
909 conversions.append (((1,5,52), conv, 'tuplet-X-visibility -> X-visibility'))
913 str = re.sub ('Pitch::transpose', 'ly-transpose-pitch', str)
917 conversions.append (((1,5,56), conv, 'Pitch::transpose -> ly-transpose-pitch'))
921 str = re.sub ('textNonEmpty *= *##t', "TextScript \\set #'no-spacing-rods = ##f", str)
922 str = re.sub ('textNonEmpty *= *##f', "TextScript \\set #'no-spacing-rods = ##t", str)
925 conversions.append (((1,5,58), conv, 'deprecate textNonEmpty'))
930 str = re.sub ('MinimumVerticalExtent', 'minimumV@rticalExtent', str)
931 str = re.sub ('minimumVerticalExtent', 'minimumV@rticalExtent', str)
932 str = re.sub ('ExtraVerticalExtent', 'extraV@rticalExtent', str)
933 str = re.sub ('extraVerticalExtent', 'extraV@rticalExtent', str)
934 str = re.sub ('VerticalExtent', 'verticalExtent', str)
935 str = re.sub ('extraV@rticalExtent', 'extraVerticalExtent', str)
936 str = re.sub ('minimumV@rticalExtent', 'minimumVerticalExtent', str)
939 conversions.append (((1,5,59), conv,
940 'XxxxVerticalExtent -> xxxVerticalExtent'))
944 str = re.sub ('visibility-lambda', 'break-visibility', str)
947 conversions.append (((1,5,62), conv,
948 'visibility-lambda -> break-visibility'))
953 if re.search (r'\addlyrics',str) \
954 and re.search ('automaticMelismata', str) == None:
955 sys.stderr.write ('\n')
956 sys.stderr.write (NOT_SMART % "automaticMelismata; turned on by default since 1.5.67.")
957 sys.stderr.write ('\n')
958 raise FatalConversionError ()
961 conversions.append (((1,5,67), conv,
962 'automaticMelismata turned on by default'))
966 str = re.sub ('ly-set-grob-property([^!])', 'ly-set-grob-property!\1', str)
967 str = re.sub ('ly-set-mus-property([^!])', 'ly-set-mus-property!\1', str)
970 conversions.append (((1,5,68), conv, 'ly-set-X-property -> ly-set-X-property!'))
974 str = re.sub ('extent-X', 'X-extent', str)
975 str = re.sub ('extent-Y', 'Y-extent', str)
978 conversions.append (((1,5,71), conv, 'extent-[XY] -> [XY]-extent'))
983 str = re.sub ("""#\(set! +point-and-click +line-column-location\)""",
984 """#(set-point-and-click! \'line-column)""", str)
985 str = re.sub ("""#\(set![ \t]+point-and-click +line-location\)""",
986 '#(set-point-and-click! \'line)', str)
987 str = re.sub ('#\(set! +point-and-click +#f\)',
988 '#(set-point-and-click! \'none)', str)
991 conversions.append (((1,5,72), conv, 'set! point-and-click -> set-point-and-click!'))
996 str = re.sub ('flag-style', 'stroke-style', str)
997 str = re.sub (r"""Stem([ ]+)\\override #'style""", r"""Stem \\override #'flag-style""", str);
998 str = re.sub (r"""Stem([ ]+)\\set([ ]+)#'style""", r"""Stem \\set #'flag-style""", str);
1001 conversions.append (((1,6,5), conv, 'Stems: flag-style -> stroke-style; style -> flag-style'))
1005 def subst_req_name (match):
1006 return "(make-music-by-name \'%sEvent)" % regularize_id (match.group(1))
1009 str = re.sub ('\\(ly-make-music *\"([A-Z][a-z_]+)_req\"\\)', subst_req_name, str)
1010 str = re.sub ('Request_chord', 'EventChord', str)
1013 conversions.append (((1,7,1), conv, 'ly-make-music foo_bar_req -> make-music-by-name FooBarEvent'))
1018 "text" : 'TextSpanEvent',
1019 "decrescendo" : 'DecrescendoEvent',
1020 "crescendo" : 'CrescendoEvent',
1021 "Sustain" : 'SustainPedalEvent',
1022 "slur" : 'SlurEvent',
1023 "UnaCorda" : 'UnaCordaEvent',
1024 "Sostenuto" : 'SostenutoEvent',
1026 def subst_ev_name (match):
1028 if re.search ('start', match.group(1)):
1031 mtype = spanner_subst[match.group(2)]
1032 return "(make-span-event '%s %s)" % (mtype , stype)
1034 def subst_definition_ev_name(match):
1035 return ' = #%s' % subst_ev_name (match)
1036 def subst_inline_ev_name (match):
1037 s = subst_ev_name (match)
1038 return '#(ly-export %s)' % s
1039 def subst_csp_definition (match):
1040 return ' = #(make-event-chord (list %s))' % subst_ev_name (match)
1041 def subst_csp_inline (match):
1042 return '#(ly-export (make-event-chord (list %s)))' % subst_ev_name (match)
1045 str = re.sub (r' *= *\\spanrequest *([^ ]+) *"([^"]+)"', subst_definition_ev_name, str)
1046 str = re.sub (r'\\spanrequest *([^ ]+) *"([^"]+)"', subst_inline_ev_name, str)
1047 str = re.sub (r' *= *\\commandspanrequest *([^ ]+) *"([^"]+)"', subst_csp_definition, str)
1048 str = re.sub (r'\\commandspanrequest *([^ ]+) *"([^"]+)"', subst_csp_inline, str)
1049 str = re.sub (r'ly-id ', 'ly-import ', str)
1051 str = re.sub (r' *= *\\script "([^"]+)"', ' = #(make-articulation "\\1")', str)
1052 str = re.sub (r'\\script "([^"]+)"', '#(ly-export (make-articulation "\\1"))', str)
1055 conversions.append (((1,7,2), conv, '\\spanrequest -> #(make-span-event .. ), \script -> #(make-articulation .. )'))
1059 str = re.sub (r'\(ly-', '(ly:', str)
1069 'music-duration-length',
1071 'duration-dotcount',
1074 'transpose-key-alist',
1078 'set-point-and-click!',
1087 'music-duration-compress',
1088 'set-point-and-click!'
1091 origre = r'\b(%s)' % string.join (changed, '|')
1093 str = re.sub (origre, r'ly:\1',str)
1094 str = re.sub ('set-point-and-click!', 'set-point-and-click', str)
1098 conversions.append (((1,7,3), conv, 'ly- -> ly:'))
1102 if re.search ('new-chords-done',str):
1105 str = re.sub (r'<<', '< <', str)
1106 str = re.sub (r'>>', '> >', str)
1109 conversions.append (((1,7,4), conv, '<< >> -> < < > >'))
1113 str = re.sub (r"\\transpose", r"\\transpose c'", str)
1114 str = re.sub (r"\\transpose c' *([a-z]+)'", r"\\transpose c \1", str)
1116 conversions.append (((1,7,5), conv, '\\transpose TO -> \\transpose FROM TO'))
1134 origstr = string.join (kws, '|')
1135 str = re.sub (r'([^_^-])\\(%s)\b' % origstr, r'\1-\\\2', str)
1137 conversions.append (((1,7,6), conv, 'note\\script -> note-\script'))
1142 str = re.sub (r"\\property *ChordNames *\. *ChordName *\\(set|override) *#'style *= *#('[a-z]+)",
1143 r"#(set-chord-name-style \2)", str)
1144 str = re.sub (r"\\property *ChordNames *\. *ChordName *\\revert *#'style",
1147 conversions.append (((1,7,10), conv, "\property ChordName #'style -> #(set-chord-name-style 'style)"))
1153 str = re.sub (r"ly:transpose-pitch", "ly:pitch-transpose", str)
1156 conversions.append (((1,7,11), conv, "transpose-pitch -> pitch-transpose"))
1160 str = re.sub (r"ly:get-molecule-extent", "ly:molecule-get-extent", str)
1161 str = re.sub (r"ly:set-molecule-extent!", "ly:molecule-set-extent!", str)
1162 str = re.sub (r"ly:add-molecule", "ly:molecule-add", str)
1163 str = re.sub (r"ly:combine-molecule-at-edge", "ly:molecule-combine-at-edge", str)
1164 str = re.sub (r"ly:align-to!", "ly:molecule-align-to!", str)
1168 conversions.append (((1,7,13), conv, "ly:XX-molecule-YY -> ly:molecule-XX-YY"))
1172 str = re.sub (r"linewidth *= *-[0-9.]+ *(\\mm|\\cm|\\in|\\pt)?", 'raggedright = ##t', str )
1175 conversions.append (((1,7,15), conv, "linewidth = -1 -> raggedright = ##t"))
1179 str = re.sub ("divisiomaior",
1180 "divisioMaior", str)
1181 str = re.sub ("divisiominima",
1182 "divisioMinima", str)
1183 str = re.sub ("divisiomaxima",
1184 "divisioMaxima", str)
1187 conversions.append (((1,7,16), conv, "divisiomaior -> divisioMaior"))
1191 str = re.sub ("Skip_req_swallow_translator",
1192 "Skip_event_swallow_translator", str)
1195 conversions.append (((1,7,17), conv, "Skip_req -> Skip_event"))
1199 str = re.sub ("groupOpen",
1201 str = re.sub ("groupClose",
1203 str = re.sub ("#'outer",
1204 "#'enclose-bounds", str)
1208 conversions.append (((1,7,18), conv,
1209 """groupOpen/Close -> start/stopGroup,
1210 #'outer -> #'enclose-bounds
1215 if re.search( r'\\GraceContext', str):
1216 sys.stderr.write ('\n')
1217 sys.stderr.write (NOT_SMART % "GraceContext")
1218 sys.stderr.write (FROM_TO \
1219 % ("GraceContext", "#(add-to-grace-init .. )"))
1220 sys.stderr.write ('\n')
1221 sys.stderr.write (UPDATE_MANUALLY)
1222 sys.stderr.write ('\n')
1223 raise FatalConversionError ()
1225 str = re.sub ('HaraKiriStaffContext', 'RemoveEmptyStaffContext', str)
1228 conversions.append (((1,7,19), conv,"remove GraceContext"))
1235 r"(set|override|revert) *#'type",
1240 conversions.append (((1,7,22), conv,"#'type -> #'style"))
1245 "barNonAuto *= *##t",
1246 "automaticBars = ##f",
1249 "barNonAuto *= *##f",
1250 "automaticBars = ##t",
1254 conversions.append (((1,7,23), conv,"barNonAuto -> automaticBars"))
1259 if re.search( r'-(start|stop)Cluster', str):
1260 sys.stderr.write ('\n')
1261 sys.stderr.write (NOT_SMART % "Cluster syntax")
1262 sys.stderr.write ('\n')
1263 sys.stderr.write (UPDATE_MANUALLY)
1264 sys.stderr.write ('\n')
1266 raise FatalConversionError ()
1270 conversions.append (((1,7,24), conv,"cluster syntax"))
1274 str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\(override|set) *#'pedal-type *",
1275 r"\property Staff.pedal\1Style ", str)
1276 str = re.sub (r"\\property *Staff\.(Sustain|Sostenuto|UnaCorda)Pedal *\\revert *#'pedal-type", '', str)
1279 conversions.append (((1,7,28), conv,"new Pedal style syntax"))
1288 origstr = '<%s>' % str
1289 if re.search (r'\\\\', str):
1292 if re.search (r'\\property', str):
1295 if re.match (r'^\s*\)?\s*\\[a-zA-Z]+', str):
1299 def sub_durs (m, durs = durs):
1300 durs.append(m.group(2))
1303 str = re.sub (r"([a-z]+[,'!? ]*)([0-9]+\.*)", sub_durs, str)
1310 return '<%s>' % m.group (1)
1317 while last_str <> str:
1320 def sub_tremolos (m, slur_strs = slur_strs):
1322 if tr not in slur_strs:
1323 slur_strs.append (tr)
1326 str = re.sub (r"([a-z]+[',!? ]*)(:[0-9]+)",
1329 def sub_dyn_end (m, dyns = dyns):
1331 return ' ' + m.group(2)
1333 str = re.sub (r'(\\!)\s*([a-z]+)', sub_dyn_end, str)
1334 def sub_slurs(m, slur_strs = slur_strs):
1335 if '-)' not in slur_strs:
1336 slur_strs.append (')')
1339 def sub_p_slurs(m, slur_strs = slur_strs):
1340 if '-\)' not in slur_strs:
1341 slur_strs.append ('\)')
1344 str = re.sub (r"\)[ ]*([a-z]+)", sub_slurs, str)
1345 str = re.sub (r"\\\)[ ]*([a-z]+)", sub_p_slurs, str)
1346 def sub_begin_slurs(m, slur_strs = slur_strs):
1347 if '-(' not in slur_strs:
1348 slur_strs.append ('(')
1351 str = re.sub (r"([a-z]+[,'!?0-9 ]*)\(",
1352 sub_begin_slurs, str)
1353 def sub_begin_p_slurs(m, slur_strs = slur_strs):
1354 if '-\(' not in slur_strs:
1355 slur_strs.append ('\(')
1358 str = re.sub (r"([a-z]+[,'!?0-9 ]*)\\\(",
1359 sub_begin_p_slurs, str)
1361 def sub_dyns (m, slur_strs = slur_strs):
1363 if s == '@STARTCRESC@':
1364 slur_strs.append ("\\<")
1365 elif s == '@STARTDECRESC@':
1366 slur_strs.append ("\\>")
1368 slur_strs.append ('\\!')
1371 str = re.sub (r'@STARTCRESC@', sub_dyns, str)
1372 str = re.sub (r'-?\\!', sub_dyns, str)
1374 def sub_articulations (m, slur_strs = slur_strs):
1376 if a not in slur_strs:
1377 slur_strs.append (a)
1380 str = re.sub (r"([_^-]\@ACCENT\@)", sub_articulations,
1382 str = re.sub (r"([_^-]\\[a-z]+)", sub_articulations,
1384 str = re.sub (r"([_^-][>_.+|^-])", sub_articulations,
1386 str = re.sub (r'([_^-]"[^"]+")', sub_articulations,
1389 def sub_pslurs(m, slur_strs = slur_strs):
1390 slur_strs.append (' \\)')
1392 str = re.sub (r"\\\)[ ]*([a-z]+)", sub_pslurs, str)
1396 suffix = string.join (slur_strs, '') + string.join (pslur_strs,
1398 + string.join (dyns, '')
1400 return '@STARTCHORD@%s@ENDCHORD@%s%s' % (str , dur_str, suffix)
1404 def sub_chords (str):
1409 marker_str = '%% new-chords-done %%'
1411 if re.search (marker_str,str):
1413 str = re.sub ('<<', '@STARTCHORD@', str)
1414 str = re.sub ('>>', '@ENDCHORD@', str)
1416 str = re.sub (r'\\<', '@STARTCRESC@', str)
1417 str = re.sub (r'\\>', '@STARTDECRESC@', str)
1418 str = re.sub (r'([_^-])>', r'\1@ACCENT@', str)
1419 str = re.sub (r'<([^<>{}]+)>', sub_chord, str)
1421 # add dash: -[, so that [<<a b>> c d] becomes
1423 # and gets skipped by articulation_substitute
1424 str = re.sub (r'\[ *(@STARTCHORD@[^@]+@ENDCHORD@[0-9.]*)',
1426 str = re.sub (r'\\! *(@STARTCHORD@[^@]+@ENDCHORD@[0-9.]*)',
1429 str = re.sub (r'<([^?])', r'%s\1' % simstart, str)
1430 str = re.sub (r'>([^?])', r'%s\1' % simend, str)
1431 str = re.sub ('@STARTCRESC@', r'\\<', str)
1432 str = re.sub ('@STARTDECRESC@', r'\\>' ,str)
1433 str = re.sub (r'\\context *Voice *@STARTCHORD@',
1434 '@STARTCHORD@', str)
1435 str = re.sub ('@STARTCHORD@', chordstart, str)
1436 str = re.sub ('@ENDCHORD@', chordend, str)
1437 str = re.sub (r'@ACCENT@', '>', str)
1440 markup_start = re.compile(r"([-^_]|\\mark)\s*(#\s*'\s*)\(")
1441 musicglyph = re.compile(r"\(\s*music\b")
1442 columns = re.compile(r"\(\s*columns\b")
1443 submarkup_start = re.compile(r"\(\s*([a-zA-Z]+)")
1444 leftpar = re.compile(r"\(")
1445 rightpar = re.compile(r"\)")
1447 def text_markup (str):
1449 # Find the beginning of each markup:
1450 match = markup_start.search (str)
1452 result = result + str[:match.end (1)] + " \markup"
1453 str = str[match.end( 2):]
1454 # Count matching parentheses to find the end of the
1457 pars = re.finditer(r"[()]",str)
1459 if par.group () == '(':
1460 nesting_level = nesting_level + 1
1462 nesting_level = nesting_level - 1
1463 if nesting_level == 0:
1464 markup_end = par.end ()
1466 # The full markup in old syntax:
1467 markup = str[:markup_end]
1468 # Modify to new syntax:
1469 markup = musicglyph.sub (r"{\\musicglyph", markup)
1470 markup = columns.sub (r"{", markup)
1471 markup = submarkup_start.sub (r"{\\\1", markup)
1472 markup = leftpar.sub ("{", markup)
1473 markup = rightpar.sub ("}", markup)
1475 result = result + markup
1477 str = str[markup_end:]
1478 match = markup_start.search(str)
1479 result = result + str
1482 def articulation_substitute (str):
1483 str = re.sub (r"""([^-])\[ *(\\?\)?[a-z]+[,']*[!?]?[0-9:]*\.*)""",
1485 str = re.sub (r"""([^-])\\\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
1487 str = re.sub (r"""([^-\\])\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
1489 str = re.sub (r"""([^-])\\! *([a-z]+[,']*[!?]?[0-9:]*\.*)""",
1493 string_or_scheme = re.compile ('("(?:[^"\\\\]|\\\\.)*")|(#\\s*\'?\\s*\\()')
1495 # Only apply articulation_substitute () outside strings and
1496 # Scheme expressions:
1497 def smarter_articulation_subst (str):
1499 # Find the beginning of next string or Scheme expr.:
1500 match = string_or_scheme.search (str)
1502 # Convert the preceding LilyPond code:
1503 previous_chunk = str[:match.start()]
1504 result = result + articulation_substitute (previous_chunk)
1505 if match.group (1): # Found a string
1506 # Copy the string to output:
1507 result = result + match.group (1)
1508 str = str[match.end(1):]
1509 else: # Found a Scheme expression. Count
1510 # matching parentheses to find its end
1511 str = str[match.start ():]
1513 pars = re.finditer(r"[()]",str)
1515 if par.group () == '(':
1516 nesting_level = nesting_level + 1
1518 nesting_level = nesting_level - 1
1519 if nesting_level == 0:
1520 scheme_end = par.end ()
1522 # Copy the Scheme expression to output:
1523 result = result + str[:scheme_end]
1524 str = str[scheme_end:]
1525 # Find next string or Scheme expression:
1526 match = string_or_scheme.search (str)
1527 # Convert the remainder of the file
1528 result = result + articulation_substitute (str)
1531 def conv_relative(str):
1532 if re.search (r"\\relative", str):
1533 str= "#(ly:set-option 'old-relative)\n" + str
1538 str = re.sub (r"#'\(\)", "@SCM_EOL@", str)
1539 str = conv_relative (str)
1540 str = sub_chords (str)
1542 str = text_markup (str)
1543 str = smarter_articulation_subst (str)
1544 str = re.sub ("@SCM_EOL@", "#'()", str)
1548 conversions.append (((1,9,0), conv, """New relative mode,
1549 Postfix articulations, new text markup syntax, new chord syntax."""))
1553 if re.search ("font-style",str):
1554 sys.stderr.write ('\n')
1555 sys.stderr.write (NOT_SMART % "font-sytle")
1556 sys.stderr.write ('\n')
1557 sys.stderr.write (UPDATE_MANUALLY)
1558 sys.stderr.write ('\n')
1560 raise FatalConversionError ()
1562 str = re.sub (r'-\\markup', r'@\\markup', str)
1563 str = re.sub (r'-\\', r'\\', str)
1564 str = re.sub (r'-\)', ')', str)
1565 str = re.sub (r'-\(', '(', str)
1566 str = re.sub ('-\[', '[', str)
1567 str = re.sub ('-\]', ']', str)
1568 str = re.sub ('-~', '~', str)
1569 str = re.sub (r'@\\markup', r'-\\markup', str)
1572 conversions.append (((1,9,1), conv, """Remove - before articulation"""))
1575 str = re.sub ('ly:set-context-property',
1576 'ly:set-context-property!', str)
1577 str = re.sub ('\\\\newcontext', '\\\\new', str)
1578 str = re.sub ('\\\\grace[\t\n ]*([^{ ]+)',
1579 r'\\grace { \1 }', str)
1580 str = re.sub ("\\\\grace[\t\n ]*{([^}]+)}",
1582 \\property Voice.Stem \\override #'stroke-style = #"grace"
1584 \\property Voice.Stem \\revert #'stroke-style }
1589 conversions.append (((1,9,2), conv, """\\newcontext -> \\new"""))
1593 str = re.sub ('accacciatura',
1594 'acciaccatura', str)
1596 if re.search ("context-spec-music", str):
1597 sys.stderr.write ('\n')
1598 sys.stderr.write (NOT_SMART % "context-spec-music")
1599 sys.stderr.write ('\n')
1600 sys.stderr.write (UPDATE_MANUALLY)
1601 sys.stderr.write ('\n')
1603 raise FatalConversionError ()
1605 str = re.sub ('fingerHorizontalDirection *= *#(LEFT|-1)',
1606 "fingeringOrientations = #'(up down left)", str)
1607 str = re.sub ('fingerHorizontalDirection *= *#(RIGHT|1)',
1608 "fingeringOrientations = #'(up down right)", str)
1612 conversions.append (((1,9,3), conv,
1613 """\\acciaccatura misspelling, fingerHorizontalDirection -> fingeringOrientations"""))
1617 if re.search ('\\figures', str):
1618 sys.stderr.write ("Warning: attempting automatic \\figures conversion. Check results!");
1621 def figures_replace (m):
1623 s = re.sub ('<', '@FIGOPEN@',s)
1624 s = re.sub ('>', '@FIGCLOSE@',s)
1625 return '\\figures { %s }' % s
1627 str = re.sub (r'\\figures[ \t\n]*{([^}]+)}', figures_replace, str)
1628 str = re.sub (r'\\<', '@STARTCRESC@', str)
1629 str = re.sub (r'\\>', '@STARTDECRESC@', str)
1630 str = re.sub (r'([-^_])>', r'\1@ACCENT@', str)
1631 str = re.sub (r'<<', '@STARTCHORD@', str)
1632 str = re.sub (r'>>', '@ENDCHORD@', str)
1633 str = re.sub (r'>', '@ENDSIMUL@', str)
1634 str = re.sub (r'<', '@STARTSIMUL@', str)
1635 str = re.sub ('@STARTDECRESC@', '\\>', str)
1636 str = re.sub ('@STARTCRESC@', '\\<', str)
1637 str = re.sub ('@ACCENT@', '>', str)
1638 str = re.sub ('@ENDCHORD@', '>', str)
1639 str = re.sub ('@STARTCHORD@', '<', str)
1640 str = re.sub ('@STARTSIMUL@', '<<', str)
1641 str = re.sub ('@ENDSIMUL@', '>>', str)
1642 str = re.sub ('@FIGOPEN@', '<', str)
1643 str = re.sub ('@FIGCLOSE@', '>', str)
1647 conversions.append (((1,9,4), conv, 'Swap < > and << >>'))
1651 str = re.sub ('HaraKiriVerticalGroup', 'RemoveEmptyVerticalGroup', str)
1655 conversions.append (((1,9,5), conv, 'HaraKiriVerticalGroup -> RemoveEmptyVerticalGroup'))
1658 if re.search ("ly:get-font", str) :
1659 sys.stderr.write ('\n')
1660 sys.stderr.write (NOT_SMART % "(ly:-get-font")
1661 sys.stderr.write ('\n')
1662 sys.stderr.write (FROM_TO \
1663 % ("(ly:paper-get-font (ly:grob-get-paper foo) .. )",
1664 "(ly:paper-get-font (ly:grob-get-paper foo) .. )"))
1665 sys.stderr.write (UPDATE_MANUALLY)
1666 sys.stderr.write ('\n')
1667 raise FatalConversionError ()
1669 if re.search ("\\pitch *#", str) :
1670 sys.stderr.write ('\n')
1671 sys.stderr.write (NOT_SMART % "\\pitch")
1672 sys.stderr.write ('\n')
1673 sys.stderr.write ("Use Scheme code to construct arbitrary note events.")
1674 sys.stderr.write ('\n')
1676 raise FatalConversionError ()
1681 conversions.append (((1,9,6), conv, 'ly:get-font deprecated.'))
1684 def sub_alteration (m):
1688 '-2': 'DOUBLE-FLAT',
1691 '2': 'DOUBLE-SHARP',
1694 return '(ly:make-pitch %s %s %s)' % (m.group(1), m.group (2),
1697 str =re.sub ("\\(ly:make-pitch *([0-9-]+) *([0-9-]+) *([0-9-]+) *\\)",
1698 sub_alteration, str)
1701 str = re.sub ("ly:verbose", "ly:get-option 'verbose", str)
1703 m= re.search ("\\\\outputproperty #([^#]+)[\t\n ]*#'([^ ]+)", str)
1706 r"""\outputproperty found,
1707 Please hand-edit, using
1709 \applyoutput #(outputproperty-compatibility %s '%s <GROB PROPERTY VALUE>)
1711 as a substitution text.""" % (m.group (1), m.group (2)) )
1712 raise FatalConversionError ()
1714 if re.search ("ly:(make-pitch|pitch-alteration)", str) \
1715 or re.search ("keySignature", str):
1716 sys.stderr.write ('\n')
1717 sys.stderr.write (NOT_SMART % "pitches")
1718 sys.stderr.write ('\n')
1720 """The alteration field of Scheme pitches was multiplied by 2
1721 to support quarter tone accidentals. You must update the following constructs by manually:
1723 * calls of ly:make-pitch and ly:pitch-alteration
1724 * keySignature settings made with \property
1726 raise FatalConversionError ()
1729 conversions.append (((1,9,7), conv,
1730 '''use symbolic constants for alterations,
1731 remove \\outputproperty, move ly:verbose into ly:get-option'''))
1735 if re.search ("dash-length",str):
1736 sys.stderr.write ('\n')
1737 sys.stderr.write (NOT_SMART % "dash-length")
1738 sys.stderr.write ('\n')
1739 sys.stderr.write (FROM_TO % ("dash-length", "dash-fraction"))
1740 sys.stderr.write ('\n')
1741 sys.stderr.write (UPDATE_MANUALLY)
1742 sys.stderr.write ('\n')
1743 raise FatalConversionError ()
1746 conversions.append (((1,9,8), conv, """dash-length -> dash-fraction"""))
1751 return "#'font-size = #%d" % (2*string.atoi (match.group (1)))
1753 str =re.sub (r"#'font-relative-size\s*=\s*#\+?([0-9-]+)", func, str)
1754 str =re.sub (r"#'font-family\s*=\s*#'ancient",
1755 r"#'font-family = #'music", str)
1759 conversions.append (((2,1,1), conv, """font-relative-size -> font-size"""))
1762 str =re.sub (r"ly:get-music-length", "ly:music-length", str)
1765 conversions.append (((2,1,2), conv, """ly:get-music-length -> ly:music-length"""))
1768 str =re.sub (r"\.\s+stz=", ". instr ", str)
1771 conversions.append (((2,1,3), conv, """stanza -> instrument"""))
1782 return r" \property %s.melismaBusyProperties \unset" % c
1784 return r"\property %s.melismaBusyProperties = #'(melismaBusy)" % c
1786 str = re.sub (r"\\property ([a-zA-Z]+)\s*\.\s*automaticMelismata\s*=\s*##([ft])", func, str)
1789 conversions.append (((2,1,4), conv, """removal of automaticMelismata; use melismaBusyProperties instead."""))
1794 str =re.sub (r"\\translator\s+([a-zA-Z]+)", r"\\change \1", str)
1797 conversions.append (((2,1,7), conv, """\\translator Staff -> \\change Staff"""))
1800 str =re.sub (r"\\newaddlyrics", r"\\lyricsto", str)
1803 conversions.append (((2,1,10), conv, """\\newaddlyrics -> \\lyricsto"""))
1806 str = re.sub (r'\\include\s*"paper([0-9]+)(-init)?.ly"',
1807 r"#(set-staff-size \1)", str)
1809 def sub_note (match):
1811 log = string.atoi (match.group (1))
1812 dots = string.atoi (match.group (2))
1815 dur = '%d' % (1 << log)
1817 dur = { -1 : 'breve',
1823 return r'\note #"%s" #%s' % (dur, match.group (3))
1825 str = re.sub (r'\\note\s+#([0-9-]+)\s+#([0-9]+)\s+#([0-9.-]+)',
1829 conversions.append (((2,1,11), conv, """\\include "paper16.ly" -> #(set-staff-size 16)
1830 \\note #3 #1 #1 -> \\note #"8." #1
1835 str =re.sub (r"OttavaSpanner", r"OttavaBracket", str)
1838 conversions.append (((2,1,12), conv, """OttavaSpanner -> OttavaBracket"""))
1842 str =re.sub (r"\(set-staff-size ", r"(set-global-staff-size ", str)
1845 conversions.append (((2,1,13), conv, """set-staff-size -> set-global-staff-size"""))
1848 str =re.sub (r"#'style\s*=\s*#'dotted-line",
1849 r"#'dash-fraction = #0.0 ", str)
1852 conversions.append (((2,1,14), conv, """style = dotted -> dash-fraction = 0"""))
1855 str =re.sub (r'LyricsVoice\s*\.\s*instrument\s*=\s*("[^"]*")',
1856 r'LyricsVoice . vocalName = \1', str)
1858 str =re.sub (r'LyricsVoice\s*\.\s*instr\s*=\s*("[^"]*")',
1859 r'LyricsVoice . vocNam = \1', str)
1862 conversions.append (((2,1,15), conv, """LyricsVoice . instr(ument) -> vocalName"""))
1876 return '\\%s' % d[m.group (1)]
1878 str = re.sub (r'\\musicglyph\s*#"accidentals-([0-9-]+)"',
1882 conversions.append (((2,1,16), conv, """\\musicglyph #"accidentals-NUM" -> \\sharp/flat/etc."""))
1887 if re.search (r'\\partcombine', str):
1888 sys.stderr.write ('\n')
1889 sys.stderr.write (NOT_SMART % "\\partcombine")
1890 sys.stderr.write ('\n')
1891 sys.stderr.write (UPDATE_MANUALLY)
1892 sys.stderr.write ('\n')
1893 raise FatalConversionError ()
1895 # this rule doesn't really work,
1896 # too lazy to figure out why.
1897 str = re.sub (r'\\context\s+Voice\s*=\s*one\s*\\partcombine\s+Voice\s*\\context\s+Thread\s*=\s*one(.*)\s*'
1898 + r'\\context\s+Thread\s*=\s*two',
1899 '\\\\newpartcombine\n\\1\n', str)
1904 conversions.append (((2,1,17), conv, """\\partcombine syntax change to \\newpartcombine"""))
1908 str = re.sub (r'\\newpartcombine', r'\\partcombine', str)
1909 str = re.sub (r'\\autochange\s+Staff', r'\\autochange ', str)
1912 conversions.append (((2,1,18), conv, """\\newpartcombine -> \\partcombine,
1913 \\autochange Staff -> \\autochange
1920 str = re.sub (r'\\include "drumpitch-init.ly"','', str)
1921 str = re.sub (r'\\pitchnames ','pitchnames = ', str)
1922 str = re.sub (r'\\chordmodifiers ','chordmodifiers = ', str)
1923 str = re.sub (r'\bdrums\b\s*=','drumContents = ', str)
1924 str = re.sub (r'\\drums\b','\\drumContents ', str)
1927 if re.search ('drums->paper', str):
1928 sys.stderr.write ("\nDrum notation found. Check file manually!")
1930 str = re.sub (r"""\\apply\s+#\(drums->paper\s+'([a-z]+)\)""",
1931 r"""\property DrumStaff.drumStyleTable = #\1-style""",
1934 if re.search ('Thread', str):
1935 sys.stderr.write ("\nThread found. Check file manually!\n");
1937 str = re.sub (r"""(\\once\s*)?\\property\s+Thread\s*\.\s*NoteHead\s*"""
1938 + r"""\\(set|override)\s*#'style\s*=\s*#'harmonic"""
1939 + r"""\s+([a-z]+[,'=]*)([0-9]*\.*)"""
1940 ,r"""<\3\\harmonic>\4""", str)
1942 str = re.sub (r"""\\new Thread""", """\context Voice""", str)
1943 str = re.sub (r"""Thread""", """Voice""", str)
1945 if re.search ('\bLyrics\b', str):
1946 sys.stderr.write ("\nLyrics found. Check file manually!\n");
1948 str = re.sub (r"""LyricsVoice""", r"""L@ricsVoice""", str)
1949 str = re.sub (r"""\bLyrics\b""", r"""LyricsVoice""", str)
1950 str = re.sub (r"""LyricsContext""", r"""LyricsVoiceContext""", str)
1951 str = re.sub (r"""L@ricsVoice""", r"""LyricsVoice""",str)
1956 conversions.append (((2,1,19), conv, """Drum notation changes, Removing \\chordmodifiers, \\notenames.
1957 Harmonic notes. Thread context removed. Lyrics context removed."""))
1960 str = re.sub (r'nonevent-skip', 'skip-music', str)
1963 conversions.append (((2,1,20), conv, """nonevent-skip -> skip-music""" ))
1966 str = re.sub (r'molecule-callback', 'print-function', str)
1967 str = re.sub (r'brew_molecule', 'print', str)
1968 str = re.sub (r'brew-new-markup-molecule', 'Text_item::print', str)
1969 str = re.sub (r'LyricsVoice', 'Lyrics', str)
1970 str = re.sub (r'tupletInvisible',
1971 r"TupletBracket \\set #'transparent", str)
1972 # str = re.sub (r'molecule', 'collage', str)
1973 #molecule -> collage
1974 str = re.sub (r"\\property\s+[a-zA-Z]+\s*\.\s*[a-zA-Z]+\s*"
1975 + r"\\set\s*#'X-extent-callback\s*=\s*#Grob::preset_extent",
1980 conversions.append (((2,1,21), conv, """molecule-callback -> print-function,
1981 brew_molecule -> print
1982 brew-new-markup-molecule -> Text_item::print
1983 LyricsVoice -> Lyrics
1984 tupletInvisible -> TupletBracket \set #'transparent
1985 Grob::preset_extent removed.
1990 str = re.sub (r'(\\property[^=]+)=\s*([-0-9]+)',
1992 str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\=]+)\s*\\(set|override)',
1993 r"\\overrid@ \1.\2 ", str)
1994 str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*=\s*',
1995 r'\\s@t \1.\2 = ', str)
1996 str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*\\unset',
1997 r'\\uns@t \1.\2 ', str)
1998 str = re.sub (r'\\property\s+([^. ]+)\s*\.\s*([^\\= ]+)\s*\\revert'
1999 + r"\s*#'([-a-z0-9_]+)",
2000 r"\\rev@rt \1.\2 #'\3", str)
2001 str = re.sub (r'Voice\.', '', str)
2002 str = re.sub (r'Lyrics\.', '', str)
2003 str = re.sub (r'ChordNames\.', '', str)
2005 str = re.sub ('rev@rt', 'revert',str)
2006 str = re.sub ('s@t', 'set',str)
2007 str = re.sub ('overrid@', 'override',str)
2009 str = re.sub ('molecule', 'stencil', str)
2010 str = re.sub ('Molecule', 'Stencil', str)
2013 conversions.append (((2,1,22), conv, """new syntax for property settings:
2014 \\set A.B = #C , \\unset A.B
2015 \\override A.B #C = #D, \\revert A.B #C
2020 def subst_in_trans (match):
2022 s = re.sub (r'\s([a-zA-Z]+)\s*\\override',
2023 r' \\override \1', s)
2024 s = re.sub (r'\s([a-zA-Z]+)\s*\\set',
2025 r' \\override \1', s)
2026 s = re.sub (r'\s([a-zA-Z]+)\s*\\revert',
2029 str = re.sub (r'\\(translator|with)\s*{[^}]+}', subst_in_trans, str)
2033 context = m.group ('context')
2036 context = " '%s" % context[:-1] # -1: remove .
2040 d['context'] = context
2042 return r"""#(override-auto-beam-setting %(prop)s %(num)s %(den)s%(context)s)""" % d
2044 str = re.sub (r"""\\override\s*(?P<context>[a-zA-Z]+\s*\.\s*)?autoBeamSettings"""
2045 +r"""\s*#(?P<prop>[^=]+)\s*=\s*#\(ly:make-moment\s+(?P<num>\d+)\s+(?P<den>\d)\s*\)""",
2050 conversions.append (((2,1,23), conv, """Property setting syntax in \\translator{ }"""))
2052 str = re.sub (r'music-list\?', 'ly:music-list?', str)
2053 str = re.sub (r'\|\s*~', '~ |', str)
2056 conversions.append (((2,1,24), conv, """music-list? -> ly:music-list?"""))
2059 str = re.sub (r'ly:get-spanner-bound', 'ly:spanner-get-bound', str)
2060 str = re.sub (r'ly:get-extent', 'ly:grob-extent', str)
2061 str = re.sub (r'ly:get-system', 'ly:grob-system', str)
2062 str = re.sub (r'ly:get-original', 'ly:grob-original', str)
2063 str = re.sub (r'ly:get-parent', 'ly:grob-parent', str)
2064 str = re.sub (r'ly:get-broken-into', 'ly:spanner-broken-into', str)
2065 str = re.sub (r'Melisma_engraver', 'Melisma_translator', str)
2066 if re.search ("ly:get-paper-variable", str):
2067 sys.stderr.write ('\n')
2068 sys.stderr.write (NOT_SMART % "ly:paper-get-variable")
2069 sys.stderr.write ('\n')
2070 sys.stderr.write ('use (ly:paper-lookup (ly:grob-paper ))')
2071 sys.stderr.write ('\n')
2072 raise FatalConversionError ()
2074 str = re.sub (r'\\defaultAccidentals', "#(set-accidental-style 'default)", str)
2075 str = re.sub (r'\\voiceAccidentals', "#(set-accidental-style 'voice)", str)
2076 str = re.sub (r'\\modernAccidentals', "#(set-accidental-style 'modern)", str)
2077 str = re.sub (r'\\modernCautionaries', "#(set-accidental-style 'modern-cautionary)", str)
2078 str = re.sub (r'\\modernVoiceAccidental', "#(set-accidental-style 'modern-voice)", str)
2079 str = re.sub (r'\\modernVoiceCautionaries', "#(set-accidental-style 'modern-voice-cautionary)", str)
2080 str = re.sub (r'\\pianoAccidentals', "#(set-accidental-style 'piano)", str)
2081 str = re.sub (r'\\pianoCautionaries', "#(set-accidental-style 'piano-cautionary)", str)
2082 str = re.sub (r'\\forgetAccidentals', "#(set-accidental-style 'forget)", str)
2083 str = re.sub (r'\\noResetKey', "#(set-accidental-style 'no-reset)", str)
2087 conversions.append (((2,1,25), conv, """Scheme grob function renaming"""))
2091 str = re.sub ('ly:set-grob-property!', 'ly:grob-set-property!',str)
2092 str = re.sub ('ly:set-mus-property!', 'ly:music-set-property!',str)
2093 str = re.sub ('ly:set-context-property!', 'ly:context-set-property!', str)
2094 str = re.sub ('ly:get-grob-property', 'ly:grob-property',str)
2095 str = re.sub ('ly:get-mus-property', 'ly:music-property',str)
2096 str = re.sub ('ly:get-context-property', 'ly:context-property',str)
2100 conversions.append (((2,1,26), conv, """More Scheme function renaming"""))
2104 g = string.atoi (m.group (2))
2112 lower_pitches = filter (lambda x : x <= g, [0, 2, 4, 5, 7, 9, 11, 12])
2113 s = len (lower_pitches) -1
2114 a = g - lower_pitches [-1]
2117 print s , lower_pitches, g, a, s
2119 str += ['eses', 'es', '', 'is', 'isis'][a + 2]
2121 str += ',' * (-o - 1)
2123 str += "'" * (o + 1)
2125 return '\\transposition %s ' % str
2128 str = re.sub (r"\\set ([A-Za-z]+\s*\.\s*)?transposing\s*=\s*#([-0-9]+)",
2132 conversions.append (((2,1,27), conv, """property transposing -> tuning"""))
2135 str = re.sub (r'make-music-by-name', 'make-music', str)
2136 str = re.sub (r"\\override\s+.*Arpeggio\s+#.print-function\s+=\s+\\arpeggioBracket", r"\\arpeggioBracket", str)
2139 conversions.append (((2,1,28), conv,
2140 """make-music-by-name -> make-music,
2141 new syntax for setting \\arpeggioBracket"""))
2144 str = re.sub (r'\\center([^-])', '\\center-align\\1', str)
2145 str = re.sub (r'\\translator', '\\context', str)
2148 conversions.append (((2,1,29), conv,
2149 '\\center -> \\center-align, \\translator -> \\context'))
2153 str = re.sub (r'\\threeq(flat|sharp)', r'\\sesqui\1', str)
2154 str = re.sub (r'ly:stencil-get-extent',
2155 'ly:stencil-extent', str)
2156 str = re.sub (r'ly:translator-find',
2157 'ly:context-find', str)
2158 str = re.sub ('ly:unset-context-property','ly:context-unset-property',
2161 str = re.sub (r'ly:get-mutable-properties',
2162 'ly:mutable-music-properties',str)
2163 str = re.sub (r'centralCPosition',
2164 'middleCPosition',str)
2167 conversions.append (((2,1,30), conv,
2168 '''\\threeq{flat,sharp} -> \\sesqui{flat,sharp}
2169 ly:get-mutable-properties -> ly:mutable-music-properties
2170 centralCPosition -> middleCPosition
2171 ly:unset-context-property -> ly:context-unset-property
2172 ly:translator-find -> ly:context-find
2173 ly:get-stencil-extent -> ly:stencil-extent
2178 str = re.sub (r'\\alias\s*"?Timing"?', '', str)
2181 conversions.append (((2,1,31), conv,
2182 '''remove \\alias Timing'''))
2185 str = re.sub (r"(\\set\s+)?(?P<context>(Score\.)?)breakAlignOrder\s*=\s*#'(?P<list>[^\)]+)",
2186 r"\n\\override \g<context>BreakAlignment #'break-align-orders = "
2187 + "#(make-vector 3 '\g<list>)", str)
2191 conversions.append (((2,1,33), conv,
2192 '''breakAlignOrder -> break-align-orders.'''))
2195 str = re.sub (r"\(set-paper-size",
2196 "(set-default-paper-size",str)
2199 conversions.append (((2,1,34), conv,
2200 '''set-paper-size -> set-default-paper-size.'''))
2203 str = re.sub (r"ly:mutable-music-properties",
2204 "ly:music-mutable-properties", str)
2207 conversions.append (((2,1, 36), conv,
2208 '''ly:mutable-music-properties -> ly:music-mutable-properties'''))
2215 conversions.append (((2, 2, 0), conv,
2216 '''clean up version. '''))
2219 return re.sub (r'\\apply\b', r'\\applymusic', str)
2221 conversions.append (((2, 3, 1), conv,
2222 '''\\apply -> \\applymusic'''))
2225 if re.search ('textheight', str):
2226 sys.stderr.write ('\n')
2227 sys.stderr.write (NOT_SMART % "textheight")
2228 sys.stderr.write ('\n')
2229 sys.stderr.write (UPDATE_MANUALLY)
2230 sys.stderr.write ('\n')
2232 """Page layout has been changed, using paper size and margins.
2233 textheight is no longer used.
2235 str = re.sub (r'\\OrchestralScoreContext', '\\Score', str)
2237 if m.group(1) not in ['RemoveEmptyStaff',
2238 'AncientRemoveEmptyStaffContext',
2240 return '\\' + m.group (1)
2245 str = re.sub (r'\\([a-zA-Z]+)Context\b', func, str)
2246 str = re.sub ('ly:paper-lookup', 'ly:output-def-lookup', str)
2249 conversions.append (((2, 3, 2), conv,
2250 '''\\FooContext -> \\Foo'''))
2253 str = re.sub (r'\\notes\b', '', str)
2257 conversions.append (((2, 3, 4), conv,
2258 '''remove \\notes'''))
2263 str = re.sub (r'lastpagefill\s*=\s*"?1"', 'raggedlastbottom = ##t', str)
2266 conversions.append (((2, 3, 6), conv,
2267 '''lastpagefill -> raggedlastbottom'''))
2272 str = re.sub (r'\\consistsend', '\\consists', str)
2273 str = re.sub (r'\\lyricsto\s+("?[a-zA-Z]+"?)(\s*\\new Lyrics\s*)?\\lyrics',
2274 r'\\lyricsto \1 \2', str)
2277 conversions.append (((2, 3, 8), conv,
2278 '''remove \\consistsend, strip \\lyrics from \\lyricsto.'''))
2281 str = re.sub (r'neo_mensural', 'neomensural', str)
2282 str = re.sub (r'if-text-padding', 'bound-padding', str)
2285 conversions.append (((2, 3, 9), conv,
2286 '''neo_mensural -> neomensural, if-text-padding -> bound-padding'''))
2291 str = re.sub (r'\\addlyrics', r'\\oldaddlyrics', str)
2292 str = re.sub (r'\\newlyrics', r'\\addlyrics', str)
2293 if re.search (r"\\override\s*TextSpanner", str):
2294 sys.stderr.write ("\nWarning: TextSpanner has been split into DynamicTextSpanner and TextSpanner\n")
2297 conversions.append (((2, 3, 10), conv,
2298 '''\\addlyrics -> \\oldaddlyrics, \\newlyrics -> \\addlyrics'''))
2301 str = re.sub (r'\\setMmRestFermata\s+(R[0-9.*/]*)',
2302 r'\1^\\fermataMarkup', str)
2305 conversions.append (((2, 3, 11), conv,
2306 '''\\setMmRestFermata -> ^\\fermataMarkup'''))
2309 str = re.sub (r'\\newpage', r'\\pageBreak', str)
2310 str = re.sub (r'\\scriptUp', r"""{
2311 \\override TextScript #'direction = #1
2312 \\override Script #'direction = #1
2314 str = re.sub (r'\\scriptDown', r"""{
2315 \\override TextScript #'direction = #-1
2316 \\override Script #'direction = #-1
2318 str = re.sub (r'\\scriptBoth', r"""{
2319 \\revert TextScript #'direction
2320 \\revert Script #'direction
2322 str = re.sub ('soloADue', 'printPartCombineTexts', str)
2323 str = re.sub (r'\\applymusic\s*#notes-to-clusters',
2324 '\\makeClusters', str)
2326 str = re.sub (r'pagenumber\s*=', 'firstpagenumber = ', str)
2329 conversions.append (((2, 3, 12), conv,
2330 '''\\newpage -> \\pageBreak, junk \\script{up,down,both},
2331 soloADue -> printPartCombineTexts, #notes-to-clusters -> \\makeClusters
2336 str = re.sub (r'\\chords\b', r'\\chordmode', str)
2337 str = re.sub (r'\\lyrics\b', r'\\lyricmode', str)
2338 str = re.sub (r'\\figures\b', r'\\figuremode', str)
2339 str = re.sub (r'\\notes\b', r'\\notemode', str)
2340 str = re.sub (r'\\drums\b', r'\\drummode', str)
2341 str = re.sub (r'\\chordmode\s*\\new ChordNames', r'\\chords', str)
2342 str = re.sub (r'\\new ChordNames\s*\\chordmode', r'\\chords', str)
2343 str = re.sub (r'\\new FiguredBass\s*\\figuremode', r'\\figures', str)
2344 str = re.sub (r'\\figuremode\s*\new FiguredBass', r'\\figures', str)
2345 str = re.sub (r'\\new DrumStaff\s*\\drummode', r'\\drums', str)
2346 str = re.sub (r'\\drummode\s*\\new DrumStaff', r'\\drums', str)
2350 conversions.append (((2, 3, 16), conv,
2351 '''\foo -> \foomode (for chords, notes, etc.)
2352 fold \new FooContext \foomode into \foo.'''))
2355 str = re.sub (r'(slur|stem|phrasingSlur|tie|dynamic|dots|tuplet|arpeggio|)Both', r'\1Neutral', str)
2356 str = re.sub (r"\\applymusic\s*#\(remove-tag\s*'([a-z-0-9]+)\)",
2357 r"\\removeWithTag #'\1", str)
2360 conversions.append (((2, 3, 17), conv,
2361 '''\foo -> \foomode (for chords, notes, etc.)
2362 fold \new FooContext \foomode into \foo.'''))
2366 str = re.sub (r'Text_item', 'Text_interface', str)
2369 conversions.append (((2, 3, 18),
2371 '''Text_item -> Text_interface''' ))
2374 str = re.sub (r'\\paper', r'\\layout', str)
2375 str = re.sub (r'\\bookpaper', r'\\paper', str)
2376 if re.search ('paper-set-staff-size', str):
2377 sys.stderr.write ('''\nWarning: staff size should be changed at top-level
2380 #(set-global-staff-size <STAFF-HEIGHT-IN-POINT>)
2385 str = re.sub (r'#\(paper-set-staff-size', '%Use set-global-staff-size at toplevel\n% #(layout-set-staff-size', str)
2388 conversions.append (((2, 3, 22),
2391 bookpaper -> paper''' ))
2395 str = re.sub (r'\\context\s+([a-zA-Z]+)\s*=\s*([a-z]+)\s',
2396 r'\\context \1 = "\2" ',
2400 conversions.append (((2, 3, 23),
2402 '''\context Foo = NOTENAME -> \context Foo = "NOTENAME"'''))
2406 return regularize_id (m.group (1))
2407 str = re.sub (r'(maintainer_email|maintainer_web|midi_stuff|gourlay_maxmeasures)',
2411 conversions.append (((2, 3, 24),
2413 '''regularize other identifiers.'''))
2419 conversions.append (((2, 4, 0),
2425 str = re.sub (r'\\quote\s+"?([a-zA-Z0-9]+)"?\s+([0-9.*/]+)',
2426 r'\\quoteDuring #"\1" { \skip \2 }',
2431 conversions.append (((2, 5, 0),
2437 str = re.sub (r'ly:import-module',
2438 r'ly:module-copy', str)
2441 conversions.append (((2, 5, 1),
2443 'ly:import-module -> ly:module-copy'))
2446 str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>',
2448 str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>',
2450 str = re.sub (r'\\(column|fill-line|dir-column|center-align|right-align|left-align|bracketed-y-column)\s*<(([^>]|<[^>]*>)*)>',
2454 s = re.sub (r'''((\\"|})\s*){''', '\2 \\line {', s)
2456 str = re.sub (r'\\markup\s*{([^}]|{[^}]*})*}', get_markup, str)
2459 conversions.append (((2, 5, 2),
2461 '\markup .. < .. > .. -> \markup .. { .. } ..'))
2464 str = re.sub ('ly:find-glyph-by-name', 'ly:font-get-glyph', str)
2465 str = re.sub ('"(scripts|clefs|accidentals)-', r'"\1.', str)
2466 str = re.sub ("'hufnagel-do-fa", "'hufnagel.do.fa", str)
2467 str = re.sub ("'(vaticana|hufnagel|medicaea|petrucci|neomensural|mensural)-", r"'\1.", str)
2470 conversions.append (((2, 5, 3),
2472 'ly:find-glyph-by-name -> ly:font-get-glyph, remove - from glyphnames.'))
2476 str = re.sub (r"\\override\s+(Voice\.)?Slur #'dashed\s*=\s*#\d*(\.\d+)?",
2477 r"\\slurDashed", str)
2480 conversions.append (((2, 5, 12),
2482 '\set Slur #\'dashed = #X -> \slurDashed'))
2485 input_encoding = 'latin1'
2487 encoding = match.group (1)
2489 # FIXME: automatic recoding of other than latin1?
2490 if encoding == 'latin1':
2491 return match.group (2)
2493 sys.stderr.write ('\n')
2494 sys.stderr.write (NOT_SMART % ("\\encoding: %s" % encoding))
2495 sys.stderr.write ('\n')
2496 sys.stderr.write (_ ("LilyPond source must be UTF-8"))
2497 sys.stderr.write ('\n')
2498 if encoding == 'TeX':
2499 sys.stderr.write (_ ("Try the texstrings backend"))
2500 sys.stderr.write ('\n')
2502 sys.stderr.write ( _("Do something like: %s") % \
2503 ("recode %s..utf-8 FILE" % encoding))
2504 sys.stderr.write ('\n')
2505 sys.stderr.write (_ ("Or save as UTF-8 in your editor"))
2506 sys.stderr.write ('\n')
2507 raise FatalConversionError ()
2509 return match.group (0)
2511 str = re.sub (r'\\encoding\s+"?([a-zA-Z0-9]+)"?(\s+)', func, str)
2514 de_ascii = codecs.getdecoder ('ascii')
2515 de_utf_8 = codecs.getdecoder ('utf_8')
2516 de_input = codecs.getdecoder (input_encoding)
2517 en_utf_8 = codecs.getencoder ('utf_8')
2520 # only in python >= 2.3
2521 # except UnicodeDecodeError:
2522 except UnicodeError:
2523 # do not re-recode UTF-8 input
2526 #except UnicodeDecodeError:
2527 except UnicodeError:
2528 str = en_utf_8 (de_input (str)[0])[0]
2532 str = re.sub (r"#\(ly:set-point-and-click '[a-z-]+\)", '', str)
2535 conversions.append (((2, 5, 13),
2537 '\\encoding: smart recode latin1..utf-8. Remove ly:point-and-click'))
2541 if re.search ("ly:stencil-set-extent!", str):
2542 sys.stderr.write ('\n')
2543 sys.stderr.write (NOT_SMART % "ly:stencil-set-extent!")
2544 sys.stderr.write ('\n')
2545 sys.stderr.write ('use (set! VAR (ly:make-stencil (ly:stencil-expr VAR) X-EXT Y-EXT))\n')
2546 raise FatalConversionError ()
2547 if re.search ("ly:stencil-align-to!", str):
2548 sys.stderr.write ('\n')
2549 sys.stderr.write (NOT_SMART % "ly:stencil-align-to!")
2550 sys.stderr.write ('\n')
2551 sys.stderr.write ('use (set! VAR (ly:stencil-aligned-to VAR AXIS DIR))\n')
2552 raise FatalConversionError ()
2555 conversions.append (((2, 5, 17),
2557 'ly:stencil-set-extent! removed'))
2560 str = re.sub (r"ly:warn\b", 'ly:warning', str)
2563 conversions.append (((2, 5, 18),
2565 'ly:warn -> ly:warning'))
2567 if re.search ("(override-|revert-)auto-beam-setting", str)\
2568 or re.search ("autoBeamSettings", str):
2569 sys.stderr.write ('\n')
2570 sys.stderr.write (NOT_SMART % "auto beam settings")
2571 sys.stderr.write ('\n')
2572 sys.stderr.write ('''
2573 Auto beam settings must now specify each interesting moment in a measure
2574 explicitely; 1/4 is no longer multiplied to cover moments 1/2 and 3/4 too.
2576 sys.stderr.write (UPDATE_MANUALLY)
2577 sys.stderr.write ('\n')
2578 raise FatalConversionError ()
2581 conversions.append (((2, 5, 21),
2583 'warn about auto beam settings'))
2585 ################################
2586 # END OF CONVERSIONS
2587 ################################
2589 def get_conversions (from_version, to_version):
2590 def version_b (v, f = from_version, t = to_version):
2591 return version_cmp (v[0], f) > 0 and version_cmp (v[0], t) <= 0
2592 return filter (version_b, conversions)
2595 def latest_version ():
2596 return conversions[-1][0]
2598 def do_conversion (infile, from_version, outfile, to_version):
2599 conv_list = get_conversions (from_version, to_version)
2601 sys.stderr.write (_ ("Applying conversion: "))
2602 str = infile.read ()
2603 last_conversion = ()
2606 sys.stderr.write (tup_to_str (x[0]))
2607 if x != conv_list[-1]:
2608 sys.stderr.write (', ')
2610 last_conversion = x[0]
2612 except FatalConversionError:
2613 sys.stderr.write (_ ("%s: error while converting") \
2615 sys.stderr.write ('\n')
2616 sys.stderr.write (_ ("Aborting"))
2617 sys.stderr.write ('\n')
2620 new_ver = '\\version \"%s\"' % tup_to_str (last_conversion)
2622 if re.search (lilypond_version_re_str, str):
2623 str = re.sub (lilypond_version_re_str,
2624 '\\%s' % new_ver, str)
2626 str = new_ver + '\n' + str
2628 sys.stderr.write ('\n')
2631 return last_conversion
2633 class UnknownVersion:
2636 def do_one_file (infile_name):
2637 sys.stderr.write (_ ("Processing `%s\'... ") % infile_name)
2638 sys.stderr.write ('\n')
2641 outfile_name = infile_name + '.NEW'
2642 elif __main__.outfile_name:
2643 outfile_name = __main__.outfile_name
2645 if __main__.from_version:
2646 from_version = __main__.from_version
2648 guess = guess_lilypond_version (infile_name)
2650 raise UnknownVersion ()
2651 from_version = str_to_tuple (guess)
2653 if __main__.to_version:
2654 to_version = __main__.to_version
2656 to_version = latest_version ()
2660 infile = open (infile_name, 'r')
2665 outfile = open (outfile_name, 'w')
2667 outfile = sys.stdout
2669 touched = do_conversion (infile, from_version, outfile, to_version)
2677 if __main__.edit and touched:
2679 os.remove(infile_name + '~')
2682 os.rename (infile_name, infile_name + '~')
2683 os.rename (infile_name + '.NEW', infile_name)
2694 (options, files) = getopt.getopt (sys.argv[1:], 'ao:f:t:senhv',
2695 ['no-version', 'version', 'output',
2696 'show-rules', 'help', 'edit',
2702 if o == '--help' or o == '-h':
2705 elif o == '--version' or o == '-v':
2708 elif o== '--from' or o=='-f':
2709 from_version = str_to_tuple (a)
2710 elif o== '--to' or o=='-t':
2711 to_version = str_to_tuple (a)
2712 elif o== '--edit' or o == '-e':
2714 elif o== '--show-rules' or o == '-s':
2716 elif o == '--output' or o == '-o':
2718 elif o == '--no-version' or o == '-n':
2724 # should parse files[] to read \version?
2726 show_rules (sys.stdout)
2738 elif not os.path.isfile (f):
2739 sys.stderr.write ('\n')
2740 sys.stderr.write (_ ("can't open file: `%s'") % f)
2741 sys.stderr.write ('\n')
2742 if len (files) == 1:
2747 except UnknownVersion:
2748 sys.stderr.write ('\n')
2749 sys.stderr.write (_ ("%s: can't determine version for `%s'") \
2750 % (program_name, f))
2751 sys.stderr.write ('\n')
2754 from_version = (0, 0, 0)
2758 sys.stderr.write (_ ("%s: skipping: `%s'") \
2759 % (program_name, f))
2762 sys.stderr.write ('\n')