]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/etf2ly.py
* lily/tie-formatting-problem.cc (set_chord_outline): initialize
[lilypond.git] / scripts / etf2ly.py
index 599ddfccb3e101befb84745873ad55c940a93ea0..18a33a4324d1efd8562591e1ba3e1c261e1b10b0 100644 (file)
@@ -38,6 +38,41 @@ program_name = sys.argv[0]
 version = '@TOPLEVEL_VERSION@'
 if version == '@' + 'TOPLEVEL_VERSION' + '@':
        version = '(unknown version)'      # uGUHGUHGHGUGH
+
+
+################################################################
+# Users of python modules should include this snippet.
+#
+libdir = '@local_lilypond_libdir@'
+if not os.path.isdir (libdir):
+        libdir = '@lilypond_libdir@'
+
+# ugh
+datadir = '@local_lilypond_datadir@'
+if os.environ.has_key ('LILYPONDPREFIX'):
+       datadir = os.environ['LILYPONDPREFIX']
+       while datadir[-1] == os.sep:
+               datadir= datadir[:-1]
+       libdir = datadir.replace ('/share/', '/lib/')
+
+if os.path.exists (os.path.join (datadir, 'lib/lilypond/@TOPLEVEL_VERSION@/')):
+       libdir = os.path.join (libdir, 'lib/lilypond/@TOPLEVEL_VERSION@/')
+        
+if os.path.exists (os.path.join (datadir, 'lib/lilypond/current/')):
+       libdir = os.path.join (libdir, 'lib/lilypond/current/')
+        
+sys.path.insert (0, os.path.join (libdir, 'python'))
+
+# dynamic relocation, for GUB binaries.
+bindir = os.path.split (sys.argv[0])[0]
+for p in ['share', 'lib']:
+       datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p)
+       sys.path.insert (0, datadir)
+
+################################################################
+
+import lilylib as ly
+_ = ly._
   
 finale_clefs= ['treble', 'alto', 'tenor', 'bass', 'percussion', 'treble_8', 'bass_8', 'baritone']
 
@@ -109,9 +144,9 @@ have the correct number of accidentals
 # should cache this.
 def find_scale (keysig):
        cscale = map (lambda x: (x,0), range (0,7))
-       print "cscale: ", cscale
+#      print "cscale: ", cscale
        ascale = map (lambda x: (x,0), range (-2,5))
-       print "ascale: ", ascale
+#      print "ascale: ", ascale
        transposition = keysig.pitch
        if keysig.sig_type == 1:
                transposition = transpose(transposition, (2, -1))
@@ -119,7 +154,7 @@ def find_scale (keysig):
                trscale = map(lambda x, k=transposition: transpose(x, k), ascale)
        else:
                trscale = map(lambda x, k=transposition: transpose(x, k), cscale)
-       print "trscale: ", trscale
+#      print "trscale: ", trscale
        return trscale
 
 def EDU_to_duration (edu):
@@ -137,7 +172,7 @@ def EDU_to_duration (edu):
                dots = 2
        return (log, dots)      
 
-def rat_to_lily_duration (rat):
+def rational_to_lily_skip (rat):
        (n,d) = rat
 
        basedur = 1
@@ -395,7 +430,7 @@ class Verse:
                                str = str + ' ' * 4 + line + '\n'
                                line = ''
                        
-               str = """\nverse%s = \\lyricmode {\n %s}\n""" %  (encodeint (self.number - 1) ,str)
+               str = """\nverse%s = \\lyricmode {\n %s }\n""" %  (encodeint (self.number - 1) ,str)
                return str
 
 class KeySignature:
@@ -463,14 +498,19 @@ class Frame:
 
                # do grace notes.
                lastch = None
+               in_grace = 0
                for c in self.chords:
                        if c.grace and (lastch == None or (not lastch.grace)):
                                c.chord_prefix = r'\grace {' + c.chord_prefix
+                               in_grace = 1
                        elif not c.grace and lastch and lastch.grace:
                                lastch.chord_suffix = lastch.chord_suffix + ' } '
-
+                               in_grace = 0
+                               
                        lastch = c
-                       
+
+               if lastch and in_grace:
+                       lastch.chord_suffix += '}' 
 
                
        def dump (self):
@@ -493,7 +533,7 @@ class Frame:
                        sys.stderr.write ("""\nHuh? Going backwards in frame no %d, start/end (%d,%d)""" % (self.number, self.start, self.end))
                        left = (0,1)
                if left[0]:
-                       str = str + rat_to_lily_duration (left)
+                       str = str + rational_to_lily_skip (left)
 
                str = str + '  | \n'
                return str
