lilypond-devel
[Top][All Lists]
Advanced

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

Re: Some fixes to musicxml2ly


From: Karl Hammar
Subject: Re: Some fixes to musicxml2ly
Date: Sat, 16 Sep 2006 13:41:22 +0200

address@hidden:
> 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.
> 

I don't understand this:

  tolerance_exp = -4
  a = - math.log(self._duration) / math.log(2)
  b = 2**tolerance_exp
  c = a - b

1:
 if tolerance_exp is a constant, why don't you simply say b = 1/16
 (another constant), which is clearly a duration(?) value.

2:
 why are you taking the difference between the log of a duration and a
 duration?

 In physics there is something which is called a dimension test: you
 simply cannot do 1 meter - 1 second. In math, you don't easily agree to
 do log(entity) - entity. And in this case I read your code as
 -2log( seconds ) - seconds which is clearly wrong.

 Now b seems to be an implementation detail caused by using floating
 point values, the same with math.ceil, is it so?

 If you simply want to map a duration to its -2log, why don't you use
 something like arr = [ 1, 2, 4, ...]; f(x) = arr[x]; which is a clear
 statement about what you are doing (although incomplete, I sense that
 self._duration is a rational number).

3:
 I don't understand what you are trying to do and your comment does not
 match the code

4:
 using floating point values for exact things usually open up enough
 nasty bugs and is very hard to verify due to rounding errors. Unless
 you have VERY good reason, just don't do it, it is not worth the
 trouble.

===========

Later in your patch:

+            factor = self._duration / 2**(-self.get_duration_log())            
+            return int (round (-math.log(2 - factor) / math.log(2)))

If:

 a = 1/2**(-self.get_duration_log())

then:

 a = 2**self.get_duration_log()

assuming that get_duration_log() returns a 2log and
that get_duration() exists, then

 a = self.get_duration()

get_duration() look suspiciously like _duration(), so my guess is that

 factor = self._duration ** 2

by quickly reading the code as a math guy.

Now, if duration usually is less than 1 (we don't see many breves and
longas today), then

 -math.log(2 - factor) / math.log(2)

more or less reduces to a near constant -1.

Is that your intention, or am I reading your code false?
I assume that duration is the lenght of a note, like whole note is 1,
a quater note is 1/4, ...

Regards,
/Karl

-----------------------------------------------------------------------
Karl Hammar                    Aspö Data               address@hidden
Lilla Aspö 2340                                                Networks
S-742 94 Östhammar          +46  173 140 57                   Computers
Sweden                     +46  70 511 97 84                 Consulting
-----------------------------------------------------------------------




reply via email to

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