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
72 header['footnotes'] = ''
77 repeat_state = [0] * 8
78 current_voice_idx = -1
79 current_lyric_idx = -1
85 global_key = [0] * 7 # UGH
86 names = ["One", "Two", "Three"]
88 alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
95 if re.match('-8va', s) or re.match('treble8', s):
96 # treble8 is used by abctab2ps; -8va is used by barfly,
97 # and by my patch to abc2ps. If there's ever a standard
98 # about this we'll support that.
100 state.base_octave = -1
101 voices_append("\\clef \"G_8\"\n")
102 elif re.match('^treble', s):
104 if re.match ('^-8', s):
106 state.base_octave = -2
107 voices_append("\\clef \"G_8\"\n")
109 state.base_octave = 0
110 voices_append("\\clef treble\n")
111 elif re.match('^alto', s):
113 state.base_octave = -1
114 voices_append ("\\clef alto\n" )
115 elif re.match('^bass',s ):
117 state.base_octave = -2
118 voices_append ("\\clef bass\n" )
121 def select_voice (name, rol):
122 if not voice_idx_dict.has_key (name):
123 state_list.append(Parser_state())
126 voice_idx_dict[name] = len (voices) -1
127 __main__.current_voice_idx = voice_idx_dict[name]
128 __main__.state = state_list[current_voice_idx]
130 m = re.match ('^([^ \t=]*)=(.*)$', rol) # find keywork
134 a = re.match ('^("[^"]*"|[^ \t]*) *(.*)$', rol)
138 if keyword == 'clef':
140 elif keyword == "name":
141 value = re.sub ('\\\\','\\\\\\\\', value)
142 voices_append ("\\property Staff.instrument = %s\n" % value )
143 __main__.part_names = 1
144 elif keyword == "sname" or keyword == "snm":
145 voices_append ("\\property Staff.instr = %s\n" % value )
153 def dump_header (outf,hdr):
154 outf.write ('\\header {\n')
158 outf.write ('\t%s = "%s"\n'% (k,hdr[k]))
161 def dump_lyrics (outf):
163 outf.write("\n\\score\n{\n \\context Lyrics\n <\n")
164 for i in range (len (lyrics)):
165 outf.write ( lyrics [i])
167 outf.write(" >\n \\paper{}\n}\n")
169 def dump_default_bar (outf):
170 outf.write ("\n\\property Score.defaultBarType=\"empty\"\n")
173 def dump_slyrics (outf):
174 ks = voice_idx_dict.keys()
177 if re.match('[1-9]', k):
178 m = alphabet[string.atoi(k)]
181 for i in range (len(slyrics[voice_idx_dict[k]])):
183 outf.write ("\nwords%sV%s = \\lyrics {" % (m, l))
184 outf.write ("\n" + slyrics [voice_idx_dict[k]][i])
187 def dump_voices (outf):
188 global doing_alternative, in_repeat
189 ks = voice_idx_dict.keys()
192 if re.match ('[1-9]', k):
193 m = alphabet[string.atoi(k)]
196 outf.write ("\nvoice%s = \\notes {" % m)
197 dump_default_bar(outf)
198 if repeat_state[voice_idx_dict[k]]:
199 outf.write("\n\\repeat volta 2 {")
200 outf.write ("\n" + voices [voice_idx_dict[k]])
202 if doing_alternative[voice_idx_dict[k]]:
204 if in_repeat[voice_idx_dict[k]]:
208 def dump_score (outf):
209 outf.write (r"""\score{
213 ks = voice_idx_dict.keys ();
216 if re.match('[1-9]', k):
217 m = alphabet[string.atoi(k)]
220 if k == 'default' and len (voice_idx_dict) > 1:
222 if len ( slyrics [voice_idx_dict[k]] ):
223 outf.write ("\n \\addlyrics")
224 outf.write ("\n\t\\context Staff=\"%s\"\n\t{\n" %k )
226 outf.write ("\t \\voicedefault\n")
227 outf.write ("\t \\voice%s " % m)
228 outf.write ("\n\t}\n")
229 if len ( slyrics [voice_idx_dict[k]] ):
230 outf.write ("\n\t\\context Lyrics=\"%s\" \n\t<\t" % k)
231 if re.match('[1-9]',k):
232 m = alphabet[string.atoi(k)]
235 for i in range (len(slyrics[voice_idx_dict[k]])):
237 outf.write("\n\t { \\words%sV%s }" % ( m, l) )
238 outf.write ( "\n\t>\n" )
240 outf.write ("\n\t\\paper {\n")
242 outf.write ("\t \\translator \n\t {\n")
243 outf.write ("\t\t\\StaffContext\n")
244 # outf.write ("\t\t\\consists Staff_margin_engraver\n")
245 outf.write ("\t }\n")
246 outf.write ("\t}\n\t\\midi {}\n}\n")
250 def set_default_length (s):
251 global length_specified
252 m = re.search ('1/([0-9]+)', s)
254 __main__.default_len = string.atoi ( m.group (1))
257 def set_default_len_from_time_sig (s):
258 m = re.search ('([0-9]+)/([0-9]+)', s)
260 n = string.atoi (m.group (1))
261 d = string.atoi (m.group (2))
262 if (n * 1.0 )/(d * 1.0) < 0.75:
263 __main__.default_len = 16
265 __main__.default_len = 8
274 sys.stderr.write ("can't open file: `%s'\n" % f)
278 sys.stderr.write ("gulped empty file: `%s'\n" % f)
283 # pitch manipulation. Tuples are (name, alteration).
284 # 0 is (central) C. Alteration -1 is a flat, Alteration +1 is a sharp
285 # pitch in semitones.
286 def semitone_pitch (tup):
296 p = p + t* 2 + tup[1]
299 def fifth_above_pitch (tup):
300 (n, a) = (tup[0] + 4, tup[1])
302 difference = 7 - (semitone_pitch ((n,a)) - semitone_pitch (tup))
313 (t,a) = fifth_above_pitch (p)
314 if semitone_pitch((t,a)) % 12 == 0:
326 (t,a) = quart_above_pitch (p)
327 if semitone_pitch((t,a)) % 12 == 0:
333 def quart_above_pitch (tup):
334 (n, a) = (tup[0] + 3, tup[1])
336 difference = 5 - (semitone_pitch ((n,a)) - semitone_pitch (tup))
341 key_lookup = { # abc to lilypond key mode names
350 'mix' : 'mixolydian',
351 'mixolydian' : 'mixolydian',
361 if k and k[0] == '#':
364 elif k and k[0] == 'b':
368 return '%s \\major' % key
371 if key_lookup.has_key(type):
372 return("%s \\%s" % ( key, key_lookup[type]))
373 sys.stderr.write("Unknown key type `%s' ignored\n" % type)
376 def shift_key (note, acc , shift):
377 s = semitone_pitch((note, acc))
378 s = (s + shift + 12) % 12
390 key_shift = { # semitone shifts for key mode names
413 intkey = (ord (k[0]) - ord('a') + 5) % 7
417 if k and k[0] == 'b':
420 elif k and k[0] == '#':
424 if k and key_shift.has_key(k):
425 (intkey, intkeyacc) = shift_key(intkey, intkeyacc, key_shift[k])
426 keytup = (intkey, intkeyacc)
428 sharp_key_seq = sharp_keys ()
429 flat_key_seq = flat_keys ()
433 if keytup in sharp_key_seq:
435 key_count = sharp_key_seq.index (keytup)
436 accseq = map (lambda x: (4*x -1 ) % 7, range (1, key_count + 1))
438 elif keytup in flat_key_seq:
440 key_count = flat_key_seq.index (keytup)
441 accseq = map (lambda x: (3*x + 3 ) % 7, range (1, key_count + 1))
447 key_table[a] = key_table[a] + accsign
462 def try_parse_tuplet_begin (str, state):
463 if re.match ('\([2-9]', str):
466 state.parsing_tuplet = string.atoi (dig[0])
468 voices_append ("\\times %s {" % tup_lookup[dig])
471 def try_parse_group_end (str, state):
472 if str and str[0] in HSPACE:
476 def header_append (key, a):
478 if header.has_key (key):
479 s = header[key] + "\n"
483 linelen = len (v) - string.rfind(v, '\n')
484 if linelen + len (a) > 80:
488 def stuff_append (stuff, idx, a):
492 stuff [idx] = wordwrap(a, stuff[idx])
496 def voices_append(a):
497 if current_voice_idx < 0:
498 select_voice ('default', '')
499 stuff_append (voices, current_voice_idx, a)
501 def repeat_prepend():
503 if current_voice_idx < 0:
504 select_voice ('default', '')
506 repeat_state[current_voice_idx] = 't'
509 def lyrics_append(a):
510 a = re.sub ( '#', '\\#', a) # latex does not like naked #'s
511 a = re.sub ( '"', '\\"', a) # latex does not like naked "'s
512 a = '\t{ \\lyrics "' + a + '" }\n'
513 stuff_append (lyrics, current_lyric_idx, a)
515 # break lyrics to words and put "'s around words containing numbers and '"'s
519 m = re.match('[ \t]*([^ \t]*)[ \t]*(.*$)', str)
523 word = re.sub('"', '\\"', word) # escape "
524 if re.match('.*[0-9"\(]', word):
525 word = re.sub('_', ' ', word) # _ causes probs inside ""
526 ret = ret + '\"' + word + '\" '
528 ret = ret + word + ' '
533 def slyrics_append(a):
534 a = re.sub ( '_', ' _ ', a) # _ to ' _ '
535 a = re.sub ( '-', '- ', a) # split words with -
536 a = re.sub ( '\\\\- ', '-', a) # unless \-
537 a = re.sub ( '~', '_', a) # ~ to space('_')
538 a = re.sub ( '\*', '_ ', a) # * to to space
539 a = re.sub ( '#', '\\#', a) # latex does not like naked #'s
540 if re.match('.*[0-9"\(]', a): # put numbers and " and ( into quoted string
542 a = re.sub ( '$', ' ', a) # insure space between lines
543 __main__.lyric_idx = lyric_idx + 1
544 if len(slyrics[current_voice_idx]) <= lyric_idx:
545 slyrics[current_voice_idx].append(a)
547 v = slyrics[current_voice_idx][lyric_idx]
548 slyrics[current_voice_idx][lyric_idx] = wordwrap(a, slyrics[current_voice_idx][lyric_idx])
551 def try_parse_header_line (ln, state):
552 global length_specified
553 m = re.match ('^([A-Za-z]): *(.*)$', ln)
559 a = re.sub('[ \t]*$','', a) #strip trailing blanks
560 if header.has_key('title'):
562 header['title'] = header['title'] + '\\\\\\\\' + a
567 if not state.common_time:
568 state.common_time = 1
569 voices_append ("\\property Staff.TimeSignature \\override #\'style = #'C\n")
572 if not state.common_time:
573 state.common_time = 1
574 voices_append ("\\property Staff.TimeSignature \\override #\'style = #'C\n")
576 if not length_specified:
577 set_default_len_from_time_sig (a)
580 voices_append ('\\time %s' % a)
585 m = re.match ('^([^ \t]*) *(.*)$', a) # seperate clef info
587 # there may or may not be a space
588 # between the key letter and the mode
589 if key_lookup.has_key(m.group(2)[0:3]):
590 key_info = m.group(1) + m.group(2)[0:3]
591 clef_info = m.group(2)[4:]
593 key_info = m.group(1)
594 clef_info = m.group(2)
595 __main__.global_key = compute_key (key_info)# ugh.
596 voices_append ('\\key %s' % lily_key(key_info))
597 check_clef(clef_info)
599 __main__.global_key = compute_key (a)# ugh.
600 voices_append ('\\key %s \\major' % lily_key(a))
602 header ['footnotes'] = header['footnotes'] + '\\\\\\\\' + a
603 if g == 'O': # Origin
604 header ['origin'] = a
605 if g == 'X': # Reference Number
606 header ['crossRefNumber'] = a
609 if g == 'H': # History
610 header_append ('history', a)
613 if g == 'C': # Composer
614 if header.has_key('composer'):
616 header['composer'] = header['composer'] + '\\\\\\\\' + a
618 header['composer'] = a
620 header ['subtitle'] = a
621 if g == 'L': # Default note length
622 set_default_length (ln)
624 voice = re.sub (' .*$', '', a)
625 rest = re.sub ('^[^ \t]* *', '', a)
627 voices_append(state.next_bar)
629 select_voice (voice, rest)
632 if g == 'w': # vocals
638 # we use in this order specified accidental, active accidental for bar,
639 # active accidental for key
640 def pitch_to_lilypond_name (name, acc, bar_acc, key):
654 return(chr (name + ord('c')) + s)
657 def octave_to_lilypond_quotes (o):
670 while str and str[0] in DIGITS:
671 durstr = durstr + str[0]
676 n =string.atoi (durstr)
680 def duration_to_lilypond_duration (multiply_tup, defaultlen, dots):
682 # (num / den) / defaultlen < 1/base
683 while base * multiply_tup[0] < multiply_tup[1]:
686 if (multiply_tup[0] / multiply_tup[1]) == 2:
688 if (multiply_tup[0] / multiply_tup[1]) == 4:
690 return '%s%s' % ( base, '.'* dots)
695 self.next_articulation = ''
699 self.parsing_tuplet = 0
706 # return (str, num,den,dots)
707 def parse_duration (str, parser_state):
709 den = parser_state.next_den
710 parser_state.next_den = 1
712 (str, num) = parse_num (str)
718 while str[:1] == '/':
722 (str, d) =parse_num (str)
726 den = den * default_len
728 current_dots = parser_state.next_dots
729 parser_state.next_dots = 0
730 if re.match ('[ \t]*[<>]', str):
731 while str[0] in HSPACE:
735 current_dots = current_dots + 1
736 parser_state.next_den = parser_state.next_den * 2
741 parser_state.next_dots = parser_state.next_dots + 1
749 if num % multiplier == 0 and den % f == 0:
750 num = num / multiplier
752 current_dots = current_dots + d
754 return (str, num,den,current_dots)
757 def try_parse_rest (str, parser_state):
758 if not str or str[0] <> 'z' and str[0] <> 'x':
761 __main__.lyric_idx = -1
763 if parser_state.next_bar:
764 voices_append(parser_state.next_bar)
765 parser_state.next_bar = ''
773 (str, num,den,d) = parse_duration (str, parser_state)
774 voices_append ('%s%s' % (rest, duration_to_lilypond_duration ((num,den), default_len, d)))
775 if parser_state.next_articulation:
776 voices_append (parser_state.next_articulation)
777 parser_state.next_articulation = ''
790 'J' : '', # ignore slide
791 'R' : '', # ignore roll
795 def try_parse_articulation (str, state):
796 while str and artic_tbl.has_key(str[:1]):
797 state.next_articulation = state.next_articulation + artic_tbl[str[:1]]
798 if not artic_tbl[str[:1]]:
799 sys.stderr.write("Warning: ignoring `%s'\n" % str[:1] )
805 # s7m2 input doesnt care about spaces
806 if re.match('[ \t]*\(', str):
807 str = string.lstrip (str)
810 while str[:1] =='(' and str[1] not in DIGITS:
811 slur_begin = slur_begin + 1
812 state.next_articulation = state.next_articulation + '('
818 # remember accidental for rest of bar
820 def set_bar_acc(note, octave, acc, state):
823 n_oct = note + octave * 7
824 state.in_acc[n_oct] = acc
826 # get accidental set in this bar or UNDEF if not set
827 def get_bar_acc(note, octave, state):
828 n_oct = note + octave * 7
829 if state.in_acc.has_key(n_oct):
830 return(state.in_acc[n_oct])
834 def clear_bar_acc(state):
835 for k in state.in_acc.keys():
840 # WAT IS ABC EEN ONTZETTENDE PROGRAMMEERPOEP !
841 def try_parse_note (str, parser_state):
860 octave = parser_state.base_octave
861 if str[0] in "ABCDEFG":
862 str = string.lower (str[0]) + str[1:]
867 if str[0] in "abcdefg":
868 notename = (ord(str[0]) - ord('a') + 5)%7
871 return str # failed; not a note!
874 __main__.lyric_idx = -1
876 if parser_state.next_bar:
877 voices_append(parser_state.next_bar)
878 parser_state.next_bar = ''
883 while str[0] == '\'':
887 (str, num,den,current_dots) = parse_duration (str, parser_state)
890 if re.match('[ \t]*\)', str):
891 str = string.lstrip (str)
895 slur_end = slur_end + 1
900 voices_append ('%s' % ')' *slur_end )
902 bar_acc = get_bar_acc(notename, octave, parser_state)
903 pit = pitch_to_lilypond_name(notename, acc, bar_acc, global_key[notename])
904 oct = octave_to_lilypond_quotes (octave)
905 if acc != UNDEF and (acc == global_key[notename] or acc == bar_acc):
909 voices_append ("%s%s%s%s" %
911 duration_to_lilypond_duration ((num,den), default_len, current_dots)))
913 set_bar_acc(notename, octave, acc, parser_state)
914 if parser_state.next_articulation:
915 articulation = articulation + parser_state.next_articulation
916 parser_state.next_articulation = ''
918 voices_append (articulation)
920 if parser_state.parsing_tuplet:
921 parser_state.parsing_tuplet = parser_state.parsing_tuplet - 1
922 if not parser_state.parsing_tuplet:
925 voices_append ('%s' % '(' * slur_begin )
930 def junk_space (str):
931 while str and str[0] in '\t\n ':
937 def try_parse_guitar_chord (str, state):
941 if str[0] == '_' or (str[0] == '^'):
946 while str and str[0] != '"':
952 gc = re.sub('#', '\\#', gc) # escape '#'s
953 state.next_articulation = ("%c\"%s\"" % (position ,gc)) + state.next_articulation
956 def try_parse_escape (str):
957 if not str or str [0] != '\\':
962 key_table = compute_key ()
966 # |] thin-thick double bar line
967 # || thin-thin double bar line
968 # [| thick-thin double bar line
971 # :: left-right repeat
991 '|:' : '\\repeat volta 2 {',
992 '::' : '} \\repeat volta 2 {',
993 '|1' : '} \\alternative{{',
1000 warn_about = ['|:', '::', ':|', '|1', ':|2', '|2']
1001 alternative_opener = ['|1', '|2', ':|2']
1002 repeat_ender = ['::', ':|']
1003 repeat_opener = ['::', '|:']
1004 in_repeat = [''] * 8
1005 doing_alternative = [''] * 8
1008 def try_parse_bar (str,state):
1009 global in_repeat, doing_alternative, using_old
1012 if current_voice_idx < 0:
1013 select_voice ('default', '')
1014 # first try the longer one
1015 for trylen in [3,2,1]:
1016 if str[:trylen] and bar_dict.has_key (str[:trylen]):
1019 bs = "\\bar \"%s\"" % old_bar_dict[s]
1021 bs = "%s" % bar_dict[s]
1023 if s in alternative_opener:
1024 if not in_repeat[current_voice_idx]:
1026 bs = "\\bar \"%s\"" % old_bar_dict[s]
1028 doing_alternative[current_voice_idx] = 't'
1030 if s in repeat_ender:
1031 if not in_repeat[current_voice_idx]:
1032 sys.stderr.write("Warning: inserting repeat to beginning of notes.\n")
1034 in_repeat[current_voice_idx] = ''
1036 if doing_alternative[current_voice_idx]:
1039 bs = "\\bar \"%s\"" % old_bar_dict[s]
1042 doing_alternative[current_voice_idx] = ''
1043 in_repeat[current_voice_idx] = ''
1044 if s in repeat_opener:
1045 in_repeat[current_voice_idx] = 't'
1047 bs = "\\bar \"%s\"" % old_bar_dict[s]
1052 state.next_bar = '|\n'
1054 clear_bar_acc(state)
1056 if bs <> None or state.next_bar != '':
1057 if state.parsing_tuplet:
1058 state.parsing_tuplet =0
1059 voices_append ('} ')
1062 clear_bar_acc(state)
1065 voices_append("} }")
1069 def try_parse_tie (str):
1072 voices_append (' ~ ')
1075 def bracket_escape (str, state):
1076 m = re.match ( '^([^\]]*)] *(.*)$', str)
1080 try_parse_header_line (cmd, state)
1083 def try_parse_chord_delims (str, state):
1086 if re.match('[A-Z]:', str): # bracket escape
1087 return bracket_escape(str, state)
1089 voices_append(state.next_bar)
1095 if state.plus_chord:
1097 state.plus_chord = 0
1100 voices_append(state.next_bar)
1103 state.plus_chord = 1
1111 while str[:1] ==')':
1116 voices_append ("\\spanrequest \\stop \"slur\"" * end)
1120 def try_parse_grace_delims (str, state):
1123 voices_append(state.next_bar)
1126 voices_append ('\\grace { ')
1134 def try_parse_comment (str):
1137 if str[0:5] == '%MIDI':
1138 #the nobarlines option is necessary for an abc to lilypond translator for
1139 #exactly the same reason abc2midi needs it: abc requires the user to enter
1140 #the note that will be printed, and MIDI and lilypond expect entry of the
1141 #pitch that will be played.
1143 #In standard 19th century musical notation, the algorithm for translating
1144 #between printed note and pitch involves using the barlines to determine
1145 #the scope of the accidentals.
1147 #Since ABC is frequently used for music in styles that do not use this
1148 #convention, such as most music written before 1700, or ethnic music in
1149 #non-western scales, it is necessary to be able to tell a translator that
1150 #the barlines should not affect its interpretation of the pitch.
1151 if (string.find(str,'nobarlines') > 0):
1153 elif str[0:3] == '%LY':
1154 p = string.find(str, 'voices')
1156 voices_append(str[p+7:])
1158 p = string.find(str, 'slyrics')
1160 slyrics_append(str[p+8:])
1162 #write other kinds of appending if we ever need them.
1166 def parse_file (fn):
1170 select_voice('default', '')
1172 sys.stderr.write ("Line ... ")
1174 __main__.state = state_list[current_voice_idx]
1179 if not (lineno % happy_count):
1180 sys.stderr.write ('[%d]'% lineno)
1182 m = re.match ('^([^%]*)%(.*)$',ln) # add comments to current voice
1185 try_parse_comment(m.group(2))
1186 voices_append ('%% %s\n' % m.group(2))
1191 ln = try_parse_header_line (ln, state)
1193 # Try nibbling characters off until the line doesn't change.
1195 while ln != prev_ln:
1197 ln = try_parse_chord_delims (ln, state)
1198 ln = try_parse_rest (ln, state)
1199 ln = try_parse_articulation (ln,state)
1200 ln = try_parse_note (ln, state)
1201 ln = try_parse_bar (ln, state)
1202 ln = try_parse_tie (ln)
1203 ln = try_parse_escape (ln)
1204 ln = try_parse_guitar_chord (ln, state)
1205 ln = try_parse_tuplet_begin (ln, state)
1206 ln = try_parse_group_end (ln, state)
1207 ln = try_parse_grace_delims (ln, state)
1208 ln = junk_space (ln)
1211 msg = "%s: %d: Huh? Don't understand\n" % (fn, lineno)
1212 sys.stderr.write (msg)
1213 left = orig_ln[0:-len (ln)]
1214 sys.stderr.write (left + '\n')
1215 sys.stderr.write (' ' * len (left) + ln + '\n')
1219 sys.stderr.write ("%s from LilyPond %s\n" % (program_name, version))
1223 Convert ABC to lilypond.
1225 Usage: abc2ly [OPTIONS]... ABC-FILE
1228 -h, --help this help
1229 -o, --output=FILE set output filename to FILE
1230 -v, --version version information
1232 This program converts ABC music files (see
1233 http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt) To LilyPond input.
1236 def print_version ():
1237 print r"""abc2ly (GNU lilypond) %s""" % version
1241 (options, files) = getopt.getopt (sys.argv[1:], 'vo:h', ['help','version', 'output='])
1247 if o== '--help' or o == '-h':
1250 if o == '--version' or o == '-v':
1254 if o == '--output' or o == '-o':
1262 header['tagline'] = 'Lily was here %s -- automatically converted from ABC' % version
1267 sys.stderr.write ('Parsing `%s\'...\n' % f)
1270 if not out_filename:
1271 out_filename = os.path.basename (os.path.splitext (f)[0]) + ".ly"
1272 sys.stderr.write ('lilypond output to: `%s\'...' % out_filename)
1273 outf = open (out_filename, 'w')
1275 # dump_global (outf)
1276 dump_header (outf ,header)
1281 sys.stderr.write ('\n')