]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/abc2ly.py
(add_columns): also compare
[lilypond.git] / scripts / abc2ly.py
index 943cc94b3b821e64192db3c27a9fb34395f961c4..91344b1934b294e1849fe7bb4c79b0970ad712ad 100644 (file)
 # UNDEF -> None
 #
   
-  
-program_name = 'abc2ly'
-version = '@TOPLEVEL_VERSION@'
-if version == '@' + 'TOPLEVEL_VERSION' + '@':
-       version = '(unknown version)'           # uGUHGUHGHGUGH
-  
+
 import __main__
 import getopt
 import sys
@@ -79,6 +74,11 @@ import re
 import string
 import os
 
+program_name = sys.argv[0]
+
+version = '@TOPLEVEL_VERSION@'
+if version == '@' + 'TOPLEVEL_VERSION' + '@':
+       version = '(unknown version)'           # uGUHGUHGHGUGH  
 
 UNDEF = 255
 state = UNDEF
@@ -102,7 +102,6 @@ nobarlines = 0
 global_key = [0] * 7                   # UGH
 names = ["One", "Two", "Three"]
 DIGITS='0123456789'
-alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"  
 HSPACE=' \t'
 midi_specs = ''
 
@@ -112,6 +111,9 @@ def error (msg):
        if strict:
                sys.exit (1)
        
+
+def alphabet (i):
+       return chr (i + ord('A'))
        
 def check_clef(s):
        if not s:
@@ -163,10 +165,12 @@ def select_voice (name, rol):
                                        check_clef(value)
                                elif keyword == "name":
                                        value = re.sub ('\\\\','\\\\\\\\', value)
-                                       voices_append ("\\property Staff.instrument = %s\n" % value )
+                                       ## < 2.2
+                                       voices_append ("\\set Staff.instrument = %s\n" % value )
+                                       
                                        __main__.part_names = 1
                                elif keyword == "sname" or keyword == "snm":
-                                       voices_append ("\\property Staff.instr = %s\n" % value )
+                                       voices_append ("\\set Staff.instr = %s\n" % value )
                else:
                        break
 
@@ -181,17 +185,18 @@ def dump_header (outf,hdr):
 
 def dump_lyrics (outf):
        if (len(lyrics)):
-               outf.write("\n\\score\n{\n    \\context Lyrics\n    <<\n")
+               outf.write("\n\\score\n{\n \\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    \\layout{}\n}\n")
 
 def dump_default_bar (outf):
        """
        Nowadays abc2ly outputs explicits barlines (?)
        """
-       outf.write ("\n\\property Score.defaultBarType=\"empty\"\n")
+       ## < 2.2
+       outf.write ("\n\\set Score.defaultBarType = \"empty\"\n")
 
 
 def dump_slyrics (outf):
@@ -199,12 +204,12 @@ def dump_slyrics (outf):
        ks.sort ()
        for k in ks:
                if re.match('[1-9]', k):
-                       m = alphabet[string.atoi(k)]
+                       m = alphabet(string.atoi(k))
                else:
                        m = k
                for i in range (len(slyrics[voice_idx_dict[k]])):
-                       l=alphabet[i]
-                       outf.write ("\nwords%sV%s = \\lyrics  {" % (m, l))
+                       l= alphabet(i)
+                       outf.write ("\nwords%sV%s = \lyricmode {" % (m, l))
                        outf.write ("\n" + slyrics [voice_idx_dict[k]][i])
                        outf.write ("\n}")
 
@@ -214,10 +219,10 @@ def dump_voices (outf):
        ks.sort ()
        for k in ks:
                if re.match ('[1-9]', k):
-                       m = alphabet[string.atoi(k)]
+                       m = alphabet(string.atoi(k))
                else:
                        m = k
-               outf.write ("\nvoice%s = \\notes {" % m)
+               outf.write ("\nvoice%s =  {" % m)
                dump_default_bar(outf)
                if repeat_state[voice_idx_dict[k]]:
                        outf.write("\n\\repeat volta 2 {")
