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.
53 # Convert to new chord styles.
59 program_name = 'abc2ly'
60 version = '@TOPLEVEL_VERSION@'
61 if version == '@' + 'TOPLEVEL_VERSION' + '@':
62 version = '(unknown version)' # uGUHGUHGHGUGH
77 header['footnotes'] = ''
82 repeat_state = [0] * 8
83 current_voice_idx = -1
84 current_lyric_idx = -1
90 global_key = [0] * 7 # UGH
91 names = ["One", "Two", "Three"]
93 alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
99 sys.stderr.write (msg)
107 if re.match('-8va', s) or re.match('treble8', s):
108 # treble8 is used by abctab2ps; -8va is used by barfly,
109 # and by my patch to abc2ps. If there's ever a standard
110 # about this we'll support that.
112 state.base_octave = -1
113 voices_append("\\clef \"G_8\"\n")
114 elif re.match('^treble', s):
116 if re.match ('^-8', s):
118 state.base_octave = -2
119 voices_append("\\clef \"G_8\"\n")
121 state.base_octave = 0
122 voices_append("\\clef treble\n")
123 elif re.match('^alto', s):
125 state.base_octave = -1
126 voices_append ("\\clef alto\n" )
127 elif re.match('^bass',s ):
129 state.base_octave = -2
130 voices_append ("\\clef bass\n" )
133 def select_voice (name, rol):
134 if not voice_idx_dict.has_key (name):
135 state_list.append(Parser_state())
138 voice_idx_dict[name] = len (voices) -1
139 __main__.current_voice_idx = voice_idx_dict[name]
140 __main__.state = state_list[current_voice_idx]
142 m = re.match ('^([^ \t=]*)=(.*)$', rol) # find keywork
146 a = re.match ('^("[^"]*"|[^ \t]*) *(.*)$', rol)
150 if keyword == 'clef':
152 elif keyword == "name":
153 value = re.sub ('\\\\','\\\\\\\\', value)
154 voices_append ("\\property Staff.instrument = %s\n" % value )
155 __main__.part_names = 1
156 elif keyword == "sname" or keyword == "snm":
157 voices_append ("\\property Staff.instr = %s\n" % value )
165 def dump_header (outf,hdr):
166 outf.write ('\\header {\n')
170 hdr[k] = re.sub('"', '\\"', hdr[k])
171 outf.write ('\t%s = "%s"\n'% (k,hdr[k]))
174 def dump_lyrics (outf):
176 outf.write("\n\\score\n{\n \\context Lyrics\n <\n")
177 for i in range (len (lyrics)):
178 outf.write ( lyrics [i])
180 outf.write(" >\n \\paper{}\n}\n")
182 def dump_default_bar (outf):
183 outf.write ("\n\\property Score.defaultBarType=\"empty\"\n")
186 def dump_slyrics (outf):
187 ks = voice_idx_dict.keys()
190 if re.match('[1-9]', k):
191 m = alphabet[string.atoi(k)]
194 for i in range (len(slyrics[voice_idx_dict[k]])):
196 outf.write ("\nwords%sV%s = \\lyrics {" % (m, l))
197 outf.write ("\n" + slyrics [voice_idx_dict[k]][i])
200 def dump_voices (outf):
201 global doing_alternative, in_repeat
202 ks = voice_idx_dict.keys()
205 if re.match ('[1-9]', k):
206 m = alphabet[string.atoi(k)]
209 outf.write ("\nvoice%s = \\notes {" % m)
210 dump_default_bar(outf)
211 if repeat_state[voice_idx_dict[k]]:
212 outf.write("\n\\repeat volta 2 {")
213 outf.write ("\n" + voices [voice_idx_dict[k]])
215 if doing_alternative[voice_idx_dict[k]]:
217 if in_repeat[voice_idx_dict[k]]:
223 #assume that Q takes the form "Q:1/4=120"
224 #There are other possibilities, but they are deprecated
225 if string.count(a, '/') == 1:
226 array=string.split(a,'/')
229 sys.stderr.write("abc2ly: Warning, unable to translate a Q specification with a numerator of %s: %s\n" % (numerator, a))
230 array2=string.split(array[1],'=')
231 denominator=array2[0]
233 duration=str(string.atoi(denominator)/string.atoi(numerator))
234 midi_specs=string.join(["\\tempo", duration, "=", perminute])
236 sys.stderr.write("abc2ly: Warning, unable to parse Q specification: %s\n" % a)
238 def dump_score (outf):
239 outf.write (r"""\score{
243 ks = voice_idx_dict.keys ();
246 if re.match('[1-9]', k):
247 m = alphabet[string.atoi(k)]
250 if k == 'default' and len (voice_idx_dict) > 1:
252 if len ( slyrics [voice_idx_dict[k]] ):
253 outf.write ("\n \\addlyrics")
254 outf.write ("\n\t\\context Staff=\"%s\"\n\t{\n" %k )
256 outf.write ("\t \\voicedefault\n")
257 outf.write ("\t \\voice%s " % m)
258 outf.write ("\n\t}\n")
259 if len ( slyrics [voice_idx_dict[k]] ):
260 outf.write ("\n\t\\context Lyrics=\"%s\" \n\t<\t" % k)
261 if re.match('[1-9]',k):
262 m = alphabet[string.atoi(k)]
265 for i in range (len(slyrics[voice_idx_dict[k]])):
267 outf.write("\n\t { \\words%sV%s }" % ( m, l) )
268 outf.write ( "\n\t>\n" )
270 outf.write ("\n\t\\paper {\n")
272 outf.write ("\t \\translator \n\t {\n")
273 outf.write ("\t\t\\StaffContext\n")
274 # outf.write ("\t\t\\consists Staff_margin_engraver\n")
275 outf.write ("\t }\n")
276 outf.write ("\t}\n\t\\midi {%s}\n}\n" % midi_specs)
280 def set_default_length (s):
281 global length_specified
282 m = re.search ('1/([0-9]+)', s)
284 __main__.default_len = string.atoi ( m.group (1))
287 def set_default_len_from_time_sig (s):
288 m = re.search ('([0-9]+)/([0-9]+)', s)
290 n = string.atoi (m.group (1))
291 d = string.atoi (m.group (2))
292 if (n * 1.0 )/(d * 1.0) < 0.75:
293 __main__.default_len = 16
295 __main__.default_len = 8
304 sys.stderr.write ("can't open file: `%s'\n" % f)
308 sys.stderr.write ("gulped empty file: `%s'\n" % f)
313 # pitch manipulation. Tuples are (name, alteration).
314 # 0 is (central) C. Alteration -1 is a flat, Alteration +1 is a sharp
315 # pitch in semitones.
316 def semitone_pitch (tup):
326 p = p + t* 2 + tup[1]
329 def fifth_above_pitch (tup):
330 (n, a) = (tup[0] + 4, tup[1])
332 difference = 7 - (semitone_pitch ((n,a)) - semitone_pitch (tup))
343 (t,a) = fifth_above_pitch (p)
344 if semitone_pitch((t,a)) % 12 == 0:
356 (t,a) = quart_above_pitch (p)
357 if semitone_pitch((t,a)) % 12 == 0:
363 def quart_above_pitch (tup):
364 (n, a) = (tup[0] + 3, tup[1])
366 difference = 5 - (semitone_pitch ((n,a)) - semitone_pitch (tup))
371 key_lookup = { # abc to lilypond key mode names
380 'mix' : 'mixolydian',
381 'mixolydian' : 'mixolydian',
391 if k and k[0] == '#':
394 elif k and k[0] == 'b':
398 return '%s \\major' % key
401 if key_lookup.has_key(type):
402 return("%s \\%s" % ( key, key_lookup[type]))
403 sys.stderr.write("Unknown key type `%s' ignored\n" % type)
406 def shift_key (note, acc , shift):
407 s = semitone_pitch((note, acc))
408 s = (s + shift + 12) % 12
420 key_shift = { # semitone shifts for key mode names
443 intkey = (ord (k[0]) - ord('a') + 5) % 7
447 if k and k[0] == 'b':
450 elif k and k[0] == '#':
454 if k and key_shift.has_key(k):
455 (intkey, intkeyacc) = shift_key(intkey, intkeyacc, key_shift[k])
456 keytup = (intkey, intkeyacc)
458 sharp_key_seq = sharp_keys ()
459 flat_key_seq = flat_keys ()
463 if keytup in sharp_key_seq:
465 key_count = sharp_key_seq.index (keytup)
466 accseq = map (lambda x: (4*x -1 ) % 7, range (1, key_count + 1))
468 elif keytup in flat_key_seq:
470 key_count = flat_key_seq.index (keytup)
471 accseq = map (lambda x: (3*x + 3 ) % 7, range (1, key_count + 1))
478 key_table[a] = key_table[a] + accsign
493 def try_parse_tuplet_begin (str, state):
494 if re.match ('\([2-9]', str):
497 prev_tuplet_state = state.parsing_tuplet
498 state.parsing_tuplet = string.atoi (dig[0])
499 if prev_tuplet_state:
501 voices_append ("\\times %s {" % tup_lookup[dig])
504 def try_parse_group_end (str, state):
505 if str and str[0] in HSPACE:
509 def header_append (key, a):
511 if header.has_key (key):
512 s = header[key] + "\n"
516 linelen = len (v) - string.rfind(v, '\n')
517 if linelen + len (a) > 80:
521 def stuff_append (stuff, idx, a):
525 stuff [idx] = wordwrap(a, stuff[idx])
529 def voices_append(a):
530 if current_voice_idx < 0:
531 select_voice ('default', '')
532 stuff_append (voices, current_voice_idx, a)
534 def repeat_prepend():
536 if current_voice_idx < 0:
537 select_voice ('default', '')
539 repeat_state[current_voice_idx] = 't'
542 def lyrics_append(a):
543 a = re.sub ( '#', '\\#', a) # latex does not like naked #'s
544 a = re.sub ( '"', '\\"', a) # latex does not like naked "'s
545 a = '\t{ \\lyrics "' + a + '" }\n'
546 stuff_append (lyrics, current_lyric_idx, a)
548 # break lyrics to words and put "'s around words containing numbers and '"'s
552 m = re.match('[ \t]*([^ \t]*)[ \t]*(.*$)', str)
556 word = re.sub('"', '\\"', word) # escape "
557 if re.match('.*[0-9"\(]', word):
558 word = re.sub('_', ' ', word) # _ causes probs inside ""
559 ret = ret + '\"' + word + '\" '
561 ret = ret + word + ' '
566 def slyrics_append(a):
567 a = re.sub ( '_', ' _ ', a) # _ to ' _ '
568 a = re.sub ( '-', '- ', a) # split words with -
569 a = re.sub ( '\\\\- ', '-', a) # unless \-
570 a = re.sub ( '~', '_', a) # ~ to space('_')
571 a = re.sub ( '\*', '_ ', a) # * to to space
572 a = re.sub ( '#', '\\#', a) # latex does not like naked #'s
573 if re.match('.*[0-9"\(]', a): # put numbers and " and ( into quoted string
575 a = re.sub ( '$', ' ', a) # insure space between lines
576 __main__.lyric_idx = lyric_idx + 1
577 if len(slyrics[current_voice_idx]) <= lyric_idx:
578 slyrics[current_voice_idx].append(a)
580 v = slyrics[current_voice_idx][lyric_idx]
581 slyrics[current_voice_idx][lyric_idx] = wordwrap(a, slyrics[current_voice_idx][lyric_idx])
584 def try_parse_header_line (ln, state):
585 global length_specified
586 m = re.match ('^([A-Za-z]): *(.*)$', ln)
592 a = re.sub('[ \t]*$','', a) #strip trailing blanks
593 if header.has_key('title'):
595 if len(header['title']):
596 header['title'] = header['title'] + '\\\\\\\\' + a
598 header['subtitle'] = a
603 if not state.common_time:
604 state.common_time = 1
605 voices_append ("\\property Staff.TimeSignature \\override #\'style = #'C\n")
608 if not state.common_time:
609 state.common_time = 1
610 voices_append ("\\property Staff.TimeSignature \\override #\'style = #'C\n")
612 if not length_specified:
613 set_default_len_from_time_sig (a)
617 voices_append ('\\time %s' % a)
622 m = re.match ('^([^ \t]*) *(.*)$', a) # seperate clef info
624 # there may or may not be a space
625 # between the key letter and the mode
626 if key_lookup.has_key(m.group(2)[0:3]):
627 key_info = m.group(1) + m.group(2)[0:3]
628 clef_info = m.group(2)[4:]
630 key_info = m.group(1)
631 clef_info = m.group(2)
632 __main__.global_key = compute_key (key_info)# ugh.
633 voices_append ('\\key %s' % lily_key(key_info))
634 check_clef(clef_info)
636 __main__.global_key = compute_key (a)# ugh.
637 voices_append ('\\key %s \\major' % lily_key(a))
639 header ['footnotes'] = header['footnotes'] + '\\\\\\\\' + a
640 if g == 'O': # Origin
641 header ['origin'] = a
642 if g == 'X': # Reference Number
643 header ['crossRefNumber'] = a
646 if g == 'H': # History
647 header_append ('history', a)
650 if g == 'C': # Composer
651 if header.has_key('composer'):
653 header['composer'] = header['composer'] + '\\\\\\\\' + a
655 header['composer'] = a
657 header ['subtitle'] = a
658 if g == 'L': # Default note length
659 set_default_length (ln)
661 voice = re.sub (' .*$', '', a)
662 rest = re.sub ('^[^ \t]* *', '', a)
664 voices_append(state.next_bar)
666 select_voice (voice, rest)
669 if g == 'w': # vocals
676 # we use in this order specified accidental, active accidental for bar,
677 # active accidental for key
678 def pitch_to_lilypond_name (name, acc, bar_acc, key):
692 return(chr (name + ord('c')) + s)
695 def octave_to_lilypond_quotes (o):
708 while str and str[0] in DIGITS:
709 durstr = durstr + str[0]
714 n =string.atoi (durstr)
718 def duration_to_lilypond_duration (multiply_tup, defaultlen, dots):
720 # (num / den) / defaultlen < 1/base
721 while base * multiply_tup[0] < multiply_tup[1]:
724 if (multiply_tup[0] / multiply_tup[1]) == 2:
726 if (multiply_tup[0] / multiply_tup[1]) == 3:
729 if (multiply_tup[0] / multiply_tup[1]) == 4:
731 return '%s%s' % ( base, '.'* dots)
736 self.next_articulation = ''
740 self.parsing_tuplet = 0
747 # return (str, num,den,dots)
748 def parse_duration (str, parser_state):
750 den = parser_state.next_den
751 parser_state.next_den = 1
753 (str, num) = parse_num (str)
759 while str[:1] == '/':
763 (str, d) =parse_num (str)
767 den = den * default_len
769 current_dots = parser_state.next_dots
770 parser_state.next_dots = 0
771 if re.match ('[ \t]*[<>]', str):
772 while str[0] in HSPACE:
776 current_dots = current_dots + 1
777 parser_state.next_den = parser_state.next_den * 2
782 parser_state.next_dots = parser_state.next_dots + 1
790 if num % multiplier == 0 and den % f == 0:
791 num = num / multiplier
793 current_dots = current_dots + d
795 return (str, num,den,current_dots)
798 def try_parse_rest (str, parser_state):
799 if not str or str[0] <> 'z' and str[0] <> 'x':
802 __main__.lyric_idx = -1
804 if parser_state.next_bar:
805 voices_append(parser_state.next_bar)
806 parser_state.next_bar = ''
814 (str, num,den,d) = parse_duration (str, parser_state)
815 voices_append ('%s%s' % (rest, duration_to_lilypond_duration ((num,den), default_len, d)))
816 if parser_state.next_articulation:
817 voices_append (parser_state.next_articulation)
818 parser_state.next_articulation = ''
831 'J' : '', # ignore slide
832 'R' : '', # ignore roll
836 def try_parse_articulation (str, state):
837 while str and artic_tbl.has_key(str[:1]):
838 state.next_articulation = state.next_articulation + artic_tbl[str[:1]]
839 if not artic_tbl[str[:1]]:
840 sys.stderr.write("Warning: ignoring `%s'\n" % str[:1] )
846 # s7m2 input doesnt care about spaces
847 if re.match('[ \t]*\(', str):
848 str = string.lstrip (str)
851 while str[:1] =='(' and str[1] not in DIGITS:
852 slur_begin = slur_begin + 1
853 state.next_articulation = state.next_articulation + '('
859 # remember accidental for rest of bar
861 def set_bar_acc(note, octave, acc, state):
864 n_oct = note + octave * 7
865 state.in_acc[n_oct] = acc
867 # get accidental set in this bar or UNDEF if not set
868 def get_bar_acc(note, octave, state):
869 n_oct = note + octave * 7
870 if state.in_acc.has_key(n_oct):
871 return(state.in_acc[n_oct])
875 def clear_bar_acc(state):
876 for k in state.in_acc.keys():
881 # WAT IS ABC EEN ONTZETTENDE PROGRAMMEERPOEP !
882 def try_parse_note (str, parser_state):
901 octave = parser_state.base_octave
902 if str[0] in "ABCDEFG":
903 str = string.lower (str[0]) + str[1:]
908 if str[0] in "abcdefg":
909 notename = (ord(str[0]) - ord('a') + 5)%7
912 return str # failed; not a note!
915 __main__.lyric_idx = -1
917 if parser_state.next_bar:
918 voices_append(parser_state.next_bar)
919 parser_state.next_bar = ''
924 while str[0] == '\'':
928 (str, num,den,current_dots) = parse_duration (str, parser_state)
930 if re.match('[ \t]*\)', str):
931 str = string.lstrip (str)
935 slur_end = slur_end + 1
939 bar_acc = get_bar_acc(notename, octave, parser_state)
940 pit = pitch_to_lilypond_name(notename, acc, bar_acc, global_key[notename])
941 oct = octave_to_lilypond_quotes (octave)
942 if acc != UNDEF and (acc == global_key[notename] or acc == bar_acc):
946 voices_append ("%s%s%s%s" %
948 duration_to_lilypond_duration ((num,den), default_len, current_dots)))
950 set_bar_acc(notename, octave, acc, parser_state)
951 if parser_state.next_articulation:
952 articulation = articulation + parser_state.next_articulation
953 parser_state.next_articulation = ''
955 voices_append (articulation)
957 if parser_state.parsing_tuplet:
958 parser_state.parsing_tuplet = parser_state.parsing_tuplet - 1
959 if not parser_state.parsing_tuplet:
962 voices_append ('-(' * slur_begin )
964 voices_append ('-)' *slur_end )
970 def junk_space (str):
971 while str and str[0] in '\t\n ':
977 def try_parse_guitar_chord (str, state):
981 if str[0] == '_' or (str[0] == '^'):
986 while str and str[0] != '"':
992 gc = re.sub('#', '\\#', gc) # escape '#'s
993 state.next_articulation = ("%c\"%s\"" % (position ,gc)) + state.next_articulation
996 def try_parse_escape (str):
997 if not str or str [0] != '\\':
1002 key_table = compute_key ()
1006 # |] thin-thick double bar line
1007 # || thin-thin double bar line
1008 # [| thick-thin double bar line
1011 # :: left-right repeat
1027 '|]' : '\\bar "|."',
1028 '||' : '\\bar "||"',
1029 '[|' : '\\bar "||"',
1031 '|:' : '\\repeat volta 2 {',
1032 '::' : '} \\repeat volta 2 {',
1033 '|1' : '} \\alternative{{',
1040 warn_about = ['|:', '::', ':|', '|1', ':|2', '|2']
1041 alternative_opener = ['|1', '|2', ':|2']
1042 repeat_ender = ['::', ':|']
1043 repeat_opener = ['::', '|:']
1044 in_repeat = [''] * 8
1045 doing_alternative = [''] * 8
1048 def try_parse_bar (str,state):
1049 global in_repeat, doing_alternative, using_old
1052 if current_voice_idx < 0:
1053 select_voice ('default', '')
1054 # first try the longer one
1055 for trylen in [3,2,1]:
1056 if str[:trylen] and bar_dict.has_key (str[:trylen]):
1059 bs = "\\bar \"%s\"" % old_bar_dict[s]
1061 bs = "%s" % bar_dict[s]
1063 if s in alternative_opener:
1064 if not in_repeat[current_voice_idx]:
1066 bs = "\\bar \"%s\"" % old_bar_dict[s]
1068 doing_alternative[current_voice_idx] = 't'
1070 if s in repeat_ender:
1071 if not in_repeat[current_voice_idx]:
1072 sys.stderr.write("Warning: inserting repeat to beginning of notes.\n")
1074 in_repeat[current_voice_idx] = ''
1076 if doing_alternative[current_voice_idx]:
1079 bs = "\\bar \"%s\"" % old_bar_dict[s]
1082 doing_alternative[current_voice_idx] = ''
1083 in_repeat[current_voice_idx] = ''
1084 if s in repeat_opener:
1085 in_repeat[current_voice_idx] = 't'
1087 bs = "\\bar \"%s\"" % old_bar_dict[s]
1092 state.next_bar = '|\n'
1094 clear_bar_acc(state)
1096 if bs <> None or state.next_bar != '':
1097 if state.parsing_tuplet:
1098 state.parsing_tuplet =0
1099 voices_append ('} ')
1102 clear_bar_acc(state)
1105 voices_append("} }")
1109 def try_parse_tie (str):
1112 voices_append (' ~ ')
1115 def bracket_escape (str, state):
1116 m = re.match ( '^([^\]]*)] *(.*)$', str)
1120 try_parse_header_line (cmd, state)
1123 def try_parse_chord_delims (str, state):
1126 if re.match('[A-Z]:', str): # bracket escape
1127 return bracket_escape(str, state)
1129 voices_append(state.next_bar)
1135 if state.plus_chord:
1137 state.plus_chord = 0
1140 voices_append(state.next_bar)
1143 state.plus_chord = 1
1151 while str[:1] ==')':
1156 voices_append ("\\spanrequest \\stop \"slur\"" * end)
1160 def try_parse_grace_delims (str, state):
1163 voices_append(state.next_bar)
1166 voices_append ('\\grace { ')
1174 def try_parse_comment (str):
1177 if str[0:5] == '%MIDI':
1178 #the nobarlines option is necessary for an abc to lilypond translator for
1179 #exactly the same reason abc2midi needs it: abc requires the user to enter
1180 #the note that will be printed, and MIDI and lilypond expect entry of the
1181 #pitch that will be played.
1183 #In standard 19th century musical notation, the algorithm for translating
1184 #between printed note and pitch involves using the barlines to determine
1185 #the scope of the accidentals.
1187 #Since ABC is frequently used for music in styles that do not use this
1188 #convention, such as most music written before 1700, or ethnic music in
1189 #non-western scales, it is necessary to be able to tell a translator that
1190 #the barlines should not affect its interpretation of the pitch.
1191 if (string.find(str,'nobarlines') > 0):
1193 elif str[0:3] == '%LY':
1194 p = string.find(str, 'voices')
1196 voices_append(str[p+7:])
1198 p = string.find(str, 'slyrics')
1200 slyrics_append(str[p+8:])
1202 #write other kinds of appending if we ever need them.
1206 def parse_file (fn):
1210 select_voice('default', '')
1212 sys.stderr.write ("Line ... ")
1214 __main__.state = state_list[current_voice_idx]
1219 if not (lineno % happy_count):
1220 sys.stderr.write ('[%d]'% lineno)
1222 m = re.match ('^([^%]*)%(.*)$',ln) # add comments to current voice
1225 try_parse_comment(m.group(2))
1226 voices_append ('%% %s\n' % m.group(2))
1231 ln = try_parse_header_line (ln, state)
1233 # Try nibbling characters off until the line doesn't change.
1235 while ln != prev_ln:
1237 ln = try_parse_chord_delims (ln, state)
1238 ln = try_parse_rest (ln, state)
1239 ln = try_parse_articulation (ln,state)
1240 ln = try_parse_note (ln, state)
1241 ln = try_parse_bar (ln, state)
1242 ln = try_parse_tie (ln)
1243 ln = try_parse_escape (ln)
1244 ln = try_parse_guitar_chord (ln, state)
1245 ln = try_parse_tuplet_begin (ln, state)
1246 ln = try_parse_group_end (ln, state)
1247 ln = try_parse_grace_delims (ln, state)
1248 ln = junk_space (ln)
1251 error ("%s: %d: Huh? Don't understand\n" % (fn, lineno))
1252 left = orig_ln[0:-len (ln)]
1253 sys.stderr.write (left + '\n')
1254 sys.stderr.write (' ' * len (left) + ln + '\n')
1258 sys.stderr.write ("%s from LilyPond %s\n" % (program_name, version))
1262 Convert ABC to lilypond.
1264 Usage: abc2ly [OPTIONS]... ABC-FILE
1267 -h, --help this help
1268 -o, --output=FILE set output filename to FILE
1269 -v, --version version information
1270 -s, --strict be strict about succes.
1272 This program converts ABC music files (see
1273 http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt) To LilyPond input.
1276 Report bugs to bug-lilypond@gnu.org
1278 Written by Han-Wen Nienhuys <hanwen@cs.uu.nl>, Laura Conrad
1279 <lconrad@laymusic.org>, Roy Rankin <Roy.Rankin@@alcatel.com.au>
1282 def print_version ():
1283 print r"""abc2ly (GNU lilypond) %s""" % version
1287 (options, files) = getopt.getopt (sys.argv[1:], 'vo:hs', ['help','version', 'output=', 'strict'])
1293 if o== '--help' or o == '-h':
1296 elif o == '--version' or o == '-v':
1299 elif o == '--strict' or o == '-s':
1301 elif o == '--output' or o == '-o':
1309 header['tagline'] = 'Lily was here %s -- automatically converted from ABC' % version
1314 sys.stderr.write ('Parsing `%s\'...\n' % f)
1317 if not out_filename:
1318 out_filename = os.path.basename (os.path.splitext (f)[0]) + ".ly"
1319 sys.stderr.write ('lilypond output to: `%s\'...' % out_filename)
1320 outf = open (out_filename, 'w')
1322 # dump_global (outf)
1323 dump_header (outf ,header)
1328 sys.stderr.write ('\n')