]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/musicxml.py
MusicXML: Cleanup of span start/end and direction, coding style
[lilypond.git] / python / musicxml.py
index e00bc07d2eb6ea0e7423531ac8a417848958cdf6..6234459187c71c7556e7f1e3cf6ae3537c2556f8 100644 (file)
@@ -5,10 +5,9 @@ import re
 
 def escape_ly_output_string (input_string):
     return_string = input_string
-    needs_quotes = re.search ("[0-9\" ,.]", return_string);
-    return_string = string.replace (return_string, "\"", "\\\"")
+    needs_quotes = not re.match ("^[a-zA-ZäöüÜÄÖßñ]*$", return_string);
     if needs_quotes:
-        return_string = "\"" + return_string + "\""
+        return_string = "\"" + string.replace (return_string, "\"", "\\\"") + "\""
     return return_string
 
 
@@ -168,6 +167,8 @@ class Duration (Music_xml_node):
 
 class Hash_comment (Music_xml_node):
     pass
+class Hash_text (Music_xml_node):
+    pass
 
 class Pitch (Music_xml_node):
     def get_step (self):
@@ -269,26 +270,30 @@ class Note (Measure_element):
         self.instrument_name = ''
         
     def get_duration_log (self):
-       ch = self.get_maybe_exist_typed_child (get_class (u'type'))
+        ch = self.get_maybe_exist_typed_child (get_class (u'type'))
 
-       if ch:
-           log = ch.get_text ().strip()
-           return {'eighth': 3,
+        if ch:
+            log = ch.get_text ().strip()
+            return {'256th': 8,
+                    '128th': 7,
+                    '64th': 6,
+                    '32nd': 5,
+                    '16th': 4,
+                    'eighth': 3,
                     'quarter': 2,
                     'half': 1,
-                    '16th': 4,
-                    '32nd': 5,
-                    'breve': -1,
-                    'long': -2,
-                    'whole': 0}.get (log)
-       else:
-           return 0
+                    'whole': 0,
+                    'breve': -1,
+                    'long': -2}.get (log, 0)
+        else:
+            sys.stderr.write ("Encountered note without duration (no <type> element): %s\n" % self)
+            return 0
 
     def get_factor (self):
-       return 1
+        return 1
 
     def get_pitches (self):
-       return self.get_typed_children (get_class (u'pitch'))
+        return self.get_typed_children (get_class (u'pitch'))
 
 class Part_list (Music_xml_node):
     def __init__ (self):
@@ -429,6 +434,8 @@ class Part (Music_xml_node):
             measure_start_moment = now
             measure_position = Rational (0)
            for n in m.get_all_children ():
+                if isinstance (n, Hash_text):
+                    continue
                dur = Rational (0)
 
                 if n.__class__ == Attributes:
@@ -461,15 +468,15 @@ class Part (Music_xml_node):
                     and n.get_maybe_exist_typed_child (Chord)):
                     now = last_moment
                     measure_position = last_measure_position
-                    
-                last_moment = now
-                last_measure_position = measure_position
 
-               n._when = now
+                n._when = now
                 n._measure_position = measure_position
-               n._duration = dur
-               now += dur
-                measure_position += dur
+                n._duration = dur
+                if dur > Rational (0):
+                    last_moment = now
+                    last_measure_position = measure_position
+                    now += dur
+                    measure_position += dur
                 if n._name == 'note':
                     instrument = n.get_maybe_exist_named_child ('instrument')
                     if instrument:
@@ -566,7 +573,10 @@ class Music_xml_spanner (Music_xml_node):
         else:
             return 0
 
-class Tuplet(Music_xml_spanner):
+class Wedge (Music_xml_spanner):
+    pass
+
+class Tuplet (Music_xml_spanner):
     pass
 
 class Slur (Music_xml_spanner):
@@ -636,6 +646,7 @@ class Bend (Music_xml_node):
 ## used by class name or extend Music_xml_node in some way!
 class_dict = {
        '#comment': Hash_comment,
+        '#text': Hash_text,
        'accidental': Accidental,
        'attributes': Attributes,
        'beam' : Beam,
@@ -659,12 +670,14 @@ class_dict = {
        'pitch': Pitch,
        'rest': Rest,
        'slur': Slur,
+       'staff': Staff,
         'syllabic': Syllabic,
         'text': Text,
        'time-modification': Time_modification,
         'tuplet': Tuplet,
        'type': Type,
         'wavy-line': Wavy_line,
+        'wedge': Wedge,
         'work': Work,
 }