]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/midi2ly.py
*** empty log message ***
[lilypond.git] / scripts / midi2ly.py
index 7a6c4988ba14922fb9a2a77403076c46bbc10990..a5bb08a11482dd5cc139c5eac356f081e327832f 100644 (file)
@@ -4,7 +4,7 @@
 # 
 # source file of the GNU LilyPond music typesetter
 #
-# (c) 1998--2002  Han-Wen Nienhuys <hanwen@cs.uu.nl>
+# (c) 1998--2004  Han-Wen Nienhuys <hanwen@cs.uu.nl>
 #                 Jan Nieuwenhuizen <janneke@gnu.org>
 
 
@@ -80,7 +80,7 @@ except:
        def _ (s):
                return s
 
-program_name = 'midi2ly'
+program_name = sys.argv[0]
 program_version = '@TOPLEVEL_VERSION@'
 
 errorport = sys.stderr
@@ -91,18 +91,18 @@ verbose_p = 0
 # keep_temp_dir_p = 0
 
 
-help_summary = _ ("Convert MIDI to LilyPond source")
+help_summary = _ ("Convert MIDI to LilyPond source.")
 
 option_definitions = [
        ('', 'a', 'absolute-pitches', _ ("print absolute pitches")),
        (_ ("DUR"), 'd', 'duration-quant', _ ("quantise note durations on DUR")),
        ('', 'e', 'explicit-durations', _ ("print explicit durations")),
-       ('', 'h', 'help', _ ("this help")),
+       ('', 'h', 'help', _ ("print this help")),
        (_ ("ALT[:MINOR]"), 'k', 'key', _ ("set key: ALT=+sharps|-flats; MINOR=1")),
-       (_ ("FILE"), 'o', 'output', _ ("write ouput to FILE")),
+       (_ ("FILE"), 'o', 'output', _ ("write output to FILE")),
        (_ ("DUR"), 's', 'start-quant', _ ("quantise note starts on DUR")),
        (_ ("DUR*NUM/DEN"), 't', 'allow-tuplet', _ ("allow tuplet durations DUR*NUM/DEN")),
-       ('', 'V', 'verbose', _ ("verbose")),
+       ('', 'V', 'verbose', _ ("be verbose")),
        ('', 'v', 'version', _ ("print version number")),
        ('', 'w', 'warranty', _ ("show warranty and copyright")),
        ('', 'x', 'text-lyrics', _ ("treat every text as a lyric")),
@@ -133,14 +133,13 @@ def identify ():
 def warranty ():
        identify ()
        sys.stdout.write ('\n')
-       sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001--2002'))
+       sys.stdout.write (_ ('Copyright (c) %s by') % ' 2001--2004')
        sys.stdout.write ('\n')
        sys.stdout.write ('  Han-Wen Nienhuys')
        sys.stdout.write ('  Jan Nieuwenhuizen')
-       sys.stdout.write ('\n')
-       sys.stdout.write (_ (r'''
-Distributed under terms of the GNU General Public License. It comes with
-NO WARRANTY.'''))
+       sys.stdout.write ('\n\n')
+       sys.stdout.write (_ ("Distributed under terms of the GNU General Public License."))
+        sys.stdout.write (_ ("It comes with NO WARRANTY."))
        sys.stdout.write ('\n')
 
 def progress (s):
@@ -187,9 +186,9 @@ def option_help_str (o):
        if o[1]:
                sh = '-%s' % o[1]
 
-       sep = ' '
+       sep = '  '
        if o[1] and o[2]:
-               sep = ','
+               sep = ', '
                
        long = ''
        if o[2]:
@@ -221,7 +220,7 @@ def options_help_str (opts):
        return str
 
 def help ():
-       ls = [(_ ("Usage: %s [OPTION]... FILE") % program_name),
+       ls = [(_ ("Usage: %s [OPTIONS]... FILE") % program_name),
                ('\n\n'),
                (help_summary),
                ('\n\n'),
@@ -229,7 +228,7 @@ def help ():
                ('\n'),
                (options_help_str (option_definitions)),
                ('\n\n'),
-               (_ ("Report bugs to %s") % 'bug-lilypond@gnu.org'),
+               (_ ("Report bugs to %s.") % 'bug-lilypond@gnu.org'),
                ('\n')]
        map (sys.stdout.write, ls)
        
@@ -785,14 +784,14 @@ def dump_chord (ch):
                s = s + dump (notes[0])
        elif len (notes) > 1:
                global reference_note
-               s = s + '<<'
+               s = s + '<'
                s = s + notes[0].dump (dump_dur = 0)
                r = reference_note
                for i in notes[1:]:
                        s = s + i.dump (dump_dur = 0 )
-               s = s + '>>'
+               s = s + '>'
 
-               s = s + notes[0].duration.dump()
+               s = s + notes[0].duration.dump() + ' '
                reference_note = r
        return s
 
@@ -892,21 +891,20 @@ def dump_track (channels, n):
 
                if item and item.__class__ == Note:
                        skip = 's'
-                       s = s + '%s = \\notes' % (track + channel)
+                       s = s + '%s = ' % (track + channel)
                        if not absolute_p:
                                s = s + '\\relative c '
                elif item and item.__class__ == Text:
                        skip = '" "'
-                       s = s + '%s = \\lyrics ' % (track + channel)
+                       s = s + '%s = \\lyricmode ' % (track + channel)
                else:
                        skip = '\\skip '
-                       # must be in \notes mode for parsing \skip
-                       s = s + '%s = \\notes ' % (track + channel)
+                       s = s + '%s =  ' % (track + channel)
                s = s + '{\n'
                s = s + '  ' + dump_channel (channels[i][0], skip)
                s = s + '}\n\n'
 
-       s = s + '%s = <\n' % track
+       s = s + '%s = <<\n' % track
 
        if clef.type != 2:
                s = s + clef.dump () + '\n'
@@ -920,7 +918,7 @@ def dump_track (channels, n):
                else:
                        s = s + '  \\context Voice = %s \\%s\n' % (channel,
                                                                   track + channel)
-       s = s + '>\n\n'
+       s = s + '>>\n\n'
        return s
 
 def thread_first_item (thread):
@@ -984,12 +982,13 @@ def convert_midi (f, o):
 
        tag = '%% Lily was here -- automatically converted by %s from %s' % ( program_name, f)
 
+        
        s = ''
-       s = tag + '\n\n'
+       s = tag + '\n\\version "2.3.25"\n\n'
        for i in range (len (tracks)):
                s = s + dump_track (tracks[i], i)
 
-       s = s + '\n\\score {\n  <\n'
+       s = s + '\n\\score {\n  <<\n'
        for i in range (len (tracks)):
                track = track_name (i)
                item = track_first_item (tracks[i])
@@ -997,7 +996,7 @@ def convert_midi (f, o):
                        s = s + '    \\context Staff=%s \\%s\n' % (track, track)
                elif item and item.__class__ == Text:
                        s = s + '    \\context Lyrics=%s \\%s\n' % (track, track)
-       s = s + '  >\n}\n'
+       s = s + '  >>\n}\n'
 
        progress (_ ("%s output to `%s'...") % ('LY', o))
 
@@ -1085,7 +1084,6 @@ if not files or files[0] == '-':
 
 
 for f in files:
-
        g = f
        g = strip_extension (g, '.midi')
        g = strip_extension (g, '.mid')