On Fri, 2006-09-15 at 22:11 +0300, Tuukka Verho wrote:
> The attached diff for musicxml.py now has an explanatory comment.
Oops, sent a diff without the comment. Here comes the correnct version.
Tuukka
--- lilypond/python/musicxml.py 2006-08-26 01:04:08.000000000 +0300
+++ musicxml.py 2006-09-16 10:12:27.000000000 +0300
@@ -1,4 +1,5 @@
import new
+import math
from rational import *
class Xml_node:
@@ -193,7 +194,22 @@
'long': -2,
'whole': 0} [log]
else:
- return 0
+ # Using floating point arithmetic here to calculate logarithm
+ # the term 2**tolerance_exp ensures that borderline cases are
+ # rounded to the next whole duration
+
+ tolerance_exp = -4 # means that notes that are 1/32 or less
+ # shorter than 1/4 will be quarter notes etc.
+ return int (math.ceil
+ (-math.log (self._duration) / math.log (2) - 2**tolerance_exp))
+
+ def get_num_dots(self):
+ if self.get_maybe_exist_typed_child (class_dict['type']):
+ return len (self.get_typed_children (Dot))
+
+ else:
+ factor = self._duration / 2**(-self.get_duration_log())
+ return int (round (-math.log(2 - factor) / math.log(2)))
def get_factor (self):
return 1
@@ -351,27 +367,26 @@
elements.extend (m.get_all_children ())
start_attr = None
- for n in elements:
- voice_id = n.get_maybe_exist_typed_child (class_dict['voice'])
-
- if not (voice_id or isinstance (n, Attributes)):
- continue
-
- if isinstance (n, Attributes) and not start_attr:
- start_attr = n
- continue
-
- if isinstance (n, Attributes):
- for v in voices.values ():
+ for n in elements:
+ if (isinstance (n, Note)):
+ voice_id = n.get_maybe_exist_typed_child (get_class('voice'))
+ if voice_id:
+ id = voice_id.get_text ()
+ else:
+ id = '1'
+
+ if not voices.has_key (id):
+ voices[id] = Musicxml_voice()
+
+ voices[id].add_element (n)
+
+ elif isinstance (n, Attributes):
+ if not start_attr:
+ start_attr = n
+
+ for v in voices.values ():
v.add_element (n)
- continue
-
- id = voice_id.get_text ()
- if not voices.has_key (id):
- voices[id] = Musicxml_voice()
-
- voices[id].add_element (n)
-
+
if start_attr:
for (k,v) in voices.items ():
v.insert (0, start_attr)
_______________________________________________
lilypond-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-devel