@@ -247,38 +252,40 @@ def try_parse_q(a):
                sys.stderr.write("abc2ly: Warning, unable to parse Q specification: %s\n" % a)
         
 def dump_score (outf):
-       outf.write (r"""\score{
-        \notes <<
+       outf.write (r"""
+
+\score{
+         <<
 """)
 
        ks = voice_idx_dict.keys ();
        ks.sort ()
        for k in  ks:
                if re.match('[1-9]', k):
-                       m = alphabet[string.atoi(k)]
+                       m = alphabet (string.atoi(k))
                else:
                        m = k
                if k == 'default' and len (voice_idx_dict) > 1:
                        break
-               if len ( slyrics [voice_idx_dict[k]] ):
-                       outf.write ("\n        \\addlyrics")
                outf.write ("\n\t\\context Staff=\"%s\"\n\t{\n" %k ) 
                if k != 'default':
                        outf.write ("\t    \\voicedefault\n")
                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)
+
+               l = ord( 'A' )
+               for lyrics in slyrics [voice_idx_dict[k]]:
+                       outf.write ("\n\t\\addlyrics { \n")
                        if re.match('[1-9]',k):
-                               m = alphabet[string.atoi(k)]
+                               m = alphabet (string.atoi(k))
                        else:
                                m = k
-                       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 ( " \\words%sV%s } " % ( m, chr (l)) )
+                       l += 1
+
        outf.write ("\n    >>")
-       outf.write ("\n\t\\paper {\n")
+       outf.write ("\n\t\\layout {\n")
        if part_names:
                outf.write ("\t    \\translator \n\t    {\n")
                outf.write ("\t\t\\StaffContext\n")
@@ -576,9 +583,9 @@ 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{ \\lyrics "' + a + '" }\n'
+       a = re.sub ('#', '\\#', a)      # latex does not like naked #'s
+       a = re.sub ('"', '\\"', a)      # latex does not like naked "'s
+       a = '\t{  "' + a + '" }\n'
        stuff_append (lyrics, current_lyric_idx, a)
 
 # break lyrics to words and put "'s around words containing numbers and '"'s
@@ -638,12 +645,12 @@ def try_parse_header_line (ln, state):
                        if a == 'C':
                                if not state.common_time:
                                        state.common_time = 1
-                                       voices_append ("\\property Staff.TimeSignature \\override #\'style = #'C\n")
+                                       voices_append (" \\override Staff.TimeSignature #\'style = #'C\n")
                                a = '4/4'
                        if a == 'C|':
                                if not state.common_time:
                                        state.common_time = 1
-                                       voices_append ("\\property Staff.TimeSignature \\override #\'style = #'C\n")
+                                       voices_append ("\\override Staff.TimeSignature #\'style = #'C\n")
                                a = '2/2'
                        if not length_specified:
                                set_default_len_from_time_sig (a)
@@ -1184,18 +1191,18 @@ def try_parse_chord_delims (str, state):
                if state.next_bar:
                        voices_append(state.next_bar)
                        state.next_bar = ''
-               voices_append ('<')
+               voices_append ('<<')
 
        if str[:1] == '+':
                str = str[1:]
                if state.plus_chord:
-                       voices_append ('>')
+                       voices_append ('>>')
                        state.plus_chord = 0
                else:
                        if state.next_bar:
                                voices_append(state.next_bar)
                                state.next_bar = ''
-                       voices_append ('<')
+                       voices_append ('<<')
                        state.plus_chord = 1
 
        ch = ''
@@ -1381,6 +1388,8 @@ for f in files:
        sys.stderr.write ('lilypond output to: `%s\'...' % out_filename)
        outf = open (out_filename, 'w')
 
+       outf.write ('\\version "2.3.25"\n')
+
 #      dump_global (outf)
        dump_header (outf, header)
        dump_slyrics (outf)