]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/musicxml2ly.py
(datadir): remove LILYPONDPREFIX support.
[lilypond.git] / scripts / musicxml2ly.py
index f1125b15d6f1d7c4c4c30a8b96405c97e14513a4..f3fd9a7a06131cb467fe4d95f274acdebb3f49af 100644 (file)
@@ -1,4 +1,4 @@
-#!@PYTHON@
+#!@TARGET_PYTHON@
 
 import optparse
 import sys
@@ -6,34 +6,22 @@ import re
 import os
 import string
 from gettext import gettext as _
-import musicxml
-
-
-
 
-datadir = '@local_lilypond_datadir@'
-if not os.path.isdir (datadir):
-    datadir = '@lilypond_datadir@'
-if os.environ.has_key ('LILYPONDPREFIX'):
-    datadir = os.environ['LILYPONDPREFIX']
-    while datadir[-1] == os.sep:
-        datadir = datadir[:-1]
 
-if os.path.exists (os.path.join (datadir, 'share/lilypond/@TOPLEVEL_VERSION@/')):
-    datadir = os.path.join (datadir, 'share/lilypond/@TOPLEVEL_VERSION@/')
-elif os.path.exists (os.path.join (datadir, 'share/lilypond/current/')):
-    datadir = os.path.join (datadir, 'share/lilypond/current/')
 
-sys.path.insert (0, os.path.join (datadir, 'python'))
+for d in ['@lilypond_datadir@',
+          '@lilypond_libdir@']:
+    sys.path.insert (0, os.path.join (d, 'python'))
 
 # dynamic relocation, for GUB binaries.
-bindir = os.path.split (sys.argv[0])[0]
-
-for prefix_component in ['share', 'lib']:
-    datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % prefix_component)
+bindir = os.path.abspath (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
 
 import musicxml
@@ -196,6 +184,7 @@ instrument_drumtype_dict = {
     'Acoustic Snare Drum': 'acousticsnare',
     'Side Stick': 'sidestick',
     'Open Triangle': 'opentriangle',
+    'Mute Triangle': 'mutetriangle',
     'Tambourine': 'tambourine',
     
 }
@@ -288,13 +277,18 @@ class LilyPondVoiceBuilder:
             self.add_music (evc, diff)
                 
     def last_event_chord (self, starting_at):
+
+        value = None
         if (self.elements
             and isinstance (self.elements[-1], musicexp.EventChord)
             and self.begin_moment == starting_at):
-            return self.elements[-1]
+            value = self.elements[-1]
         else:
             self.jumpto (starting_at)
-            return None
+            value = None
+
+        return value
+        
     def correct_negative_skip (self, goto):
         self.end_moment = goto
         self.begin_moment = goto
@@ -306,15 +300,17 @@ def musicxml_voice_to_lily_voice (voice):
     modes_found = {}
 
     voice_builder = LilyPondVoiceBuilder()
+
     for n in voice._elements:
         if n.get_name () == 'forward':
             continue
 
-        try:
-            voice_builder.jumpto (n._when)
-        except NegativeSkip, neg:
-            voice_builder.correct_negative_skip (n._when)
-            n.message ("Negative skip? from %s to %s, diff %s" % (neg.here, neg.dest, neg.dest - neg.here))
+        if not n.get_maybe_exist_named_child ('chord'):
+            try:
+                voice_builder.jumpto (n._when)
+            except NegativeSkip, neg:
+                voice_builder.correct_negative_skip (n._when)
+                n.message ("Negative skip? from %s to %s, diff %s" % (neg.here, neg.dest, neg.dest - neg.here))
             
         if isinstance (n, musicxml.Attributes):
             if n.is_first () and n._measure_position == Rational (0):
@@ -350,10 +346,9 @@ def musicxml_voice_to_lily_voice (voice):
         ev_chord = voice_builder.last_event_chord (n._when)
         if not ev_chord: 
             ev_chord = musicexp.EventChord()
+            voice_builder.add_music (ev_chord, n._duration)
 
-        
         ev_chord.append (main_event)
-        voice_builder.add_music (ev_chord, n._duration)
         
         notations = n.get_maybe_exist_typed_child (musicxml.Notations)
         tuplet_event = None
@@ -398,7 +393,7 @@ def musicxml_voice_to_lily_voice (voice):
             tuplet_events.append ((ev_chord, tuplet_event, frac))
 
     ## force trailing mm rests to be written out.   
-    voice_builder.add_music (musicexp.EventChord ())
+    voice_builder.add_music (musicexp.EventChord (), Rational (0))
     
     ly_voice = group_tuplets (voice_builder.elements, tuplet_events)