@@ -570,7 +610,7 @@ class Staff:
                                last_clef = m.clef
                        if e:
                                if gap <> (0,1):
-                                       k = k +' ' + rat_to_lily_duration (gap) + '\n'
+                                       k = k +' ' + rational_to_lily_skip (gap) + '\n'
                                gap = (0,1)
                                k = k + e
                                
@@ -606,7 +646,7 @@ class Staff:
                                if fr:
                                        first_frame = fr
                                        if gap <> (0,1):
-                                               laystr = laystr +'} %s {\n ' % rat_to_lily_duration (gap)
+                                               laystr = laystr +'} %s {\n ' % rational_to_lily_skip (gap)
                                                gap = (0,1)
                                        laystr = laystr + fr.dump ()
                                else:
@@ -618,7 +658,7 @@ class Staff:
                                                        % (self.number, m.number))
                        if first_frame:
                                l = self.layerid (x)
-                               laystr = '%s = { { %s } }\n\n' % (l, laystr)
+                               laystr = '%s = { {  %s } }\n\n' % (l, laystr)
                                str = str  + laystr
                                layerids.append (l)
 
@@ -814,7 +854,7 @@ Return: (value, rest-of-STR)
                        
                return (string.atoi (dec), str)
        else:
-               sys.stderr.write ("Can't convert `%s'\n" % str)
+               sys.stderr.write ("can't convert `%s'\n" % str)
                return (None, str)
 
 
@@ -1126,7 +1166,8 @@ 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 += '\\version "2.3.25"\n'
+                       str = str + '<<\n  %s\n>> } ' % string.join (staffs)
                        
                return str
 
@@ -1145,59 +1186,54 @@ class Etf_file:
 def identify():
        sys.stderr.write ("%s from LilyPond %s\n" % (program_name, version))
 
-def help ():
-       sys.stdout.write("""Usage: etf2ly [OPTIONS]... ETF-FILE
-
-Convert ETF to LilyPond.
-
-Options:
-  -h, --help          print this help
-  -o, --output=FILE   set output filename to FILE
-  -v, --version       show version information
-
-Enigma Transport Format is a format used by Coda Music Technology's
-Finale product. This program will convert a subset of ETF to a
-ready-to-use lilypond file.
+def warranty ():
+       identify ()
+       sys.stdout.write ('''
+Copyright (c) %s by
 
-Report bugs to bug-lilypond@gnu.org.
+  Han-Wen Nienhuys
+  Jan Nieuwenhuizen
 
-Written by  Han-Wen Nienhuys <hanwen@cs.uu.nl>.
+%s
+%s
+''' % ( '2001--2006',
+       _('Distributed under terms of the GNU General Public License.'),
+       _('It comes with NO WARRANTY.')))
 
-""")
 
-def print_version ():
-       sys.stdout.write (r"""etf2ly (GNU lilypond) %s
 
-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--2004 by Han-Wen Nienhuys <hanwen@cs.uu.nl>
-""" % version)
-
-
-
-(options, files) = getopt.getopt (sys.argv[1:], 'vo:h', ['help','version', 'output='])
-out_filename = None
-
-for opt in options:
-       o = opt[0]
-       a = opt[1]
-       if o== '--help' or o == '-h':
-               help ()
+def get_option_parser ():
+       p = ly.get_option_parser (usage='etf2ly [OPTIONS]... ETF-FILE',
+                                 version="etf2ly (LilyPond) @TOPLEVEL_VERSION@",
+                                 description=_("""Enigma Transport Format is a format used by Coda Music Technology's
+Finale product. This program will convert a subset of ETF to a
+ready-to-use lilypond file."""))
+       p.add_option ('-o', '--output', help=_("write output to FILE"),
+                     metavar=_("FILE"),
+                     action='store')
+       p.add_option ('-w', '--warranty', help=_ ("show warranty"),
+                     action='store_true',
+                     ),
+
+       p.add_option_group  ('bugs',
+                            description='''Report bugs via http://post.gmane.org/post.php'''
+                            '''?group=gmane.comp.gnu.lilypond.bugs\n''')
+       return p
+
+def do_options ():
+       opt_parser = get_option_parser()
+       (options,args) = opt_parser.parse_args ()
+       if options.warranty:
+               warranty ()
                sys.exit (0)
-       if o == '--version' or o == '-v':
-               print_version ()
-               sys.exit(0)
-               
-       if o == '--output' or o == '-o':
-               out_filename = a
-       else:
-               print o
-               raise getopt.error
 
+       return (options,args)
+
+(options, files) = do_options()
 identify()
 
+out_filename = options.output
+
 e = None
 for f in files:
        if f == '-':