]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/abc2ly.py
Add '-dcrop' option to ps and svg backends
[lilypond.git] / scripts / abc2ly.py
index 3a0aeaedabe7776a610acbc087b358a80bab3e90..e6e0d12407e4ed53006ee529da85f55f7ac7dbab 100644 (file)
@@ -222,18 +222,18 @@ def dump_header (outf,hdr):
 
 def dump_lyrics (outf):
     if (len(lyrics)):
-        outf.write("\n\\score\n{\n \\lyrics\n <<\n")
+        outf.write("\n\\markup \\column {\n")
         for i in range (len (lyrics)):
-            outf.write ( lyrics [i])
+            outf.write (lyrics [i])
             outf.write ("\n")
-        outf.write("    >>\n    \\layout{}\n}\n")
+        outf.write("}\n")
 
 def dump_default_bar (outf):
     """
     Nowadays abc2ly outputs explicits barlines (?)
     """
     ## < 2.2
-    outf.write ("\n\\set Score.defaultBarType = \"empty\"\n")
+    outf.write ("\n\\set Score.defaultBarType = \"\"\n")
 
 
 def dump_slyrics (outf):
@@ -284,7 +284,15 @@ def try_parse_q(a):
         dur = duration_to_lilypond_duration ((numerator,denominator), 1, 0)
         voices_append ("\\tempo " + descr + " " + dur + "=" + tempo + "\n")
     else:
-        sys.stderr.write("abc2ly: Warning, unable to parse Q specification: %s\n" % a)
+        # Parsing of numeric tempi, as these are fairly
+        # common.  The spec says the number is a "beat" so using
+        # a quarter note as the standard time
+        numericQ = re.compile ('[0-9]+')
+        m = numericQ.match (a)
+        if m:
+            voices_append ("\\tempo 4=" + m.group(0))
+        else:
+            sys.stderr.write("abc2ly: Warning, unable to parse Q specification: %s\n" % a)
 
 def dump_score (outf):
     outf.write (r"""
@@ -433,6 +441,8 @@ key_lookup = {         # abc to lilypond key mode names
 }
 
 def lily_key (k):
+    if k == 'none':
+        return
     orig = "" + k
     # UGR
     k = k.lower ()
@@ -615,7 +625,7 @@ def repeat_prepend():
 def lyrics_append(a):
     a = re.sub ('#', '\\#', a)        # latex does not like naked #'s
     a = re.sub ('"', '\\"', a)        # latex does not like naked "'s
-    a = '\t{  "' + a + '" }\n'
+    a = '  \\line { "' + a + '" }\n'
     stuff_append (lyrics, current_lyric_idx, a)
 
 # break lyrics to words and put "'s around words containing numbers and '"'s
@@ -751,8 +761,12 @@ def try_parse_header_line (ln, state):
             lyrics_append(a)
         if g == 'w':        # vocals
             slyrics_append (a)
-        if g == 'Q':    #tempo
+        if g == 'Q':        # tempo
             try_parse_q (a)
+        if g == 'R':        # Rhythm (e.g. jig, reel, hornpipe)
+            header['meter'] = a
+        if g == 'Z':        # Transcription (e.g. Steve Mansfield 1/2/2000)
+            header['transcription'] = a
         return ''
     return ln
 
@@ -1114,12 +1128,12 @@ old_bar_dict = {
 '|]' : '|.',
 '||' : '||',
 '[|' : '||',
-':|' : ':|',
+':|' : ':|.',
 '|:' : '|:',
-'::' : ':|:',
+'::' : ':|.|:',
 '|1' : '|',
 '|2' : '|',
-':|2' : ':|',
+':|2' : ':|.',
 '|' :  '|'
 }
 bar_dict = {
@@ -1193,6 +1207,9 @@ def try_parse_bar (str,state):
         clear_bar_acc(state)
         close_beam_state(state)
 
+    if str[:1] == '}':
+        close_beam_state(state)
+
     if bs <> None or state.next_bar != '':
         if state.parsing_tuplet:
             state.parsing_tuplet =0
@@ -1313,8 +1330,9 @@ def parse_file (fn):
     select_voice('default', '')
     global lineno
     lineno = 0
-    sys.stderr.write ("Line ... ")
-    sys.stderr.flush ()
+    if not global_options.quiet:
+        sys.stderr.write ("Line ... ")
+        sys.stderr.flush ()
     __main__.state = state_list[current_voice_idx]
 
     for ln in ls:
@@ -1360,7 +1378,8 @@ def parse_file (fn):
 
 
 def identify():
-    sys.stderr.write ("%s from LilyPond %s\n" % (program_name, version))
+    if not global_options.quiet:
+        sys.stderr.write ("%s from LilyPond %s\n" % (program_name, version))
 
 authors = """
 Written by Han-Wen Nienhuys <hanwen@xs4all.nl>, Laura Conrad
@@ -1381,16 +1400,21 @@ def get_option_parser ():
     p.add_option("--version",
                  action="version",
                  help=_ ("show version number and exit"))
-
     p.add_option("-h", "--help",
                  action="help",
                  help=_ ("show this help and exit"))
-    p.add_option ('-o', '--output', metavar='FILE',
-                  help=_ ("write output to FILE"),
-                  action='store')
-    p.add_option ('-s', '--strict', help=_ ("be strict about success"),
-                  action='store_true')
-    p.add_option ('-b', '--beams', help=_ ("preserve ABC's notion of beams"), action="store_true")
+    p.add_option ("-o", "--output", metavar='FILE',
+                  action="store",
+                  help=_ ("write output to FILE"))
+    p.add_option ("-s", "--strict",
+                  action="store_true",
+                  help=_ ("be strict about success"))
+    p.add_option ('-b', '--beams',
+                  action="store_true",
+                  help=_ ("preserve ABC's notion of beams"))
+    p.add_option ('-q', '--quiet',
+                  action="store_true",
+                  help=_ ("suppress progress messages"))
     p.add_option_group ('',
                         description=(
             _ ('Report bugs via %s')
@@ -1410,12 +1434,14 @@ for f in files:
     if f == '-':
         f = ''
 
-    sys.stderr.write ('Parsing `%s\'...\n' % f)
+    if not global_options.quiet:
+        sys.stderr.write ('Parsing `%s\'...\n' % f)
     parse_file (f)
 
     if not global_options.output:
         global_options.output = os.path.basename (os.path.splitext (f)[0]) + ".ly"
-    sys.stderr.write ('lilypond output to: `%s\'...' % global_options.output)
+    if not global_options.quiet:
+        sys.stderr.write ('lilypond output to: `%s\'...' % global_options.output)
     outf = open (global_options.output, 'w')
 
 # don't substitute @VERSION@. We want this to reflect
@@ -1428,4 +1454,5 @@ for f in files:
     dump_voices (outf)
     dump_score (outf)
     dump_lyrics (outf)
-    sys.stderr.write ('\n')
+    if not global_options.quiet:
+        sys.stderr.write ('\n')