]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/abc2ly.py
(sarabandeA):
[lilypond.git] / scripts / abc2ly.py
index 6428e0f1054aa4fb6ff2cbc6062da1b4a01c10fd..bde1e8cfe553a89982ab2ad3cc1af47ed1ceca09 100644 (file)
@@ -32,7 +32,8 @@
 # the default placement for text in abc is above the staff.
 # %%LY now supported.
 # \breve and \longa supported.
-                       
+# M:none doesn't crash lily.
+
 # Limitations
 #
 # Multiple tunes in single file not supported
 
 
 #TODO:
+#
+# Convert to new chord styles.
+#
 # UNDEF -> None
+#
   
   
 program_name = 'abc2ly'
@@ -163,19 +167,23 @@ def dump_header (outf,hdr):
        ks = hdr.keys ()
        ks.sort ()
        for k in ks:
+               hdr[k] = re.sub('"', '\\"', hdr[k])             
                outf.write ('\t%s = "%s"\n'% (k,hdr[k]))
        outf.write ('}')
 
 def dump_lyrics (outf):
        if (len(lyrics)):
-               outf.write("\n\\score\n{\n    \\context Lyrics\n    <\n")
+               outf.write("\n\\score\n{\n    \\context Lyrics\n    <<\n")
                for i in range (len (lyrics)):
                        outf.write ( lyrics [i])
                        outf.write ("\n")
-               outf.write("    >\n    \\paper{}\n}\n")
+               outf.write("    >>\n    \\paper{}\n}\n")
 
 def dump_default_bar (outf):
-       outf.write ("\n\\property Score.defaultBarType=\"empty\"\n")
+       """
+       Nowadays abc2ly outputs explicits barlines (?)
+       """
+       outf.write ("\n\\property Score.defaultBarType=\"empty\"\n")
 
 
 def dump_slyrics (outf):
@@ -225,14 +233,14 @@ def try_parse_q(a):
                array2=string.split(array[1],'=')
                denominator=array2[0]
                perminute=array2[1]
-               duration=str(string.atof(denominator)/string.atoi(numerator))
+               duration=str(string.atoi(denominator)/string.atoi(numerator))
                midi_specs=string.join(["\\tempo", duration, "=", perminute])
        else:
                sys.stderr.write("abc2ly: Warning, unable to parse Q specification: %s\n" % a)
         
 def dump_score (outf):
        outf.write (r"""\score{
-        \notes <
+        \notes <<
 """)
 
        ks  = voice_idx_dict.keys ();
@@ -252,7 +260,7 @@ def dump_score (outf):
                outf.write ("\t    \\voice%s " % m)
                outf.write ("\n\t}\n")
                if len ( slyrics [voice_idx_dict[k]] ):
-                       outf.write ("\n\t\\context Lyrics=\"%s\" \n\t<\t" % k)
+                       outf.write ("\n\t\\context Lyrics=\"%s\" \n\t<<\t" % k)
                        if re.match('[1-9]',k):
                                m = alphabet[string.atoi(k)]
                        else:
@@ -260,8 +268,8 @@ def dump_score (outf):
                        for i in range (len(slyrics[voice_idx_dict[k]])):
                                l=alphabet[i]
                                outf.write("\n\t  { \\words%sV%s }" % ( m, l) )
-                       outf.write ( "\n\t>\n" )
-       outf.write ("\n    >")
+                       outf.write ( "\n\t>>\n" )
+       outf.write ("\n    >>")
        outf.write ("\n\t\\paper {\n")
        if part_names:
                outf.write ("\t    \\translator \n\t    {\n")
@@ -489,8 +497,10 @@ def try_parse_tuplet_begin (str, state):
        if re.match ('\([2-9]', str):
                dig = str[1]
                str = str[2:]
-               state.parsing_tuplet = string.atoi (dig[0])
-               
+               prev_tuplet_state = state.parsing_tuplet
+               state.parsing_tuplet = string.atoi (dig[0])
+               if prev_tuplet_state:
+                       voices_append ("}")             
                voices_append ("\\times %s {" % tup_lookup[dig])
        return str
 
@@ -585,7 +595,10 @@ def try_parse_header_line (ln, state):
                        a = re.sub('[ \t]*$','', a)     #strip trailing blanks
                        if header.has_key('title'):
                                if a:
-                                       header['title'] = header['title'] + '\\\\\\\\' + a
+                                       if len(header['title']):
+                                               header['title'] = header['title'] + '\\\\\\\\' + a
+                                       else:
+                                               header['subtitle'] = a
                        else:
                                header['title'] =  a
                if g == 'M':    # Meter
@@ -603,7 +616,8 @@ def try_parse_header_line (ln, state):
                                set_default_len_from_time_sig (a)
                        else:
                                length_specified = 0
-                       voices_append ('\\time %s' % a)
+                       if not a == 'none':
+                               voices_append ('\\time %s' % a)
                        state.next_bar = ''
                if g == 'K': # KEY
                        a = check_clef(a)
@@ -712,6 +726,9 @@ def duration_to_lilypond_duration  (multiply_tup, defaultlen, dots):
        if base == 1:
                if (multiply_tup[0] / multiply_tup[1])  == 2:
                        base = '\\breve'
+               if (multiply_tup[0] / multiply_tup[1]) == 3:
+                       base = '\\breve'
+                       dots = 1
                if (multiply_tup[0] / multiply_tup[1]) == 4:
                        base = '\longa'
        return '%s%s' % ( base, '.'* dots)
@@ -913,7 +930,6 @@ def try_parse_note (str, parser_state):
 
        (str, num,den,current_dots) = parse_duration (str, parser_state)
 
-
        if re.match('[ \t]*\)', str):
                str = string.lstrip (str)
        
@@ -923,9 +939,6 @@ def try_parse_note (str, parser_state):
                str = str[1:]
 
        
-       if slur_end:
-               voices_append ('%s' % ')' *slur_end )
-
        bar_acc = get_bar_acc(notename, octave, parser_state)
        pit = pitch_to_lilypond_name(notename, acc, bar_acc, global_key[notename])
        oct = octave_to_lilypond_quotes (octave)
@@ -949,7 +962,10 @@ def try_parse_note (str, parser_state):
                if not parser_state.parsing_tuplet:
                        voices_append ("}")
        if slur_begin:
-               voices_append ('%s' % '(' * slur_begin )
+               voices_append ('-(' * slur_begin )
+       if slur_end:
+               voices_append ('-)' *slur_end )
+
 
 
        return str
@@ -1251,13 +1267,19 @@ Convert ABC to lilypond.
 Usage: abc2ly [OPTIONS]... ABC-FILE
 
 Options:
-  -h, --help          this help
+  -h, --help          print this help
   -o, --output=FILE   set output filename to FILE
-  -v, --version       version information
-  -s, --strict        be strict about succes.
+  -v, --version       show version information
+  -s, --strict        be strict about succes
   
 This program converts ABC music files (see
-http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt) To LilyPond input.
+http://www.gre.ac.uk/~c.walshaw/abc2mtex/abc.txt) to LilyPond input.
+
+
+Report bugs to bug-lilypond@gnu.org.
+
+Written by Han-Wen Nienhuys <hanwen@cs.uu.nl>, Laura Conrad
+<lconrad@laymusic.org>, Roy Rankin <Roy.Rankin@@alcatel.com.au>.
 """
 
 def print_version ():