]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: extract note duration log and nr of dots in one function
authorReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 21 Nov 2008 21:25:58 +0000 (22:25 +0100)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 21 Nov 2008 21:25:58 +0000 (22:25 +0100)
python/musicxml.py
scripts/musicxml2ly.py

index f796bf5892e04ab4465a16bc32479b981b32376c..f3487d4a8ea1038324198116b3e6fb000e541cb5 100644 (file)
@@ -401,6 +401,14 @@ class Note (Measure_element):
            return 3
         else:
             return None
+    
+    def get_duration_info (self):
+        log = self.get_duration_log ()
+        if log != None:
+            dots = len (self.get_typed_children (Dot))
+            return (log, dots)
+        else:
+            return None
 
     def get_factor (self):
         return 1
index b124e99ebe57430969c415af8ae510c3badb84cf..529de96020ae577b6b93c8bf8b4e7fc704d4654f 100644 (file)
@@ -461,24 +461,27 @@ def extract_score_structure (part_list, staffinfo):
 
 
 def musicxml_duration_to_lily (mxl_note):
-    d = musicexp.Duration ()
     # if the note has no Type child, then that method returns None. In that case,
     # use the <duration> tag instead. If that doesn't exist, either -> Error
-    d.duration_log = mxl_note.get_duration_log ()
-    if d.duration_log == None:
-        if mxl_note._duration > 0:
-            return rational_to_lily_duration (mxl_note._duration)
-        else:
-            mxl_note.message (_ ("Encountered note at %s without type and duration (=%s)") % (mxl_note.start, mxl_note._duration) )
-            return None
-    else:
-        d.dots = len (mxl_note.get_typed_children (musicxml.Dot))
+    dur = mxl_note.get_duration_info ()
+    if dur:
+        d = musicexp.Duration ()
+        d.duration_log = dur[0]
+        d.dots = dur[1]
         # Grace notes by specification have duration 0, so no time modification 
         # factor is possible. It even messes up the output with *0/1
         if not mxl_note.get_maybe_exist_typed_child (musicxml.Grace):
             d.factor = mxl_note._duration / d.get_length ()
         return d
 
+    else:
+        if mxl_note._duration > 0:
+            return rational_to_lily_duration (mxl_note._duration)
+        else:
+            mxl_note.message (_ ("Encountered note at %s without type and duration (=%s)") % (mxl_note.start, mxl_note._duration) )
+            return None
+
+
 def rational_to_lily_duration (rational_len):
     d = musicexp.Duration ()