]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/etf2ly.py
increase extent of Staff.
[lilypond.git] / scripts / etf2ly.py
index c1767db5b8bb9930b6d9ad46a5b7e2d077dd6bdd..c4627a611d41efca94e003d30a0bdae7e8f174d0 100644 (file)
 #
 
 
-program_name = 'etf2ly'
-version = '@TOPLEVEL_VERSION@'
-if version == '@' + 'TOPLEVEL_VERSION' + '@':
-       version = '(unknown version)'      # uGUHGUHGHGUGH
-  
 import __main__
 import getopt
 import sys
@@ -38,6 +33,12 @@ import re
 import string
 import os
 
+program_name = sys.argv[0]
+
+version = '@TOPLEVEL_VERSION@'
+if version == '@' + 'TOPLEVEL_VERSION' + '@':
+       version = '(unknown version)'      # uGUHGUHGHGUGH
+  
 finale_clefs= ['treble', 'alto', 'tenor', 'bass', 'percussion', 'treble_8', 'bass_8', 'baritone']
 
 def lily_clef (fin):
@@ -97,17 +98,30 @@ have the correct number of accidentals
                while accidental_bits < 256:
                        p = transpose (p, (3,0))
                        accidental_bits = accidental_bits + 1
-                       
+
+       if bank_number == 1:
+               # minor scale
+               p = transpose (p, (5, 0))
        p  = (p[0] % 7, p[1])
 
-       return p
+       return KeySignature (p, bank_number)
 
 # should cache this.
-def find_scale (transposition):
+def find_scale (keysig):
        cscale = map (lambda x: (x,0), range (0,7))
-       trscale = map(lambda x, k=transposition: transpose(x, k), cscale)
-
+       print "cscale: ", cscale
+       ascale = map (lambda x: (x,0), range (-2,5))
+       print "ascale: ", ascale
+       transposition = keysig.pitch
+       if keysig.sig_type == 1:
+               transposition = transpose(transposition, (2, -1))
+               transposition = (transposition[0] % 7, transposition[1])
+               trscale = map(lambda x, k=transposition: transpose(x, k), ascale)
+       else:
+               trscale = map(lambda x, k=transposition: transpose(x, k), cscale)
+       print "trscale: ", trscale
        return trscale
+
 def EDU_to_duration (edu):
        log = 1
        d = 4096
@@ -381,10 +395,28 @@ class Verse:
                                str = str + ' ' * 4 + line + '\n'
                                line = ''
                        
-               str = """\nverse%s = \\lyrics {\n %s}\n""" %  (encodeint (self.number - 1) ,str)
+               str = """\nverse%s = \\lyricmode {\n %s}\n""" %  (encodeint (self.number - 1) ,str)
                return str
 
+class KeySignature:
+       def __init__(self, pitch, sig_type = 0):
+               self.pitch = pitch
+               self.sig_type = sig_type
        
+       def signature_type (self):
+               if self.sig_type == 1:
+                       return "\\minor"
+               else:
+                       # really only for 0, but we only know about 0 and 1
+                       return "\\major"
+       
+       def equal (self, other):
+               if other and other.pitch == self.pitch and other.sig_type == self.sig_type:
+                       return 1
+               else:
+                       return 0
+       
+
 class Measure:
        def __init__(self, no):
                self.number = no
@@ -502,9 +534,10 @@ class Staff:
                        e = ''
                        
                        if g:
-                               if last_key <> g.key_signature:
-                                       pitch= g.key_signature                                  
-                                       e = e + "\\key %s \\major " % (lily_notename (pitch))
+                               if g.key_signature and not g.key_signature.equal(last_key):
+                                       pitch= g.key_signature.pitch
+                                       e = e + "\\key %s %s " % (lily_notename (pitch),
+                                                                 g.key_signature.signature_type())
                                        
                                        last_key = g.key_signature
                                if last_time <> g.timesig :
@@ -527,7 +560,7 @@ class Staff:
 
                                        str = string.join (map (lambda x: '(volta %s)' % x, strs))
                                        
-                                       e = e + ' \\property Score.repeatCommands =  #\'(%s) ' % str
+                                       e = e + ' \\set Score.repeatCommands =  #\'(%s) ' % str
 
                                if g.force_break:
                                        e = e + ' \\break '  
@@ -595,7 +628,7 @@ class Staff:
                        stafdef = stafdef + ' \\' + i
                        
 
-               str = str + '%s = \\context Staff = %s <\n %s\n >\n' % \
+               str = str + '%s = \\context Staff = %s <<\n %s\n >>\n' % \
                      (self.staffid (), self.staffid (), stafdef)
                return str
 
@@ -726,7 +759,7 @@ class Chord:
                if not self.pitches:
                        s  = 'r'
                if len (self.pitches) > 1:
-                       s = '<< %s >>' % s
+                       s = '<%s>' % s
 
                s = s + '%d%s' % (self.duration[0], '.'* self.duration[1])
                s = self.note_prefix + s + self.note_suffix
@@ -1093,7 +1126,7 @@ class Etf_file:
                        sys.stderr.write ("\nLyrics found; edit to use \\addlyrics to couple to a staff\n")
                        
                if staffs:
-                       str = str + '\\score { < %s > } ' % string.join (staffs)
+                       str = str + '\\score { << %s >> } ' % string.join (staffs)
                        
                return str
 
@@ -1139,7 +1172,7 @@ This is free software.  It is covered by the GNU General Public License,
 and you are welcome to change it and/or distribute copies of it under
 certain conditions.  Invoke as `midi2ly --warranty' for more information.
 
-Copyright (c)  2000--2003 by Han-Wen Nienhuys <hanwen@cs.uu.nl>
+Copyright (c) 2000--2004 by Han-Wen Nienhuys <hanwen@cs.uu.nl>
 """ % version)