]> git.donarmstrong.com Git - lilypond.git/commitdiff
Midi2ly: new option: --include-header. Allows titling and customizing.
authorJan Nieuwenhuizen <janneke@gnu.org>
Tue, 1 Mar 2011 13:47:38 +0000 (14:47 +0100)
committerJan Nieuwenhuizen <janneke@gnu.org>
Tue, 1 Mar 2011 13:47:38 +0000 (14:47 +0100)
scripts/midi2ly.py

index af47460a96471092e5d83024374e565976806163..f831123c3e81ba640aa83c8f7b79085ece799b65 100644 (file)
@@ -917,10 +917,10 @@ def convert_midi (in_file, out_file):
     tag = '%% Lily was here -- automatically converted by %s from %s' % ( program_name, in_file)
 
 
-    s = ''
-    s = tag + '\n\\version "2.7.38"\n\n'
-    for i in range (len (tracks)):
-        s = s + dump_track (tracks[i], i)
+    s = tag
+    s += r'''
+\version "2.7.38"
+'''
 
     s += r'''
 \layout {
@@ -932,6 +932,16 @@ def convert_midi (in_file, out_file):
 }
 '''
 
+    for i in global_options.include_header:
+        s += '\n%% included from %(i)s\n' % locals ()
+        s += open (i).read ()
+        if s[-1] != '\n':
+            s += '\n'
+        s += '% end\n'
+
+    for i in range (len (tracks)):
+        s = s + dump_track (tracks[i], i)
+
     s += '\n\\score {\n  <<\n'
 
     i = 0
@@ -975,6 +985,11 @@ def get_option_parser ():
     p.add_option('-h', '--help',
                  action='help',
                  help=_ ('show this help and exit'))
+    p.add_option('-i', '--include-header',
+                 help=_ ('prepend FILE to output'),
+                 action='append',
+                 default=[],
+                 metavar=_ ('FILE'))
     p.add_option('-k', '--key', help=_ ('set key: ALT=+sharps|-flats; MINOR=1'),
           metavar=_ ('ALT[:MINOR]'),
           default='0'),