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.
35 # M:none doesn't crash lily.
39 # Multiple tunes in single file not supported
40 # Blank T: header lines should write score and open a new score
41 # Not all header fields supported
42 # ABC line breaks are ignored
43 # Block comments generate error and are ignored
44 # Postscript commands are ignored
45 # lyrics not resynchronized by line breaks (lyrics must fully match notes)
46 # %%LY slyrics can't be directly before a w: line.
56 program_name = 'abc2ly'
57 version = '@TOPLEVEL_VERSION@'
58 if version == '@' + 'TOPLEVEL_VERSION' + '@':
59 version = '(unknown version)' # uGUHGUHGHGUGH
74 header['footnotes'] = ''
79 repeat_state = [0] * 8
80 current_voice_idx = -1
81 current_lyric_idx = -1
87 global_key = [0] * 7 # UGH
88 names = ["One", "Two", "Three"]
90 alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
96 sys.stderr.write (msg)
104 if re.match('-8va', s) or re.match('treble8', s):
105 # treble8 is used by abctab2ps; -8va is used by barfly,
106 # and by my patch to abc2ps. If there's ever a standard
107 # about this we'll support that.
109 state.base_octave = -1
110 voices_append("\\clef \"G_8\"\n")
111 elif re.match('^treble', s):
113 if re.match ('^-8', s):
115 state.base_octave = -2
116 voices_append("\\clef \"G_8\"\n")
118 state.base_octave = 0
119 voices_append("\\clef treble\n")
120 elif re.match('^alto', s):
122 state.base_octave = -1
123 voices_append ("\\clef alto\n" )
124 elif re.match('^bass',s ):
126 state.base_octave = -2
127 voices_append ("\\clef bass\n" )
130 def select_voice (name, rol):
131 if not voice_idx_dict.has_key (name):
132 state_list.append(Parser_state())
135 voice_idx_dict[name] = len (voices) -1
136 __main__.current_voice_idx = voice_idx_dict[name]
137 __main__.state = state_list[current_voice_idx]
139 m = re.match ('^([^ \t=]*)=(.*)$', rol) # find keywork
143 a = re.match ('^("[^"]*"|[^ \t]*) *(.*)$', rol)
147 if keyword == 'clef':
149 elif keyword == "name":
150 value = re.sub ('\\\\','\\\\\\\\', value)
151 voices_append ("\\property Staff.instrument = %s\n" % value )
152 __main__.part_names = 1
153 elif keyword == "sname" or keyword == "snm":
154 voices_append ("\\property Staff.instr = %s\n" % value )
162 def dump_header (outf,hdr):
163 outf.write ('\\header {\n')
167 hdr[k] = re.sub('"', '\\"', hdr[k])
168 outf.write ('\t%s = "%s"\n'% (k,hdr[k]))
171 def dump_lyrics (outf):
173 outf.write("\n\\score\n{\n \\context Lyrics\n <\n")
174 for i in range (len (lyrics)):
175 outf.write ( lyrics [i])
177 outf.write(" >\n \\paper{}\n}\n")
179 def dump_default_bar (outf):
180 outf.write ("\n\\property Score.defaultBarType=\"empty\"\n")
183 def dump_slyrics (outf):
184 ks = voice_idx_dict.keys()
187 if re.match('[1-9]', k):
188 m = alphabet[string.atoi(k)]
191 for i in range (len(slyrics[voice_idx_dict[k]])):
193 outf.write ("\nwords%sV%s = \\lyrics {" % (m, l))
194 outf.write ("\n" + slyrics [voice_idx_dict[k]][i])
197 def dump_voices (outf):
198 global doing_alternative, in_repeat
199 ks = voice_idx_dict.keys()
202 if re.match ('[1-9]', k):
203 m = alphabet[string.atoi(k)]
206 outf.write ("\nvoice%s = \\notes {" % m)
207 dump_default_bar(outf)
208 if repeat_state[voice_idx_dict[k]]:
209 outf.write("\n\\repeat volta 2 {")
210 outf.write ("\n" + voices [voice_idx_dict[k]])
212 if doing_alternative[voice_idx_dict[k]]:
214 if in_repeat[voice_idx_dict[k]]:
220 #assume that Q takes the form "Q:1/4=120"
221 #There are other possibilities, but they are deprecated
222 if string.count(a, '/') == 1:
223 array=string.split(a,'/')
226 sys.stderr.write("abc2ly: Warning, unable to translate a Q specification with a numerator of %s: %s\n" % (numerator, a))
227 array2=string.split(array[1],'=')
228 denominator=array2[0]
230 duration=str(string.atoi(denominator)/string.atoi(numerator))
231 midi_specs=string.join(["\\tempo", duration, "=", perminute])
233 sys.stderr.write("abc2ly: Warning, unable to parse Q specification: %s\n" % a)
235 def dump_score (outf):
236 outf.write (r"""\score{
240 ks = voice_idx_dict.keys ();
243 if re.match('[1-9]', k):
244 m = alphabet[string.atoi(k)]
247 if k == 'default' and len (voice_idx_dict) > 1:
249 if len ( slyrics [voice_idx_dict[k]] ):
250 outf.write ("\n \\addlyrics")
251 outf.write ("\n\t\\context Staff=\"%s\"\n\t{\n" %k )
253 outf.write ("\t \\voicedefault\n")
254 outf.write ("\t \\voice%s " % m)
255 outf.write ("\n\t}\n")
256 if len ( slyrics [voice_idx_dict[k]] ):
257 outf.write ("\n\t\\context Lyrics=\"%s\" \n\t<\t" % k)
258 if re.match('[1-9]',k):
259 m = alphabet[string.atoi(k)]
262 for i in range (len(slyrics[voice_idx_dict[k]])):
264 outf.write("\n\t { \\words%sV%s }" % ( m, l) )
265 outf.write ( "\n\t>\n" )
267 outf.write ("\n\t\\paper {\n")
269 outf.write ("\t \\translator \n\t {\n")
270 outf.write ("\t\t\\StaffContext\n")
271 # outf.write ("\t\t\\consists Staff_margin_engraver\n")
272 outf.write ("\t }\n")
273 outf.write ("\t}\n\t\\midi {%s}\n}\n" % midi_specs)
277 def set_default_length (s):
278 global length_specified
279 m = re.search ('1/([0-9]+)', s)
281 __main__.default_len = string.atoi ( m.group (1))
284 def set_default_len_from_time_sig (s):
285 m = re.search ('([0-9]+)/([0-9]+)', s)
287 n = string.atoi (m.group (1))
288 d = string.atoi (m.group (2))
289 if (n * 1.0 )/(d * 1.0) < 0.75:
290 __main__.default_len = 16
292 __main__.default_len = 8
301 sys.stderr.write ("can't open file: `%s'\n" % f)
305 sys.stderr.write ("gulped empty file: `%s'\n" % f)
310 # pitch manipulation. Tuples are (name, alteration).
311 # 0 is (central) C. Alteration -1 is a flat, Alteration +1 is a sharp
312 # pitch in semitones.
313 def semitone_pitch (tup):
323 p = p + t* 2 + tup[1]
326 def fifth_above_pitch (tup):
327 (n, a) = (tup[0] + 4, tup[1])
329 difference = 7 - (semitone_pitch ((n,a)) - semitone_pitch (tup))
340 (t,a) = fifth_above_pitch (p)
341 if semitone_pitch((t,a)) % 12 == 0:
353 (t,a) = quart_above_pitch (p)
354 if semitone_pitch((t,a)) % 12 == 0:
360 def quart_above_pitch (tup):
361 (n, a) = (tup[0] + 3, tup[1])
363 difference = 5 - (semitone_pitch ((n,a)) - semitone_pitch (tup))
368 key_lookup = { # abc to lilypond key mode names
377 'mix' : 'mixolydian',
378 'mixolydian' : 'mixolydian',
388 if k and k[0] == '#':
391 elif k and k[0] == 'b':
395 return '%s \\major' % key
398 if key_lookup.has_key(type):
399 return("%s \\%s" % ( key, key_lookup[type]))
400 sys.stderr.write("Unknown key type `%s' ignored\n" % type)
403 def shift_key (note, acc , shift):
404 s = semitone_pitch((note, acc))
405 s = (s + shift + 12) % 12
417 key_shift = { # semitone shifts for key mode names
440 intkey = (ord (k[0]) - ord('a') + 5) % 7
444 if k and k[0] == 'b':
447 elif k and k[0] == '#':
451 if k and key_shift.has_key(k):
452 (intkey, intkeyacc) = shift_key(intkey, intkeyacc, key_shift[k])
453 keytup = (intkey, intkeyacc)
455 sharp_key_seq = sharp_keys ()
456 flat_key_seq = flat_keys ()
460 if keytup in sharp_key_seq:
462 key_count = sharp_key_seq.index (keytup)
463 accseq = map (lambda x: (4*x -1 ) % 7, range (1, key_count + 1))
465 elif keytup in flat_key_seq:
467 key_count = flat_key_seq.index (keytup)
468 accseq = map (lambda x: (3*x + 3 ) % 7, range (1, key_count + 1))
475 key_table[a] = key_table[a] + accsign
490 def try_parse_tuplet_begin (str, state):
491 if re.match ('\([2-9]', str):
494 prev_tuplet_state = state.parsing_tuplet
495 state.parsing_tuplet = string.atoi (dig[0])
496 if prev_tuplet_state:
498 voices_append ("\\times %s {" % tup_lookup[dig])
501 def try_parse_group_end (str, state):
502 if str and str[0] in HSPACE:
506 def header_append (key, a):
508 if header.has_key (key):
509 s = header[key] + "\n"
513 linelen = len (v) - string.rfind(v, '\n')
514 if linelen + len (a) > 80:
518 def stuff_append (stuff, idx, a):
522 stuff [idx] = wordwrap(a, stuff[idx])
526 def voices_append(a):
527 if current_voice_idx < 0:
528 select_voice ('default', '')
529 stuff_append (voices, current_voice_idx, a)
531 def repeat_prepend():
533 if current_voice_idx < 0:
534 select_voice ('default', '')
536 repeat_state[current_voice_idx] = 't'
539 def lyrics_append(a):
540 a = re.sub ( '#', '\\#', a) # latex does not like naked #'s
541 a = re.sub ( '"', '\\"', a) # latex does not like naked "'s
542 a = '\t{ \\lyrics "' + a + '" }\n'
543 stuff_append (lyrics, current_lyric_idx, a)
545 # break lyrics to words and put "'s around words containing numbers and '"'s
549 m = re.match('[ \t]*([^ \t]*)[ \t]*(.*$)', str)
553 word = re.sub('"', '\\"', word) # escape "
554 if re.match('.*[0-9"\(]', word):
555 word = re.sub('_', ' ', word) # _ causes probs inside ""
556 ret = ret + '\"' + word + '\" '
558 ret = ret + word + ' '
563 def slyrics_append(a):
564 a = re.sub ( '_', ' _ ', a) # _ to ' _ '
565 a = re.sub ( '-', '- ', a) # split words with -
566 a = re.sub ( '\\\\- ', '-', a) # unless \-
567 a = re.sub ( '~', '_', a) # ~ to space('_')
568 a = re.sub ( '\*', '_ ', a) # * to to space
569 a = re.sub ( '#', '\\#', a) # latex does not like naked #'s
570 if re.match('.*[0-9"\(]', a): # put numbers and " and ( into quoted string
572 a = re.sub ( '$', ' ', a) # insure space between lines
573 __main__.lyric_idx = lyric_idx + 1
574 if len(slyrics[current_voice_idx]) <= lyric_idx:
575 slyrics[current_voice_idx].append(a)
577 v = slyrics[current_voice_idx][lyric_idx]
578 slyrics[current_voice_idx][lyric_idx] = wordwrap(a, slyrics[current_voice_idx][lyric_idx])
581 def try_parse_header_line (ln, state):
582 global length_specified
583 m = re.match ('^([A-Za-z]): *(.*)$', ln)
589 a = re.sub('[ \t]*$','', a) #strip trailing blanks
590 if header.has_key('title'):
592 if len(header['title']):
593 header['title'] = header['title'] + '\\\\\\\\' + a
595 header['subtitle'] = a
600 if not state.common_time:
601 state.common_time = 1
602 voices_append ("\\property Staff.TimeSignature \\override #\'style = #'C\n")
605 if not state.common_time:
606 state.common_time = 1
607 voices_append ("\\property Staff.TimeSignature \\override #\'style = #'C\n")
609 if not length_specified:
610 set_default_len_from_time_sig (a)
614 voices_append ('\\time %s' % a)
619 m = re.match ('^([^ \t]*) *(.*)$', a) # seperate clef info
621 # there may or may not be a space
622 # between the key letter and the mode
623 if key_lookup.has_key(m.group(2)[0:3]):
624 key_info = m.group(1) + m.group(2)[0:3]
625 clef_info = m.group(2)[4:]
627 key_info = m.group(1)
628 clef_info = m.group(2)
629 __main__.global_key = compute_key (key_info)# ugh.
630 voices_append ('\\key %s' % lily_key(key_info))
631 check_clef(clef_info)
633 __main__.global_key = compute_key (a)# ugh.
634 voices_append ('\\key %s \\major' % lily_key(a))
636 header ['footnotes'] = header['footnotes'] + '\\\\\\\\' + a
637 if g == 'O': # Origin
638 header ['origin'] = a
639 if g == 'X': # Reference Number
640 header ['crossRefNumber'] = a
643 if g == 'H': # History
644 header_append ('history', a)
647 if g == 'C': # Composer
648 if header.has_key('composer'):
650 header['composer'] = header['composer'] + '\\\\\\\\' + a
652 header['composer'] = a
654 header ['subtitle'] = a
655 if g == 'L': # Default note length
656 set_default_length (ln)
658 voice = re.sub (' .*$', '', a)
659 rest = re.sub ('^[^ \t]* *', '', a)
661 voices_append(state.next_bar)
663 select_voice (voice, rest)
666 if g == 'w': # vocals
673 # we use in this order specified accidental, active accidental for bar,
674 # active accidental for key
675 def pitch_to_lilypond_name (name, acc, bar_acc, key):
689 return(chr (name + ord('c')) + s)
692 def octave_to_lilypond_quotes (o):
705 while str and str[0] in DIGITS:
706 durstr = durstr + str[0]
711 n =string.atoi (durstr)
715 def duration_to_lilypond_duration (multiply_tup, defaultlen, dots):
717 # (num / den) / defaultlen < 1/base
718 while base * multiply_tup[0] < multiply_tup[1]:
721 if (multiply_tup[0] / multiply_tup[1]) == 2:
723 if (multiply_tup[0] / multiply_tup[1]) == 3:
726 if (multiply_tup[0] / multiply_tup[1]) == 4:
728 return '%s%s' % ( base, '.'* dots)
733 self.next_articulation = ''
737 self.parsing_tuplet = 0
744 # return (str, num,den,dots)
745 def parse_duration (str, parser_state):
747 den = parser_state.next_den
748 parser_state.next_den = 1
750 (str, num) = parse_num (str)
756 while str[:1] == '/':
760 (str, d) =parse_num (str)
764 den = den * default_len
766 current_dots = parser_state.next_dots
767 parser_state.next_dots = 0
768 if re.match ('[ \t]*[<>]', str):
769 while str[0] in HSPACE:
773 current_dots = current_dots + 1
774 parser_state.next_den = parser_state.next_den * 2
779 parser_state.next_dots = parser_state.next_dots + 1
787 if num % multiplier == 0 and den % f == 0:
788 num = num / multiplier
790 current_dots = current_dots + d
792 return (str, num,den,current_dots)
795 def try_parse_rest (str, parser_state):
796 if not str or str[0] <> 'z' and str[0] <> 'x':
799 __main__.lyric_idx = -1
801 if parser_state.next_bar:
802 voices_append(parser_state.next_bar)
803 parser_state.next_bar = ''
811 (str, num,den,d) = parse_duration (str, parser_state)
812 voices_append ('%s%s' % (rest, duration_to_lilypond_duration ((num,den), default_len, d)))
813 if parser_state.next_articulation:
814 voices_append (parser_state.next_articulation)
815 parser_state.next_articulation = ''
828 'J' : '', # ignore slide
829 'R' : '', # ignore roll
833 def try_parse_articulation (str, state):
834 while str and artic_tbl.has_key(str[:1]):
835 state.next_articulation = state.next_articulation + artic_tbl[str[:1]]
836 if not artic_tbl[str[:1]]:
837 sys.stderr.write("Warning: ignoring `%s'\n" % str[:1] )
843 # s7m2 input doesnt care about spaces
844 if re.match('[ \t]*\(', str):
845 str = string.lstrip (str)
848 while str[:1] =='(' and str[1] not in DIGITS:
849 slur_begin = slur_begin + 1
850 state.next_articulation = state.next_articulation + '('
856 # remember accidental for rest of bar
858 def set_bar_acc(note, octave, acc, state):
861 n_oct = note + octave * 7
862 state.in_acc[n_oct] = acc
864 # get accidental set in this bar or UNDEF if not set
865 def get_bar_acc(note, octave, state):
866 n_oct = note + octave * 7
867 if state.in_acc.has_key(n_oct):
868 return(state.in_acc[n_oct])
872 def clear_bar_acc(state):
873 for k in state.in_acc.keys():
878 # WAT IS ABC EEN ONTZETTENDE PROGRAMMEERPOEP !
879 def try_parse_note (str, parser_state):
898 octave = parser_state.base_octave
899 if str[0] in "ABCDEFG":
900 str = string.lower (str[0]) + str[1:]
905 if str[0] in "abcdefg":
906 notename = (ord(str[0]) - ord('a') + 5)%7
909 return str # failed; not a note!
912 __main__.lyric_idx = -1
914 if parser_state.next_bar:
915 voices_append(parser_state.next_bar)
916 parser_state.next_bar = ''
921 while str[0] == '\'':
925 (str, num,den,current_dots) = parse_duration (str, parser_state)
928 if re.match('[ \t]*\)', str):
929 str = string.lstrip (str)
933 slur_end = slur_end + 1
938 voices_append ('%s' % ')' *slur_end )
940 bar_acc = get_bar_acc(notename, octave, parser_state)
941 pit = pitch_to_lilypond_name(notename, acc, bar_acc, global_key[notename])
942 oct = octave_to_lilypond_quotes (octave)
943 if acc != UNDEF and (acc == global_key[notename] or acc == bar_acc):
947 voices_append ("%s%s%s%s" %
949 duration_to_lilypond_duration ((num,den), default_len, current_dots)))
951 set_bar_acc(notename, octave, acc, parser_state)
952 if parser_state.next_articulation:
953 articulation = articulation + parser_state.next_articulation
954 parser_state.next_articulation = ''
956 voices_append (articulation)
958 if parser_state.parsing_tuplet:
959 parser_state.parsing_tuplet = parser_state.parsing_tuplet - 1
960 if not parser_state.parsing_tuplet:
963 voices_append ('%s' % '(' * slur_begin )
968 def junk_space (str):
969 while str and str[0] in '\t\n ':
975 def try_parse_guitar_chord (str, state):
979 if str[0] == '_' or (str[0] == '^'):
984 while str and str[0] != '"':
990 gc = re.sub('#', '\\#', gc) # escape '#'s
991 state.next_articulation = ("%c\"%s\"" % (position ,gc)) + state.next_articulation
994 def try_parse_escape (str):
995 if not str or str [0] != '\\':
1000 key_table = compute_key ()
1004 # |] thin-thick double bar line
1005 # || thin-thin double bar line
1006 # [| thick-thin double bar line
1009 # :: left-right repeat
1025 '|]' : '\\bar "|."',
1026 '||' : '\\bar "||"',
1027 '[|' : '\\bar "||"',
1029 '|:' : '\\repeat volta 2 {',
1030 '::' : '} \\repeat volta 2 {',
1031 '|1' : '} \\alternative{{',
1038 warn_about = ['|:', '::', ':|', '|1', ':|2', '|2']
1039 alternative_opener = ['|1', '|2', ':|2']
1040 repeat_ender = ['::', ':|']
1041 repeat_opener = ['::', '|:']
1042 in_repeat = [''] * 8
1043 doing_alternative = [''] * 8
1046 def try_parse_bar (str,state):
1047 global in_repeat, doing_alternative, using_old
1050 if current_voice_idx < 0:
1051 select_voice ('default', '')
1052 # first try the longer one
1053 for trylen in [3,2,1]:
1054 if str[:trylen] and bar_dict.has_key (str[:trylen]):
1057 bs = "\\bar \"%s\"" % old_bar_dict[s]
1059 bs = "%s" % bar_dict[s]
1061 if s in alternative_opener:
1062 if not in_repeat[current_voice_idx]:
1064 bs = "\\bar \"%s\"" % old_bar_dict[s]
1066 doing_alternative[current_voice_idx] = 't'
1068 if s in repeat_ender:
1069 if not in_repeat[current_voice_idx]:
1070 sys.stderr.write("Warning: inserting repeat to beginning of notes.\n")
1072 in_repeat[current_voice_idx] = ''
1074 if doing_alternative[current_voice_idx]:
1077 bs = "\\bar \"%s\"" % old_bar_dict[s]
1080 doing_alternative[current_voice_idx] = ''
1081 in_repeat[current_voice_idx] = ''
1082 if s in repeat_opener:
1083 in_repeat[current_voice_idx] = 't'
1085 bs = "\\bar \"%s\"" % old_bar_dict[s]
1090 state.next_bar = '|\n'
1092 clear_bar_acc(state)
1094 if bs <> None or state.next_bar != '':
1095 if state.parsing_tuplet:
1096 state.parsing_tuplet =0
1097 voices_append ('} ')
1100 clear_bar_acc(state)
1103 voices_append("} }")
1107 def try_parse_tie (str):
1110 voices_append (' ~ ')
1113 def bracket_escape (str, state):
1114 m = re.match ( '^([^\]]*)] *(.*)$', str)
1118 try_parse_header_line (cmd, state)
1121 def try_parse_chord_delims (str, state):
1124 if re.match('[A-Z]:', str): # bracket escape
1125 return bracket_escape(str, state)
1127 voices_append(state.next_bar)
1133 if state.plus_chord:
1135 state.plus_chord = 0
1138 voices_append(state.next_bar)
1141 state.plus_chord = 1
1149 while str[:1] ==')':
1154 voices_append ("\\spanrequest \\stop \"slur\"" * end)
1158 def try_parse_grace_delims (str, state):
1161 voices_append(state.next_bar)
1164 voices_append ('\\grace { ')
1172 def try_parse_comment (str):
1175 if str[0:5] == '%MIDI':
1176 #the nobarlines option is necessary for an abc to lilypond translator for
1177 #exactly the same reason abc2midi needs it: abc requires the user to enter
1178 #the note that will be printed, and MIDI and lilypond expect entry of the
1179 #pitch that will be played.
1181 #In standard 19th century musical notation, the algorithm for translating
1182 #between printed note and pitch involves using the barlines to determine
1183 #the scope of the accidentals.
1185 #Since ABC is frequently used for music in styles that do not use this
1186 #convention, such as most music written before 1700, or ethnic music in
1187 #non-western scales, it is necessary to be able to tell a translator that
1188 #the barlines should not affect its interpretation of the pitch.
1189 if (string.find(str,'nobarlines') > 0):
1191 elif str[0:3] == '%LY':
1192 p = string.find(str, 'voices')
1194 voices_append(str[p+7:])
1196 p = string.find(str, 'slyrics')
1198 slyrics_append(str[p+8:])
1200 #write other kinds of appending if we ever need them.
1204 def parse_file (fn):
1208 select_voice('default', '')
1210 sys.stderr.write ("Line ... ")
1212 __main__.state = state_list[current_voice_idx]
1217 if not (lineno % happy_count):
1218 sys.stderr.write ('[%d]'% lineno)
1220 m = re.match ('^([^%]*)%(.*)$',ln) # add comments to current voice
1223 try_parse_comment(m.group(2))
1224 voices_append ('%% %s\n' % m.group(2))
1229 ln = try_parse_header_line (ln, state)
1231 # Try nibbling characters off until the line doesn't change.
1233 while ln != prev_ln:
1235 ln = try_parse_chord_delims (ln, state)
1236 ln = try_parse_rest (ln, state)
1237 ln = try_parse_articulation (ln,state)
1238 ln = try_parse_note (ln, state)
1239 ln = try_parse_bar (ln, state)
1240 ln = try_parse_tie (ln)
1241 ln = try_parse_escape (ln)
1242 ln = try_parse_guitar_chord (ln, state)
1243 ln = try_parse_tuplet_begin (ln, state)
1244 ln = try_parse_group_end (ln, state)
1245 ln = try_parse_grace_delims (ln, state)
1246 ln = junk_space (ln)
1249 error ("%s: %d: Huh? Don't understand\n" % (fn, lineno))
1250 left = orig_ln[0:-len (ln)]
1251 sys.stderr.write (left + '\n')
1252 sys.stderr.write (' ' * len (left) + ln + '\n')
1256 sys.stderr.write ("%s from LilyPond %s\n" % (program_name, version))
1260 Convert ABC to lilypond.
1262 Usage: abc2ly [OPTIONS]... ABC-FILE
1265 -h, --help this help
1266 -o, --output=FILE set output filename to FILE
1267 -v, --version version information
1268 -s, --strict be strict about succes.
1270 This program converts ABC music files (see
1271 http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt) To LilyPond input.
1274 Report bugs to bug-lilypond@gnu.org
1276 Written by Han-Wen Nienhuys <hanwen@cs.uu.nl>, Laura Conrad
1277 <lconrad@laymusic.org>, Roy Rankin <Roy.Rankin@@alcatel.com.au>
1280 def print_version ():
1281 print r"""abc2ly (GNU lilypond) %s""" % version
1285 (options, files) = getopt.getopt (sys.argv[1:], 'vo:hs', ['help','version', 'output=', 'strict'])
1291 if o== '--help' or o == '-h':
1294 elif o == '--version' or o == '-v':
1297 elif o == '--strict' or o == '-s':
1299 elif o == '--output' or o == '-o':
1307 header['tagline'] = 'Lily was here %s -- automatically converted from ABC' % version
1312 sys.stderr.write ('Parsing `%s\'...\n' % f)
1315 if not out_filename:
1316 out_filename = os.path.basename (os.path.splitext (f)[0]) + ".ly"
1317 sys.stderr.write ('lilypond output to: `%s\'...' % out_filename)
1318 outf = open (out_filename, 'w')
1320 # dump_global (outf)
1321 dump_header (outf ,header)
1326 sys.stderr.write ('\n')