3 # once upon a rainy monday afternoon.
8 # ABC standard v1.6: http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt
10 # Enhancements (Roy R. Rankin)
12 # Header section moved to top of lilypond file
13 # handle treble, treble-8, alto, and bass clef
14 # Handle voices (V: headers) with clef and part names, multiple voices
15 # Handle w: lyrics with multiple verses
16 # Handle key mode names for minor, major, phrygian, ionian, locrian, aeolian,
17 # mixolydian, lydian, dorian
18 # Handle part names from V: header
19 # Tuplets handling fixed up
20 # Lines starting with |: not discarded as header lines
21 # Multiple T: and C: header entries handled
22 # Accidental maintained until next bar check
23 # Silent rests supported
24 # articulations fermata, upbow, downbow, ltoe, accent, tenuto supported
25 # Chord strings([-^]"string") can contain a '#'
26 # Header fields enclosed by [] in notes string processed
27 # W: words output after tune as abc2ps does it (they failed before)
29 # Enhancements (Laura Conrad)
31 # Barring now preserved between ABC and lilypond
32 # the default placement for text in abc is above the staff.
34 # \breve and \longa supported.
38 # Multiple tunes in single file not supported
39 # Blank T: header lines should write score and open a new score
40 # Not all header fields supported
41 # ABC line breaks are ignored
42 # Block comments generate error and are ignored
43 # Postscript commands are ignored
44 # lyrics not resynchronized by line breaks (lyrics must fully match notes)
45 # %%LY slyrics can't be directly before a w: line.
55 program_name = 'abc2ly'
56 version = '@TOPLEVEL_VERSION@'
57 if version == '@' + 'TOPLEVEL_VERSION' + '@':
58 version = '(unknown version)' # uGUHGUHGHGUGH
73 header['footnotes'] = ''
78 repeat_state = [0] * 8
79 current_voice_idx = -1
80 current_lyric_idx = -1
86 global_key = [0] * 7 # UGH
87 names = ["One", "Two", "Three"]
89 alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
95 sys.stderr.write (msg)
103 if re.match('-8va', s) or re.match('treble8', s):
104 # treble8 is used by abctab2ps; -8va is used by barfly,
105 # and by my patch to abc2ps. If there's ever a standard
106 # about this we'll support that.
108 state.base_octave = -1
109 voices_append("\\clef \"G_8\"\n")
110 elif re.match('^treble', s):
112 if re.match ('^-8', s):
114 state.base_octave = -2
115 voices_append("\\clef \"G_8\"\n")
117 state.base_octave = 0
118 voices_append("\\clef treble\n")
119 elif re.match('^alto', s):
121 state.base_octave = -1
122 voices_append ("\\clef alto\n" )
123 elif re.match('^bass',s ):
125 state.base_octave = -2
126 voices_append ("\\clef bass\n" )
129 def select_voice (name, rol):
130 if not voice_idx_dict.has_key (name):
131 state_list.append(Parser_state())
134 voice_idx_dict[name] = len (voices) -1
135 __main__.current_voice_idx = voice_idx_dict[name]
136 __main__.state = state_list[current_voice_idx]
138 m = re.match ('^([^ \t=]*)=(.*)$', rol) # find keywork
142 a = re.match ('^("[^"]*"|[^ \t]*) *(.*)$', rol)
146 if keyword == 'clef':
148 elif keyword == "name":
149 value = re.sub ('\\\\','\\\\\\\\', value)
150 voices_append ("\\property Staff.instrument = %s\n" % value )
151 __main__.part_names = 1
152 elif keyword == "sname" or keyword == "snm":
153 voices_append ("\\property Staff.instr = %s\n" % value )
161 def dump_header (outf,hdr):
162 outf.write ('\\header {\n')
166 outf.write ('\t%s = "%s"\n'% (k,hdr[k]))
169 def dump_lyrics (outf):
171 outf.write("\n\\score\n{\n \\context Lyrics\n <\n")
172 for i in range (len (lyrics)):
173 outf.write ( lyrics [i])
175 outf.write(" >\n \\paper{}\n}\n")
177 def dump_default_bar (outf):
178 outf.write ("\n\\property Score.defaultBarType=\"empty\"\n")
181 def dump_slyrics (outf):
182 ks = voice_idx_dict.keys()
185 if re.match('[1-9]', k):
186 m = alphabet[string.atoi(k)]
189 for i in range (len(slyrics[voice_idx_dict[k]])):
191 outf.write ("\nwords%sV%s = \\lyrics {" % (m, l))
192 outf.write ("\n" + slyrics [voice_idx_dict[k]][i])
195 def dump_voices (outf):
196 global doing_alternative, in_repeat
197 ks = voice_idx_dict.keys()
200 if re.match ('[1-9]', k):
201 m = alphabet[string.atoi(k)]
204 outf.write ("\nvoice%s = \\notes {" % m)
205 dump_default_bar(outf)
206 if repeat_state[voice_idx_dict[k]]:
207 outf.write("\n\\repeat volta 2 {")
208 outf.write ("\n" + voices [voice_idx_dict[k]])
210 if doing_alternative[voice_idx_dict[k]]:
212 if in_repeat[voice_idx_dict[k]]:
218 #assume that Q takes the form "Q:1/4=120"
219 #There are other possibilities, but they are deprecated
220 if string.count(a, '/') == 1:
221 array=string.split(a,'/')
224 sys.stderr.write("abc2ly: Warning, unable to translate a Q specification with a numerator of %s: %s\n" % (numerator, a))
225 array2=string.split(array[1],'=')
226 denominator=array2[0]
228 duration=str(string.atof(denominator)/string.atoi(numerator))
229 midi_specs=string.join(["\\tempo", duration, "=", perminute])
231 sys.stderr.write("abc2ly: Warning, unable to parse Q specification: %s\n" % a)
233 def dump_score (outf):
234 outf.write (r"""\score{
238 ks = voice_idx_dict.keys ();
241 if re.match('[1-9]', k):
242 m = alphabet[string.atoi(k)]
245 if k == 'default' and len (voice_idx_dict) > 1:
247 if len ( slyrics [voice_idx_dict[k]] ):
248 outf.write ("\n \\addlyrics")
249 outf.write ("\n\t\\context Staff=\"%s\"\n\t{\n" %k )
251 outf.write ("\t \\voicedefault\n")
252 outf.write ("\t \\voice%s " % m)
253 outf.write ("\n\t}\n")
254 if len ( slyrics [voice_idx_dict[k]] ):
255 outf.write ("\n\t\\context Lyrics=\"%s\" \n\t<\t" % k)
256 if re.match('[1-9]',k):
257 m = alphabet[string.atoi(k)]
260 for i in range (len(slyrics[voice_idx_dict[k]])):
262 outf.write("\n\t { \\words%sV%s }" % ( m, l) )
263 outf.write ( "\n\t>\n" )
265 outf.write ("\n\t\\paper {\n")
267 outf.write ("\t \\translator \n\t {\n")
268 outf.write ("\t\t\\StaffContext\n")
269 # outf.write ("\t\t\\consists Staff_margin_engraver\n")
270 outf.write ("\t }\n")
271 outf.write ("\t}\n\t\\midi {%s}\n}\n" % midi_specs)
275 def set_default_length (s):
276 global length_specified
277 m = re.search ('1/([0-9]+)', s)
279 __main__.default_len = string.atoi ( m.group (1))
282 def set_default_len_from_time_sig (s):
283 m = re.search ('([0-9]+)/([0-9]+)', s)
285 n = string.atoi (m.group (1))
286 d = string.atoi (m.group (2))
287 if (n * 1.0 )/(d * 1.0) < 0.75:
288 __main__.default_len = 16
290 __main__.default_len = 8
299 sys.stderr.write ("can't open file: `%s'\n" % f)
303 sys.stderr.write ("gulped empty file: `%s'\n" % f)
308 # pitch manipulation. Tuples are (name, alteration).
309 # 0 is (central) C. Alteration -1 is a flat, Alteration +1 is a sharp
310 # pitch in semitones.
311 def semitone_pitch (tup):
321 p = p + t* 2 + tup[1]
324 def fifth_above_pitch (tup):
325 (n, a) = (tup[0] + 4, tup[1])
327 difference = 7 - (semitone_pitch ((n,a)) - semitone_pitch (tup))
338 (t,a) = fifth_above_pitch (p)
339 if semitone_pitch((t,a)) % 12 == 0:
351 (t,a) = quart_above_pitch (p)
352 if semitone_pitch((t,a)) % 12 == 0:
358 def quart_above_pitch (tup):
359 (n, a) = (tup[0] + 3, tup[1])
361 difference = 5 - (semitone_pitch ((n,a)) - semitone_pitch (tup))
366 key_lookup = { # abc to lilypond key mode names
375 'mix' : 'mixolydian',
376 'mixolydian' : 'mixolydian',
386 if k and k[0] == '#':
389 elif k and k[0] == 'b':
393 return '%s \\major' % key
396 if key_lookup.has_key(type):
397 return("%s \\%s" % ( key, key_lookup[type]))
398 sys.stderr.write("Unknown key type `%s' ignored\n" % type)
401 def shift_key (note, acc , shift):
402 s = semitone_pitch((note, acc))
403 s = (s + shift + 12) % 12
415 key_shift = { # semitone shifts for key mode names
438 intkey = (ord (k[0]) - ord('a') + 5) % 7
442 if k and k[0] == 'b':
445 elif k and k[0] == '#':
449 if k and key_shift.has_key(k):
450 (intkey, intkeyacc) = shift_key(intkey, intkeyacc, key_shift[k])
451 keytup = (intkey, intkeyacc)
453 sharp_key_seq = sharp_keys ()
454 flat_key_seq = flat_keys ()
458 if keytup in sharp_key_seq:
460 key_count = sharp_key_seq.index (keytup)
461 accseq = map (lambda x: (4*x -1 ) % 7, range (1, key_count + 1))
463 elif keytup in flat_key_seq:
465 key_count = flat_key_seq.index (keytup)
466 accseq = map (lambda x: (3*x + 3 ) % 7, range (1, key_count + 1))
473 key_table[a] = key_table[a] + accsign
488 def try_parse_tuplet_begin (str, state):
489 if re.match ('\([2-9]', str):
492 state.parsing_tuplet = string.atoi (dig[0])
494 voices_append ("\\times %s {" % tup_lookup[dig])
497 def try_parse_group_end (str, state):
498 if str and str[0] in HSPACE:
502 def header_append (key, a):
504 if header.has_key (key):
505 s = header[key] + "\n"
509 linelen = len (v) - string.rfind(v, '\n')
510 if linelen + len (a) > 80:
514 def stuff_append (stuff, idx, a):
518 stuff [idx] = wordwrap(a, stuff[idx])
522 def voices_append(a):
523 if current_voice_idx < 0:
524 select_voice ('default', '')
525 stuff_append (voices, current_voice_idx, a)
527 def repeat_prepend():
529 if current_voice_idx < 0:
530 select_voice ('default', '')
532 repeat_state[current_voice_idx] = 't'
535 def lyrics_append(a):
536 a = re.sub ( '#', '\\#', a) # latex does not like naked #'s
537 a = re.sub ( '"', '\\"', a) # latex does not like naked "'s
538 a = '\t{ \\lyrics "' + a + '" }\n'
539 stuff_append (lyrics, current_lyric_idx, a)
541 # break lyrics to words and put "'s around words containing numbers and '"'s
545 m = re.match('[ \t]*([^ \t]*)[ \t]*(.*$)', str)
549 word = re.sub('"', '\\"', word) # escape "
550 if re.match('.*[0-9"\(]', word):
551 word = re.sub('_', ' ', word) # _ causes probs inside ""
552 ret = ret + '\"' + word + '\" '
554 ret = ret + word + ' '
559 def slyrics_append(a):
560 a = re.sub ( '_', ' _ ', a) # _ to ' _ '
561 a = re.sub ( '-', '- ', a) # split words with -
562 a = re.sub ( '\\\\- ', '-', a) # unless \-
563 a = re.sub ( '~', '_', a) # ~ to space('_')
564 a = re.sub ( '\*', '_ ', a) # * to to space
565 a = re.sub ( '#', '\\#', a) # latex does not like naked #'s
566 if re.match('.*[0-9"\(]', a): # put numbers and " and ( into quoted string
568 a = re.sub ( '$', ' ', a) # insure space between lines
569 __main__.lyric_idx = lyric_idx + 1
570 if len(slyrics[current_voice_idx]) <= lyric_idx:
571 slyrics[current_voice_idx].append(a)
573 v = slyrics[current_voice_idx][lyric_idx]
574 slyrics[current_voice_idx][lyric_idx] = wordwrap(a, slyrics[current_voice_idx][lyric_idx])
577 def try_parse_header_line (ln, state):
578 global length_specified
579 m = re.match ('^([A-Za-z]): *(.*)$', ln)
585 a = re.sub('[ \t]*$','', a) #strip trailing blanks
586 if header.has_key('title'):
588 header['title'] = header['title'] + '\\\\\\\\' + a
593 if not state.common_time:
594 state.common_time = 1
595 voices_append ("\\property Staff.TimeSignature \\override #\'style = #'C\n")
598 if not state.common_time:
599 state.common_time = 1
600 voices_append ("\\property Staff.TimeSignature \\override #\'style = #'C\n")
602 if not length_specified:
603 set_default_len_from_time_sig (a)
606 voices_append ('\\time %s' % a)
611 m = re.match ('^([^ \t]*) *(.*)$', a) # seperate clef info
613 # there may or may not be a space
614 # between the key letter and the mode
615 if key_lookup.has_key(m.group(2)[0:3]):
616 key_info = m.group(1) + m.group(2)[0:3]
617 clef_info = m.group(2)[4:]
619 key_info = m.group(1)
620 clef_info = m.group(2)
621 __main__.global_key = compute_key (key_info)# ugh.
622 voices_append ('\\key %s' % lily_key(key_info))
623 check_clef(clef_info)
625 __main__.global_key = compute_key (a)# ugh.
626 voices_append ('\\key %s \\major' % lily_key(a))
628 header ['footnotes'] = header['footnotes'] + '\\\\\\\\' + a
629 if g == 'O': # Origin
630 header ['origin'] = a
631 if g == 'X': # Reference Number
632 header ['crossRefNumber'] = a
635 if g == 'H': # History
636 header_append ('history', a)
639 if g == 'C': # Composer
640 if header.has_key('composer'):
642 header['composer'] = header['composer'] + '\\\\\\\\' + a
644 header['composer'] = a
646 header ['subtitle'] = a
647 if g == 'L': # Default note length
648 set_default_length (ln)
650 voice = re.sub (' .*$', '', a)
651 rest = re.sub ('^[^ \t]* *', '', a)
653 voices_append(state.next_bar)
655 select_voice (voice, rest)
658 if g == 'w': # vocals
665 # we use in this order specified accidental, active accidental for bar,
666 # active accidental for key
667 def pitch_to_lilypond_name (name, acc, bar_acc, key):
681 return(chr (name + ord('c')) + s)
684 def octave_to_lilypond_quotes (o):
697 while str and str[0] in DIGITS:
698 durstr = durstr + str[0]
703 n =string.atoi (durstr)
707 def duration_to_lilypond_duration (multiply_tup, defaultlen, dots):
709 # (num / den) / defaultlen < 1/base
710 while base * multiply_tup[0] < multiply_tup[1]:
713 if (multiply_tup[0] / multiply_tup[1]) == 2:
715 if (multiply_tup[0] / multiply_tup[1]) == 4:
717 return '%s%s' % ( base, '.'* dots)
722 self.next_articulation = ''
726 self.parsing_tuplet = 0
733 # return (str, num,den,dots)
734 def parse_duration (str, parser_state):
736 den = parser_state.next_den
737 parser_state.next_den = 1
739 (str, num) = parse_num (str)
745 while str[:1] == '/':
749 (str, d) =parse_num (str)
753 den = den * default_len
755 current_dots = parser_state.next_dots
756 parser_state.next_dots = 0
757 if re.match ('[ \t]*[<>]', str):
758 while str[0] in HSPACE:
762 current_dots = current_dots + 1
763 parser_state.next_den = parser_state.next_den * 2
768 parser_state.next_dots = parser_state.next_dots + 1
776 if num % multiplier == 0 and den % f == 0:
777 num = num / multiplier
779 current_dots = current_dots + d
781 return (str, num,den,current_dots)
784 def try_parse_rest (str, parser_state):
785 if not str or str[0] <> 'z' and str[0] <> 'x':
788 __main__.lyric_idx = -1
790 if parser_state.next_bar:
791 voices_append(parser_state.next_bar)
792 parser_state.next_bar = ''
800 (str, num,den,d) = parse_duration (str, parser_state)
801 voices_append ('%s%s' % (rest, duration_to_lilypond_duration ((num,den), default_len, d)))
802 if parser_state.next_articulation:
803 voices_append (parser_state.next_articulation)
804 parser_state.next_articulation = ''
817 'J' : '', # ignore slide
818 'R' : '', # ignore roll
822 def try_parse_articulation (str, state):
823 while str and artic_tbl.has_key(str[:1]):
824 state.next_articulation = state.next_articulation + artic_tbl[str[:1]]
825 if not artic_tbl[str[:1]]:
826 sys.stderr.write("Warning: ignoring `%s'\n" % str[:1] )
832 # s7m2 input doesnt care about spaces
833 if re.match('[ \t]*\(', str):
834 str = string.lstrip (str)
837 while str[:1] =='(' and str[1] not in DIGITS:
838 slur_begin = slur_begin + 1
839 state.next_articulation = state.next_articulation + '('
845 # remember accidental for rest of bar
847 def set_bar_acc(note, octave, acc, state):
850 n_oct = note + octave * 7
851 state.in_acc[n_oct] = acc
853 # get accidental set in this bar or UNDEF if not set
854 def get_bar_acc(note, octave, state):
855 n_oct = note + octave * 7
856 if state.in_acc.has_key(n_oct):
857 return(state.in_acc[n_oct])
861 def clear_bar_acc(state):
862 for k in state.in_acc.keys():
867 # WAT IS ABC EEN ONTZETTENDE PROGRAMMEERPOEP !
868 def try_parse_note (str, parser_state):
887 octave = parser_state.base_octave
888 if str[0] in "ABCDEFG":
889 str = string.lower (str[0]) + str[1:]
894 if str[0] in "abcdefg":
895 notename = (ord(str[0]) - ord('a') + 5)%7
898 return str # failed; not a note!
901 __main__.lyric_idx = -1
903 if parser_state.next_bar:
904 voices_append(parser_state.next_bar)
905 parser_state.next_bar = ''
910 while str[0] == '\'':
914 (str, num,den,current_dots) = parse_duration (str, parser_state)
917 if re.match('[ \t]*\)', str):
918 str = string.lstrip (str)
922 slur_end = slur_end + 1
927 voices_append ('%s' % ')' *slur_end )
929 bar_acc = get_bar_acc(notename, octave, parser_state)
930 pit = pitch_to_lilypond_name(notename, acc, bar_acc, global_key[notename])
931 oct = octave_to_lilypond_quotes (octave)
932 if acc != UNDEF and (acc == global_key[notename] or acc == bar_acc):
936 voices_append ("%s%s%s%s" %
938 duration_to_lilypond_duration ((num,den), default_len, current_dots)))
940 set_bar_acc(notename, octave, acc, parser_state)
941 if parser_state.next_articulation:
942 articulation = articulation + parser_state.next_articulation
943 parser_state.next_articulation = ''
945 voices_append (articulation)
947 if parser_state.parsing_tuplet:
948 parser_state.parsing_tuplet = parser_state.parsing_tuplet - 1
949 if not parser_state.parsing_tuplet:
952 voices_append ('%s' % '(' * slur_begin )
957 def junk_space (str):
958 while str and str[0] in '\t\n ':
964 def try_parse_guitar_chord (str, state):
968 if str[0] == '_' or (str[0] == '^'):
973 while str and str[0] != '"':
979 gc = re.sub('#', '\\#', gc) # escape '#'s
980 state.next_articulation = ("%c\"%s\"" % (position ,gc)) + state.next_articulation
983 def try_parse_escape (str):
984 if not str or str [0] != '\\':
989 key_table = compute_key ()
993 # |] thin-thick double bar line
994 # || thin-thin double bar line
995 # [| thick-thin double bar line
998 # :: left-right repeat
1014 '|]' : '\\bar "|."',
1015 '||' : '\\bar "||"',
1016 '[|' : '\\bar "||"',
1018 '|:' : '\\repeat volta 2 {',
1019 '::' : '} \\repeat volta 2 {',
1020 '|1' : '} \\alternative{{',
1027 warn_about = ['|:', '::', ':|', '|1', ':|2', '|2']
1028 alternative_opener = ['|1', '|2', ':|2']
1029 repeat_ender = ['::', ':|']
1030 repeat_opener = ['::', '|:']
1031 in_repeat = [''] * 8
1032 doing_alternative = [''] * 8
1035 def try_parse_bar (str,state):
1036 global in_repeat, doing_alternative, using_old
1039 if current_voice_idx < 0:
1040 select_voice ('default', '')
1041 # first try the longer one
1042 for trylen in [3,2,1]:
1043 if str[:trylen] and bar_dict.has_key (str[:trylen]):
1046 bs = "\\bar \"%s\"" % old_bar_dict[s]
1048 bs = "%s" % bar_dict[s]
1050 if s in alternative_opener:
1051 if not in_repeat[current_voice_idx]:
1053 bs = "\\bar \"%s\"" % old_bar_dict[s]
1055 doing_alternative[current_voice_idx] = 't'
1057 if s in repeat_ender:
1058 if not in_repeat[current_voice_idx]:
1059 sys.stderr.write("Warning: inserting repeat to beginning of notes.\n")
1061 in_repeat[current_voice_idx] = ''
1063 if doing_alternative[current_voice_idx]:
1066 bs = "\\bar \"%s\"" % old_bar_dict[s]
1069 doing_alternative[current_voice_idx] = ''
1070 in_repeat[current_voice_idx] = ''
1071 if s in repeat_opener:
1072 in_repeat[current_voice_idx] = 't'
1074 bs = "\\bar \"%s\"" % old_bar_dict[s]
1079 state.next_bar = '|\n'
1081 clear_bar_acc(state)
1083 if bs <> None or state.next_bar != '':
1084 if state.parsing_tuplet:
1085 state.parsing_tuplet =0
1086 voices_append ('} ')
1089 clear_bar_acc(state)
1092 voices_append("} }")
1096 def try_parse_tie (str):
1099 voices_append (' ~ ')
1102 def bracket_escape (str, state):
1103 m = re.match ( '^([^\]]*)] *(.*)$', str)
1107 try_parse_header_line (cmd, state)
1110 def try_parse_chord_delims (str, state):
1113 if re.match('[A-Z]:', str): # bracket escape
1114 return bracket_escape(str, state)
1116 voices_append(state.next_bar)
1122 if state.plus_chord:
1124 state.plus_chord = 0
1127 voices_append(state.next_bar)
1130 state.plus_chord = 1
1138 while str[:1] ==')':
1143 voices_append ("\\spanrequest \\stop \"slur\"" * end)
1147 def try_parse_grace_delims (str, state):
1150 voices_append(state.next_bar)
1153 voices_append ('\\grace { ')
1161 def try_parse_comment (str):
1164 if str[0:5] == '%MIDI':
1165 #the nobarlines option is necessary for an abc to lilypond translator for
1166 #exactly the same reason abc2midi needs it: abc requires the user to enter
1167 #the note that will be printed, and MIDI and lilypond expect entry of the
1168 #pitch that will be played.
1170 #In standard 19th century musical notation, the algorithm for translating
1171 #between printed note and pitch involves using the barlines to determine
1172 #the scope of the accidentals.
1174 #Since ABC is frequently used for music in styles that do not use this
1175 #convention, such as most music written before 1700, or ethnic music in
1176 #non-western scales, it is necessary to be able to tell a translator that
1177 #the barlines should not affect its interpretation of the pitch.
1178 if (string.find(str,'nobarlines') > 0):
1180 elif str[0:3] == '%LY':
1181 p = string.find(str, 'voices')
1183 voices_append(str[p+7:])
1185 p = string.find(str, 'slyrics')
1187 slyrics_append(str[p+8:])
1189 #write other kinds of appending if we ever need them.
1193 def parse_file (fn):
1197 select_voice('default', '')
1199 sys.stderr.write ("Line ... ")
1201 __main__.state = state_list[current_voice_idx]
1206 if not (lineno % happy_count):
1207 sys.stderr.write ('[%d]'% lineno)
1209 m = re.match ('^([^%]*)%(.*)$',ln) # add comments to current voice
1212 try_parse_comment(m.group(2))
1213 voices_append ('%% %s\n' % m.group(2))
1218 ln = try_parse_header_line (ln, state)
1220 # Try nibbling characters off until the line doesn't change.
1222 while ln != prev_ln:
1224 ln = try_parse_chord_delims (ln, state)
1225 ln = try_parse_rest (ln, state)
1226 ln = try_parse_articulation (ln,state)
1227 ln = try_parse_note (ln, state)
1228 ln = try_parse_bar (ln, state)
1229 ln = try_parse_tie (ln)
1230 ln = try_parse_escape (ln)
1231 ln = try_parse_guitar_chord (ln, state)
1232 ln = try_parse_tuplet_begin (ln, state)
1233 ln = try_parse_group_end (ln, state)
1234 ln = try_parse_grace_delims (ln, state)
1235 ln = junk_space (ln)
1238 error ("%s: %d: Huh? Don't understand\n" % (fn, lineno))
1239 left = orig_ln[0:-len (ln)]
1240 sys.stderr.write (left + '\n')
1241 sys.stderr.write (' ' * len (left) + ln + '\n')
1245 sys.stderr.write ("%s from LilyPond %s\n" % (program_name, version))
1249 Convert ABC to lilypond.
1251 Usage: abc2ly [OPTIONS]... ABC-FILE
1254 -h, --help this help
1255 -o, --output=FILE set output filename to FILE
1256 -v, --version version information
1257 -s, --strict be strict about succes.
1259 This program converts ABC music files (see
1260 http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt) To LilyPond input.
1263 def print_version ():
1264 print r"""abc2ly (GNU lilypond) %s""" % version
1268 (options, files) = getopt.getopt (sys.argv[1:], 'vo:hs', ['help','version', 'output=', 'strict'])
1274 if o== '--help' or o == '-h':
1277 elif o == '--version' or o == '-v':
1280 elif o == '--strict' or o == '-s':
1282 elif o == '--output' or o == '-o':
1290 header['tagline'] = 'Lily was here %s -- automatically converted from ABC' % version
1295 sys.stderr.write ('Parsing `%s\'...\n' % f)
1298 if not out_filename:
1299 out_filename = os.path.basename (os.path.splitext (f)[0]) + ".ly"
1300 sys.stderr.write ('lilypond output to: `%s\'...' % out_filename)
1301 outf = open (out_filename, 'w')
1303 # dump_global (outf)
1304 dump_header (outf ,header)
1309 sys.stderr.write ('\n')