]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/musicxml2ly.py
Merge master into nested-bookparts
[lilypond.git] / scripts / musicxml2ly.py
index 22f78523754131cca185450ff076ce901ae72d35..6cdd72e430996ba47c1f58fd9ac3db68d941e283 100644 (file)
@@ -55,24 +55,23 @@ additional_definitions = {
             '(-0.1 . 0.1) '(0.1 . 1)))
         0.7 X))))""",
   "eyeglasses": """eyeglassesps = #"0.15 setlinewidth
-% 255 0 0 setrgbcolor
--0.9 0 translate
-1.1 1.1 scale
-1.2 0.7 moveto
-0.7 0.7 0.5 0 361 arc
-stroke
-2.20 0.70 0.50 0 361 arc
-stroke
-1.45 0.85 0.30 0 180 arc
-stroke
-0.20 0.70 moveto
-0.80 2.00 lineto
-0.92 2.26 1.30 2.40 1.15 1.70 curveto
-stroke
-2.70 0.70 moveto
-3.30 2.00 lineto
-3.42 2.26 3.80 2.40 3.65 1.70 curveto
-stroke"
+      -0.9 0 translate
+      1.1 1.1 scale
+      1.2 0.7 moveto
+      0.7 0.7 0.5 0 361 arc
+      stroke
+      2.20 0.70 0.50 0 361 arc
+      stroke
+      1.45 0.85 0.30 0 180 arc
+      stroke
+      0.20 0.70 moveto
+      0.80 2.00 lineto
+      0.92 2.26 1.30 2.40 1.15 1.70 curveto
+      stroke
+      2.70 0.70 moveto
+      3.30 2.00 lineto
+      3.42 2.26 3.80 2.40 3.65 1.70 curveto
+      stroke"
 eyeglasses =  \markup { \with-dimensions #'(0 . 4.4) #'(0 . 2.5) \postscript #eyeglassesps }"""
 }
 
@@ -1054,7 +1053,7 @@ def musicxml_words_to_lily_event (words):
             "medium": '',
             "large": '\\large',
             "x-large": '\\huge',
-            "xx-large": '\\bigger\\huge'
+            "xx-large": '\\larger\\huge'
         }.get (size, '')
         if font_size:
             event.markup += font_size
@@ -1158,6 +1157,21 @@ def musicxml_rehearsal_to_ly_mark (mxl_event):
     ev = musicexp.MarkEvent ("\\markup { %s }" % text)
     return ev
 
+def musicxml_harp_pedals_to_ly (mxl_event):
+    count = 0
+    result = "\\harp-pedal #\""
+    for t in mxl_event.get_named_children ('pedal-tuning'):
+      alter = t.get_named_child ('pedal-alter')
+      if alter:
+        val = int (alter.get_text ().strip ())
+        result += {1: "v", 0: "-", -1: "^"}.get (val, "")
+      count += 1
+      if count == 3:
+        result += "|"
+    ev = musicexp.MarkupEvent ()
+    ev.contents = result + "\""
+    return ev
+
 def musicxml_eyeglasses_to_ly (mxl_event):
     needed_additional_definitions.append ("eyeglasses")
     return musicexp.MarkEvent ("\\eyeglasses")
