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.
54 # * GNU style messages: warning:FILE:LINE:
57 # Convert to new chord styles.
63 program_name = 'abc2ly'
64 version = '@TOPLEVEL_VERSION@'
65 if version == '@' + 'TOPLEVEL_VERSION' + '@':
66 version = '(unknown version)' # uGUHGUHGHGUGH
81 header['footnotes'] = ''
86 repeat_state = [0] * 8
87 current_voice_idx = -1
88 current_lyric_idx = -1
94 global_key = [0] * 7 # UGH
95 names = ["One", "Two", "Three"]
97 alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
103 sys.stderr.write (msg)
111 if re.match('-8va', s) or re.match('treble8', s):
112 # treble8 is used by abctab2ps; -8va is used by barfly,
113 # and by my patch to abc2ps. If there's ever a standard
114 # about this we'll support that.
116 state.base_octave = -1
117 voices_append("\\clef \"G_8\"\n")
118 elif re.match('^treble', s):
120 if re.match ('^-8', s):
122 state.base_octave = -2
123 voices_append("\\clef \"G_8\"\n")
125 state.base_octave = 0
126 voices_append("\\clef treble\n")
127 elif re.match('^alto', s):
129 state.base_octave = -1
130 voices_append ("\\clef alto\n" )
131 elif re.match('^bass',s ):
133 state.base_octave = -2
134 voices_append ("\\clef bass\n" )
137 def select_voice (name, rol):
138 if not voice_idx_dict.has_key (name):
139 state_list.append(Parser_state())
142 voice_idx_dict[name] = len (voices) -1
143 __main__.current_voice_idx = voice_idx_dict[name]
144 __main__.state = state_list[current_voice_idx]
146 m = re.match ('^([^ \t=]*)=(.*)$', rol) # find keywork
150 a = re.match ('^("[^"]*"|[^ \t]*) *(.*)$', rol)
154 if keyword == 'clef':
156 elif keyword == "name":
157 value = re.sub ('\\\\','\\\\\\\\', value)
158 voices_append ("\\set Staff.instrument = %s\n" % value )
159 __main__.part_names = 1
160 elif keyword == "sname" or keyword == "snm":
161 voices_append ("\\set Staff.instr = %s\n" % value )
169 def dump_header (outf,hdr):
170 outf.write ('\\header {\n')
174 hdr[k] = re.sub('"', '\\"', hdr[k])
175 outf.write ('\t%s = "%s"\n'% (k,hdr[k]))
178 def dump_lyrics (outf):
180 outf.write("\n\\score\n{\n \\context Lyrics\n <<\n")
181 for i in range (len (lyrics)):
182 outf.write ( lyrics [i])
184 outf.write(" >>\n \\paper{}\n}\n")
186 def dump_default_bar (outf):
188 Nowadays abc2ly outputs explicits barlines (?)
190 outf.write ("\n\\set Score.defaultBarType=\"empty\"\n")
193 def dump_slyrics (outf):
194 ks = voice_idx_dict.keys()
197 if re.match('[1-9]', k):
198 m = alphabet[string.atoi(k)]
201 for i in range (len(slyrics[voice_idx_dict[k]])):
203 outf.write ("\nwords%sV%s = \\lyrics {" % (m, l))
204 outf.write ("\n" + slyrics [voice_idx_dict[k]][i])
207 def dump_voices (outf):
208 global doing_alternative, in_repeat
209 ks = voice_idx_dict.keys()
212 if re.match ('[1-9]', k):
213 m = alphabet[string.atoi(k)]
216 outf.write ("\nvoice%s = \\notes {" % m)
217 dump_default_bar(outf)
218 if repeat_state[voice_idx_dict[k]]:
219 outf.write("\n\\repeat volta 2 {")
220 outf.write ("\n" + voices [voice_idx_dict[k]])
222 if doing_alternative[voice_idx_dict[k]]:
224 if in_repeat[voice_idx_dict[k]]:
230 #assume that Q takes the form "Q:1/4=120"
231 #There are other possibilities, but they are deprecated
232 if string.count(a, '/') == 1:
233 array=string.split(a,'/')
236 sys.stderr.write("abc2ly: Warning, unable to translate a Q specification with a numerator of %s: %s\n" % (numerator, a))
237 array2=string.split(array[1],'=')
238 denominator=array2[0]
240 duration=str(string.atoi(denominator)/string.atoi(numerator))
241 midi_specs=string.join(["\\tempo", duration, "=", perminute])
243 sys.stderr.write("abc2ly: Warning, unable to parse Q specification: %s\n" % a)
245 def dump_score (outf):
246 outf.write (r"""\score{
250 ks = voice_idx_dict.keys ();
253 if re.match('[1-9]', k):
254 m = alphabet[string.atoi(k)]
257 if k == 'default' and len (voice_idx_dict) > 1:
259 if len ( slyrics [voice_idx_dict[k]] ):
260 outf.write ("\n \\addlyrics")
261 outf.write ("\n\t\\context Staff=\"%s\"\n\t{\n" %k )
263 outf.write ("\t \\voicedefault\n")
264 outf.write ("\t \\voice%s " % m)
265 outf.write ("\n\t}\n")
266 if len ( slyrics [voice_idx_dict[k]] ):
267 outf.write ("\n\t\\context Lyrics=\"%s\" \n\t<<\t" % k)
268 if re.match('[1-9]',k):
269 m = alphabet[string.atoi(k)]
272 for i in range (len(slyrics[voice_idx_dict[k]])):
274 outf.write("\n\t { \\words%sV%s }" % ( m, l) )
275 outf.write ( "\n\t>>\n" )
277 outf.write ("\n\t\\paper {\n")
279 outf.write ("\t \\translator \n\t {\n")
280 outf.write ("\t\t\\StaffContext\n")
281 # outf.write ("\t\t\\consists Staff_margin_engraver\n")
282 outf.write ("\t }\n")
283 outf.write ("\t}\n\t\\midi {%s}\n}\n" % midi_specs)
287 def set_default_length (s):
288 global length_specified
289 m = re.search ('1/([0-9]+)', s)
291 __main__.default_len = string.atoi ( m.group (1))
294 def set_default_len_from_time_sig (s):
295 m = re.search ('([0-9]+)/([0-9]+)', s)
297 n = string.atoi (m.group (1))
298 d = string.atoi (m.group (2))
299 if (n * 1.0 )/(d * 1.0) < 0.75:
300 __main__.default_len = 16
302 __main__.default_len = 8
311 sys.stderr.write ("can't open file: `%s'\n" % f)
315 sys.stderr.write ("gulped empty file: `%s'\n" % f)
320 # pitch manipulation. Tuples are (name, alteration).
321 # 0 is (central) C. Alteration -1 is a flat, Alteration +1 is a sharp
322 # pitch in semitones.
323 def semitone_pitch (tup):
333 p = p + t* 2 + tup[1]
336 def fifth_above_pitch (tup):
337 (n, a) = (tup[0] + 4, tup[1])
339 difference = 7 - (semitone_pitch ((n,a)) - semitone_pitch (tup))
350 (t,a) = fifth_above_pitch (p)
351 if semitone_pitch((t,a)) % 12 == 0:
363 (t,a) = quart_above_pitch (p)
364 if semitone_pitch((t,a)) % 12 == 0:
370 def quart_above_pitch (tup):
371 (n, a) = (tup[0] + 3, tup[1])
373 difference = 5 - (semitone_pitch ((n,a)) - semitone_pitch (tup))
378 key_lookup = { # abc to lilypond key mode names
387 'mix' : 'mixolydian',
388 'mixolydian' : 'mixolydian',
401 if k and k[0] == '#':
404 elif k and k[0] == 'b':
408 return '%s \\major' % key
411 if not key_lookup.has_key (type):
412 #ugh, use lilylib, say WARNING:FILE:LINE:
413 sys.stderr.write ("abc2ly:warning:")
414 sys.stderr.write ("ignoring unknown key: `%s'" % orig)
415 sys.stderr.write ('\n')
417 return ("%s \\%s" % ( key, key_lookup[type]))
419 def shift_key (note, acc , shift):
420 s = semitone_pitch((note, acc))
421 s = (s + shift + 12) % 12
433 key_shift = { # semitone shifts for key mode names
456 intkey = (ord (k[0]) - ord('a') + 5) % 7
460 if k and k[0] == 'b':
463 elif k and k[0] == '#':
467 if k and key_shift.has_key(k):
468 (intkey, intkeyacc) = shift_key(intkey, intkeyacc, key_shift[k])
469 keytup = (intkey, intkeyacc)
471 sharp_key_seq = sharp_keys ()
472 flat_key_seq = flat_keys ()
476 if keytup in sharp_key_seq:
478 key_count = sharp_key_seq.index (keytup)
479 accseq = map (lambda x: (4*x -1 ) % 7, range (1, key_count + 1))
481 elif keytup in flat_key_seq:
483 key_count = flat_key_seq.index (keytup)
484 accseq = map (lambda x: (3*x + 3 ) % 7, range (1, key_count + 1))
491 key_table[a] = key_table[a] + accsign
506 def try_parse_tuplet_begin (str, state):
507 if re.match ('\([2-9]', str):
510 prev_tuplet_state = state.parsing_tuplet
511 state.parsing_tuplet = string.atoi (dig[0])
512 if prev_tuplet_state:
514 voices_append ("\\times %s {" % tup_lookup[dig])
517 def try_parse_group_end (str, state):
518 if str and str[0] in HSPACE:
522 def header_append (key, a):
524 if header.has_key (key):
525 s = header[key] + "\n"
529 linelen = len (v) - string.rfind(v, '\n')
530 if linelen + len (a) > 80:
534 def stuff_append (stuff, idx, a):
538 stuff [idx] = wordwrap(a, stuff[idx])
542 def voices_append(a):
543 if current_voice_idx < 0:
544 select_voice ('default', '')
545 stuff_append (voices, current_voice_idx, a)
547 def repeat_prepend():
549 if current_voice_idx < 0:
550 select_voice ('default', '')
552 repeat_state[current_voice_idx] = 't'
555 def lyrics_append(a):
556 a = re.sub ( '#', '\\#', a) # latex does not like naked #'s
557 a = re.sub ( '"', '\\"', a) # latex does not like naked "'s
558 a = '\t{ \\lyrics "' + a + '" }\n'
559 stuff_append (lyrics, current_lyric_idx, a)
561 # break lyrics to words and put "'s around words containing numbers and '"'s
565 m = re.match('[ \t]*([^ \t]*)[ \t]*(.*$)', str)
569 word = re.sub('"', '\\"', word) # escape "
570 if re.match('.*[0-9"\(]', word):
571 word = re.sub('_', ' ', word) # _ causes probs inside ""
572 ret = ret + '\"' + word + '\" '
574 ret = ret + word + ' '
579 def slyrics_append(a):
580 a = re.sub ( '_', ' _ ', a) # _ to ' _ '
581 a = re.sub ( '-', '- ', a) # split words with -
582 a = re.sub ( '\\\\- ', '-', a) # unless \-
583 a = re.sub ( '~', '_', a) # ~ to space('_')
584 a = re.sub ( '\*', '_ ', a) # * to to space
585 a = re.sub ( '#', '\\#', a) # latex does not like naked #'s
586 if re.match('.*[0-9"\(]', a): # put numbers and " and ( into quoted string
588 a = re.sub ( '$', ' ', a) # insure space between lines
589 __main__.lyric_idx = lyric_idx + 1
590 if len(slyrics[current_voice_idx]) <= lyric_idx:
591 slyrics[current_voice_idx].append(a)
593 v = slyrics[current_voice_idx][lyric_idx]
594 slyrics[current_voice_idx][lyric_idx] = wordwrap(a, slyrics[current_voice_idx][lyric_idx])
597 def try_parse_header_line (ln, state):
598 global length_specified
599 m = re.match ('^([A-Za-z]): *(.*)$', ln)
605 a = re.sub('[ \t]*$','', a) #strip trailing blanks
606 if header.has_key('title'):
608 if len(header['title']):
609 header['title'] = header['title'] + '\\\\\\\\' + a
611 header['subtitle'] = a
616 if not state.common_time:
617 state.common_time = 1
618 voices_append ("\\override Staff.TimeSignature #\'style = #'C\n")
621 if not state.common_time:
622 state.common_time = 1
623 voices_append ("\\override Staff.TimeSignature #\'style = #'C\n")
625 if not length_specified:
626 set_default_len_from_time_sig (a)
630 voices_append ('\\time %s' % a)
635 m = re.match ('^([^ \t]*) *(.*)$', a) # seperate clef info
637 # there may or may not be a space
638 # between the key letter and the mode
639 if key_lookup.has_key(m.group(2)[0:3]):
640 key_info = m.group(1) + m.group(2)[0:3]
641 clef_info = m.group(2)[4:]
643 key_info = m.group(1)
644 clef_info = m.group(2)
645 __main__.global_key = compute_key (key_info)
646 k = lily_key (key_info)
648 voices_append ('\\key %s' % k)
649 check_clef(clef_info)
651 __main__.global_key = compute_key (a)
654 voices_append ('\\key %s \\major' % k)
656 header ['footnotes'] = header['footnotes'] + '\\\\\\\\' + a
657 if g == 'O': # Origin
658 header ['origin'] = a
659 if g == 'X': # Reference Number
660 header ['crossRefNumber'] = a
663 if g == 'H': # History
664 header_append ('history', a)
667 if g == 'C': # Composer
668 if header.has_key('composer'):
670 header['composer'] = header['composer'] + '\\\\\\\\' + a
672 header['composer'] = a
674 header ['subtitle'] = a
675 if g == 'L': # Default note length
676 set_default_length (ln)
678 voice = re.sub (' .*$', '', a)
679 rest = re.sub ('^[^ \t]* *', '', a)
681 voices_append(state.next_bar)
683 select_voice (voice, rest)
686 if g == 'w': # vocals
693 # we use in this order specified accidental, active accidental for bar,
694 # active accidental for key
695 def pitch_to_lilypond_name (name, acc, bar_acc, key):
709 return(chr (name + ord('c')) + s)
712 def octave_to_lilypond_quotes (o):
725 while str and str[0] in DIGITS:
726 durstr = durstr + str[0]
731 n =string.atoi (durstr)
735 def duration_to_lilypond_duration (multiply_tup, defaultlen, dots):
737 # (num / den) / defaultlen < 1/base
738 while base * multiply_tup[0] < multiply_tup[1]:
741 if (multiply_tup[0] / multiply_tup[1]) == 2:
743 if (multiply_tup[0] / multiply_tup[1]) == 3:
746 if (multiply_tup[0] / multiply_tup[1]) == 4:
748 return '%s%s' % ( base, '.'* dots)
753 self.next_articulation = ''
757 self.parsing_tuplet = 0
764 # return (str, num,den,dots)
765 def parse_duration (str, parser_state):
767 den = parser_state.next_den
768 parser_state.next_den = 1
770 (str, num) = parse_num (str)
776 while str[:1] == '/':
780 (str, d) =parse_num (str)
784 den = den * default_len
786 current_dots = parser_state.next_dots
787 parser_state.next_dots = 0
788 if re.match ('[ \t]*[<>]', str):
789 while str[0] in HSPACE:
793 current_dots = current_dots + 1
794 parser_state.next_den = parser_state.next_den * 2
799 parser_state.next_dots = parser_state.next_dots + 1
807 if num % multiplier == 0 and den % f == 0:
808 num = num / multiplier
810 current_dots = current_dots + d
812 return (str, num,den,current_dots)
815 def try_parse_rest (str, parser_state):
816 if not str or str[0] <> 'z' and str[0] <> 'x':
819 __main__.lyric_idx = -1
821 if parser_state.next_bar:
822 voices_append(parser_state.next_bar)
823 parser_state.next_bar = ''
831 (str, num,den,d) = parse_duration (str, parser_state)
832 voices_append ('%s%s' % (rest, duration_to_lilypond_duration ((num,den), default_len, d)))
833 if parser_state.next_articulation:
834 voices_append (parser_state.next_articulation)
835 parser_state.next_articulation = ''
848 'J' : '', # ignore slide
849 'R' : '', # ignore roll
853 def try_parse_articulation (str, state):
854 while str and artic_tbl.has_key(str[:1]):
855 state.next_articulation = state.next_articulation + artic_tbl[str[:1]]
856 if not artic_tbl[str[:1]]:
857 sys.stderr.write("Warning: ignoring `%s'\n" % str[:1] )
863 # s7m2 input doesnt care about spaces
864 if re.match('[ \t]*\(', str):
865 str = string.lstrip (str)
868 while str[:1] =='(' and str[1] not in DIGITS:
869 slur_begin = slur_begin + 1
870 state.next_articulation = state.next_articulation + '('
876 # remember accidental for rest of bar
878 def set_bar_acc(note, octave, acc, state):
881 n_oct = note + octave * 7
882 state.in_acc[n_oct] = acc
884 # get accidental set in this bar or UNDEF if not set
885 def get_bar_acc(note, octave, state):
886 n_oct = note + octave * 7
887 if state.in_acc.has_key(n_oct):
888 return(state.in_acc[n_oct])
892 def clear_bar_acc(state):
893 for k in state.in_acc.keys():
898 # WAT IS ABC EEN ONTZETTENDE PROGRAMMEERPOEP !
899 def try_parse_note (str, parser_state):
918 octave = parser_state.base_octave
919 if str[0] in "ABCDEFG":
920 str = string.lower (str[0]) + str[1:]
925 if str[0] in "abcdefg":
926 notename = (ord(str[0]) - ord('a') + 5)%7
929 return str # failed; not a note!
932 __main__.lyric_idx = -1
934 if parser_state.next_bar:
935 voices_append(parser_state.next_bar)
936 parser_state.next_bar = ''
941 while str[0] == '\'':
945 (str, num,den,current_dots) = parse_duration (str, parser_state)
947 if re.match('[ \t]*\)', str):
948 str = string.lstrip (str)
952 slur_end = slur_end + 1
956 bar_acc = get_bar_acc(notename, octave, parser_state)
957 pit = pitch_to_lilypond_name(notename, acc, bar_acc, global_key[notename])
958 oct = octave_to_lilypond_quotes (octave)
959 if acc != UNDEF and (acc == global_key[notename] or acc == bar_acc):
963 voices_append ("%s%s%s%s" %
965 duration_to_lilypond_duration ((num,den), default_len, current_dots)))
967 set_bar_acc(notename, octave, acc, parser_state)
968 if parser_state.next_articulation:
969 articulation = articulation + parser_state.next_articulation
970 parser_state.next_articulation = ''
972 voices_append (articulation)
974 if parser_state.parsing_tuplet:
975 parser_state.parsing_tuplet = parser_state.parsing_tuplet - 1
976 if not parser_state.parsing_tuplet:
979 voices_append ('-(' * slur_begin )
981 voices_append ('-)' *slur_end )
987 def junk_space (str):
988 while str and str[0] in '\t\n ':
994 def try_parse_guitar_chord (str, state):
998 if str[0] == '_' or (str[0] == '^'):
1003 while str and str[0] != '"':
1009 gc = re.sub('#', '\\#', gc) # escape '#'s
1010 state.next_articulation = ("%c\"%s\"" % (position ,gc)) + state.next_articulation
1013 def try_parse_escape (str):
1014 if not str or str [0] != '\\':
1019 key_table = compute_key ()
1023 # |] thin-thick double bar line
1024 # || thin-thin double bar line
1025 # [| thick-thin double bar line
1028 # :: left-right repeat
1044 '|]' : '\\bar "|."',
1045 '||' : '\\bar "||"',
1046 '[|' : '\\bar "||"',
1048 '|:' : '\\repeat volta 2 {',
1049 '::' : '} \\repeat volta 2 {',
1050 '|1' : '} \\alternative{{',
1057 warn_about = ['|:', '::', ':|', '|1', ':|2', '|2']
1058 alternative_opener = ['|1', '|2', ':|2']
1059 repeat_ender = ['::', ':|']
1060 repeat_opener = ['::', '|:']
1061 in_repeat = [''] * 8
1062 doing_alternative = [''] * 8
1065 def try_parse_bar (str,state):
1066 global in_repeat, doing_alternative, using_old
1069 if current_voice_idx < 0:
1070 select_voice ('default', '')
1071 # first try the longer one
1072 for trylen in [3,2,1]:
1073 if str[:trylen] and bar_dict.has_key (str[:trylen]):
1076 bs = "\\bar \"%s\"" % old_bar_dict[s]
1078 bs = "%s" % bar_dict[s]
1080 if s in alternative_opener:
1081 if not in_repeat[current_voice_idx]:
1083 bs = "\\bar \"%s\"" % old_bar_dict[s]
1085 doing_alternative[current_voice_idx] = 't'
1087 if s in repeat_ender:
1088 if not in_repeat[current_voice_idx]:
1089 sys.stderr.write("Warning: inserting repeat to beginning of notes.\n")
1091 in_repeat[current_voice_idx] = ''
1093 if doing_alternative[current_voice_idx]:
1096 bs = "\\bar \"%s\"" % old_bar_dict[s]
1099 doing_alternative[current_voice_idx] = ''
1100 in_repeat[current_voice_idx] = ''
1101 if s in repeat_opener:
1102 in_repeat[current_voice_idx] = 't'
1104 bs = "\\bar \"%s\"" % old_bar_dict[s]
1109 state.next_bar = '|\n'
1111 clear_bar_acc(state)
1113 if bs <> None or state.next_bar != '':
1114 if state.parsing_tuplet:
1115 state.parsing_tuplet =0
1116 voices_append ('} ')
1119 clear_bar_acc(state)
1122 voices_append("} }")
1126 def try_parse_tie (str):
1129 voices_append (' ~ ')
1132 def bracket_escape (str, state):
1133 m = re.match ( '^([^\]]*)] *(.*)$', str)
1137 try_parse_header_line (cmd, state)
1140 def try_parse_chord_delims (str, state):
1143 if re.match('[A-Z]:', str): # bracket escape
1144 return bracket_escape(str, state)
1146 voices_append(state.next_bar)
1152 if state.plus_chord:
1154 state.plus_chord = 0
1157 voices_append(state.next_bar)
1160 state.plus_chord = 1
1168 while str[:1] ==')':
1173 voices_append ("\\spanrequest \\stop \"slur\"" * end)
1177 def try_parse_grace_delims (str, state):
1180 voices_append(state.next_bar)
1183 voices_append ('\\grace { ')
1191 def try_parse_comment (str):
1194 if str[0:5] == '%MIDI':
1195 #the nobarlines option is necessary for an abc to lilypond translator for
1196 #exactly the same reason abc2midi needs it: abc requires the user to enter
1197 #the note that will be printed, and MIDI and lilypond expect entry of the
1198 #pitch that will be played.
1200 #In standard 19th century musical notation, the algorithm for translating
1201 #between printed note and pitch involves using the barlines to determine
1202 #the scope of the accidentals.
1204 #Since ABC is frequently used for music in styles that do not use this
1205 #convention, such as most music written before 1700, or ethnic music in
1206 #non-western scales, it is necessary to be able to tell a translator that
1207 #the barlines should not affect its interpretation of the pitch.
1208 if (string.find(str,'nobarlines') > 0):
1210 elif str[0:3] == '%LY':
1211 p = string.find(str, 'voices')
1213 voices_append(str[p+7:])
1215 p = string.find(str, 'slyrics')
1217 slyrics_append(str[p+8:])
1219 #write other kinds of appending if we ever need them.
1224 def parse_file (fn):
1227 ls = map (lambda x: re.sub ("\r$", '', x), ls)
1229 select_voice('default', '')
1232 sys.stderr.write ("Line ... ")
1234 __main__.state = state_list[current_voice_idx]
1239 if not (lineno % happy_count):
1240 sys.stderr.write ('[%d]'% lineno)
1242 m = re.match ('^([^%]*)%(.*)$',ln) # add comments to current voice
1245 try_parse_comment(m.group(2))
1246 voices_append ('%% %s\n' % m.group(2))
1251 ln = try_parse_header_line (ln, state)
1253 # Try nibbling characters off until the line doesn't change.
1255 while ln != prev_ln:
1257 ln = try_parse_chord_delims (ln, state)
1258 ln = try_parse_rest (ln, state)
1259 ln = try_parse_articulation (ln,state)
1260 ln = try_parse_note (ln, state)
1261 ln = try_parse_bar (ln, state)
1262 ln = try_parse_tie (ln)
1263 ln = try_parse_escape (ln)
1264 ln = try_parse_guitar_chord (ln, state)
1265 ln = try_parse_tuplet_begin (ln, state)
1266 ln = try_parse_group_end (ln, state)
1267 ln = try_parse_grace_delims (ln, state)
1268 ln = junk_space (ln)
1271 error ("%s: %d: Huh? Don't understand\n" % (fn, lineno))
1272 left = orig_ln[0:-len (ln)]
1273 sys.stderr.write (left + '\n')
1274 sys.stderr.write (' ' * len (left) + ln + '\n')
1278 sys.stderr.write ("%s from LilyPond %s\n" % (program_name, version))
1282 Convert ABC to lilypond.
1284 Usage: abc2ly [OPTIONS]... ABC-FILE
1287 -h, --help print this help
1288 -o, --output=FILE set output filename to FILE
1289 -v, --version show version information
1290 -s, --strict be strict about succes
1292 This program converts ABC music files (see
1293 http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt) to LilyPond input.
1296 Report bugs to bug-lilypond@gnu.org.
1298 Written by Han-Wen Nienhuys <hanwen@cs.uu.nl>, Laura Conrad
1299 <lconrad@laymusic.org>, Roy Rankin <Roy.Rankin@@alcatel.com.au>.
1302 def print_version ():
1303 print r"""abc2ly (GNU lilypond) %s""" % version
1307 (options, files) = getopt.getopt (sys.argv[1:], 'vo:hs', ['help','version', 'output=', 'strict'])
1313 if o== '--help' or o == '-h':
1316 elif o == '--version' or o == '-v':
1319 elif o == '--strict' or o == '-s':
1321 elif o == '--output' or o == '-o':
1329 header['tagline'] = 'Lily was here %s -- automatically converted from ABC' % version
1334 sys.stderr.write ('Parsing `%s\'...\n' % f)
1337 if not out_filename:
1338 out_filename = os.path.basename (os.path.splitext (f)[0]) + ".ly"
1339 sys.stderr.write ('lilypond output to: `%s\'...' % out_filename)
1340 outf = open (out_filename, 'w')
1342 # dump_global (outf)
1343 dump_header (outf ,header)
1348 sys.stderr.write ('\n')