lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some fixes to musicxml2ly


From: Tuukka Verho
Subject: Re: Some fixes to musicxml2ly
Date: Fri, 15 Sep 2006 22:11:45 +0300

On Fri, 2006-09-15 at 19:33 +0200, Han-Wen Nienhuys wrote:
> 
> >         else:
> > -           return 0
> > +           tolerance_exp = -4  # means that notes that are 1/32 or less 
> > shorter
> > than 1/4 are quarter notes etc.
> > +           return int (math.ceil (-math.log(self._duration) / math.log(2)  
> > -
> > 2**tolerance_exp))
> 
> Since music notation uses exact rational numbers, using math.log () is 
> usually forbidden, and it's better to use exact arithmetic.  Can you 
> doublecheck whether or not exact arithmetic applies to your case, please 
> add an explanation comment why you're using floating point numbers?

In this case inexactness doesn't matter. The term 2**tolerance_exp makes
sure that notes that are slightly shorter than the next whole duration
are rounded to the whole duration instead of somethin like "c8.....". In
some cases floating point arithmetic can cause some randomness regarding
whether the note becomes c8... or c4 (if the duration is exactly 1/32
from the next whole duration), but I don't think that matters -- such
note length are weird enough to start with.

When determining the number of dots the use of floating point arithmetic
doesn't obviously harm, because the result is rounded anyway.

I can't think of any simple way to achieve the same result without using
math.log().

The attached diff for musicxml.py now has an explanatory comment.

Attachment: musicxml.py.diff
Description: Text Data

Attachment: musicxml2ly.py.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]