@@ -1223,7 +1237,7 @@ directions_dict = {
 #     'damp' : ???
 #     'damp-all' : ???
     'eyeglasses': musicxml_eyeglasses_to_ly,
-#     'harp-pedals' : ???
+    'harp-pedals' : musicxml_harp_pedals_to_ly,
 #     'image' : ???
     'metronome' : musicxml_metronome_to_ly,
     'rehearsal' : musicxml_rehearsal_to_ly_mark,
@@ -1319,17 +1333,17 @@ def musicxml_chordpitch_to_lily (mxl_cpitch):
 
 chordkind_dict = {
     'major': '5',
-    'minor': 'm',
-    'augmented': 'aug',
-    'diminished': 'dim',
+    'minor': 'm5',
+    'augmented': 'aug5',
+    'diminished': 'dim5',
         # Sevenths:
     'dominant': '7',
-    'major-seventh': 'maj',
+    'major-seventh': 'maj7',
     'minor-seventh': 'm7',
     'diminished-seventh': 'dim7',
     'augmented-seventh': 'aug7',
-    #'half-diminished': '???', (diminished triad, minor seventh)
-    #'major-minor': '???', (minor triad, major seventh)
+    'half-diminished': 'dim5m7',
+    'major-minor': 'maj7m5',
         # Sixths:
     'major-sixth': '6',
     'minor-sixth': 'm6',
@@ -1342,20 +1356,21 @@ chordkind_dict = {
     'major-11th': 'maj11',
     'minor-11th': 'm11',
         # 13ths (usually as the basis for alteration):
-    'dominant-13th': '13',
-    'major-13th': 'maj13',
+    'dominant-13th': '13.11',
+    'major-13th': 'maj13.11',
     'minor-13th': 'm13',
         # Suspended:
     'suspended-second': 'sus2',
     'suspended-fourth': 'sus4',
         # Functional sixths:
+    # TODO
     #'Neapolitan': '???',
     #'Italian': '???',
     #'French': '???',
     #'German': '???',
         # Other:
     #'pedal': '???',(pedal-point bass)
-    #'power': '???',(perfect fifth)
+    'power': '5^3',
     #'Tristan': '???',
     'other': '1',
     'none': None,
@@ -1385,6 +1400,19 @@ def musicxml_harmony_to_lily_chordname (n):
         inversion = n.get_maybe_exist_named_child ('inversion')
         if inversion:
             # TODO: Lilypond does not support inversions, does it?
+
+            # Mail from Carl Sorensen on lilypond-devel, June 11, 2008:
+            # 4. LilyPond supports the first inversion in the form of added 
+            # bass notes.  So the first inversion of C major would be c:/g.   
+            # To get the second inversion of C major, you would need to do 
+            # e:6-3-^5 or e:m6-^5.  However, both of these techniques 
+            # require you to know the chord and calculate either the fifth 
+            # pitch (for the first inversion) or the third pitch (for the 
+            # second inversion) so they may not be helpful for musicxml2ly.
+            inversion_count = string.atoi (inversion.get_text ())
+            if inversion_count == 1:
+              # TODO: Calculate the bass note for the inversion...
+              pass
             pass
         for deg in n.get_named_children ('degree'):
             d = musicexp.ChordModification ()
@@ -1842,6 +1870,8 @@ def musicxml_voice_to_lily_voice (voice):
                 dur = fb.real_duration
                 if not dur:
                     dur = ev_chord.get_length ()
+                if not fb.duration:
+                    fb.duration = ev_chord.get_duration ()
                 figured_bass_builder.add_music (fb, dur)
             pending_figured_bass = []
         
@@ -2126,26 +2156,30 @@ def get_all_voices (parts):
 
 
 def option_parser ():
-    p = ly.get_option_parser (usage = _ ("musicxml2ly [options] FILE.xml"),
-                             description = _ ("Convert MusicXML from FILE.xml to LilyPond input. If the given filename is -, musicxml2ly reads from the command line.") + "\n",
-                             add_help_option=False)
+    p = ly.get_option_parser (usage = _ ("musicxml2ly [OPTION]... FILE.xml"),
+                             description =
+_ ("""Convert MusicXML from FILE.xml to LilyPond input.
+If the given filename is -, musicxml2ly reads from the command line.
+"""), add_help_option=False)
 
     p.add_option("-h", "--help",
                  action="help",
                  help=_ ("show this help and exit"))
 
     p.version = ('''%prog (LilyPond) @TOPLEVEL_VERSION@\n\n'''
-                                      +
-_ ("""This program 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 `%s --warranty' for more
-information.""") % 'lilypond'
-+ """
-Copyright (c) 2005--2008 by
++
+_ ("""Copyright (c) 2005--2008 by
     Han-Wen Nienhuys <hanwen@xs4all.nl>,
     Jan Nieuwenhuizen <janneke@gnu.org> and
     Reinhold Kainhofer <reinhold@kainhofer.com>
-""")
+"""
++
+"""
+This program 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 `%s --warranty' for more
+information.""") % 'lilypond')
+
     p.add_option("--version",
                  action="version",
                  help=_ ("show version number and exit"))
@@ -2202,7 +2236,7 @@ Copyright (c) 2005--2008 by
                   type = 'string',
                   dest = 'output_name',
                   help = _ ("set output filename to FILE, stdout if -"))
-    p.add_option_group (ly.display_encode (_ ('Bugs')),
+    p.add_option_group ('',
                         description = (_ ("Report bugs via")
                                      + ''' http://post.gmane.org/post.php'''
                                      '''?group=gmane.comp.gnu.lilypond.bugs\n'''))