Re: Bug in iTunes?
Re: Bug in iTunes?
- Subject: Re: Bug in iTunes?
- From: Kai <email@hidden>
- Date: Mon, 09 Jun 2003 05:31:46 +0100
on Sat, 7 Jun 2003 16:33:25 +0200, Manfred Lippert <email@hidden> wrote:
>
I've got the following script that sets and reads the volume adjustment
>
of the first selected track in iTunes:
>
>
tell application "iTunes"
>
set theTrack to first item of selection
>
set (volume adjustment of theTrack) to 42
>
display dialog (volume adjustment of theTrack) as integer
>
end tell
>
>
Result: The volume adjustment is 41 instead of the requested 42! This
>
is reproducable with every value: positive values are set one too low,
>
negative values are set one too high (e.g. -7 would result in -6).
>
Is this a bug in iTunes? Is this a known bug? Is this bug in every
>
version of iTunes, or is it a new one?
I just tried it on an old version (2.0.4) - and that behaves in the way you
describe, too.
This appears to be a rounding anomaly. My guess is that iTunes includes a
rounding function - just in case it's passed a real number instead of an
integer.
Trouble is that it doesn't seem to work as expected. For example...
=========================
tell application "iTunes"
set {l, t} to {{}, selection's item 1}
repeat with n from -30 to 30
set v to n / 10
set t's volume adjustment to v
set l's end to {v, t's volume adjustment}
end repeat
end tell
l
=========================
--> {{-3.0, -2}, {-2.9, -2}, {-2.8, -2}, {-2.7, -2}, {-2.6, -2}, {-2.5, -1},
{-2.4, -1}, {-2.3, -1}, {-2.2, -1}, {-2.1, -1}, {-2.0, -1}, {-1.9, -1},
{-1.8, -1}, {-1.7, -1}, {-1.6, -1}, {-1.5, -1}, {-1.4, 0}, {-1.3, 0}, {-1.2,
0}, {-1.1, 0}, {-1.0, 0}, {-0.9, 0}, {-0.8, 0}, {-0.7, 0}, {-0.6, 0}, {-0.5,
0}, {-0.4, 0}, {-0.3, 0}, {-0.2, 0}, {-0.1, 0}, {0.0, 0}, {0.1, 0}, {0.2,
0}, {0.3, 0}, {0.4, 0}, {0.5, 0}, {0.6, 0}, {0.7, 0}, {0.8, 0}, {0.9, 0},
{1.0, 0}, {1.1, 0}, {1.2, 0}, {1.3, 0}, {1.4, 0}, {1.5, 1}, {1.6, 1}, {1.7,
1}, {1.8, 1}, {1.9, 1}, {2.0, 1}, {2.1, 1}, {2.2, 1}, {2.3, 1}, {2.4, 1},
{2.5, 1}, {2.6, 2}, {2.7, 2}, {2.8, 2}, {2.9, 2}, {3.0, 2}}
It looks to me as if iTunes is trying to round in a similar way to Standard
Additions' round "to nearest" (which rounds .5 cases to the nearest even
integer in order to decrease cumulative errors.)
However, if that's the case, then the results should look more like this:
=========================
set l to {}
repeat with n from -30 to 30
set v to n / 10
set l's end to {v, round v rounding to nearest}
end repeat
l
=========================
--> {{-3.0, -3}, {-2.9, -3}, {-2.8, -3}, {-2.7, -3}, {-2.6, -3}, {-2.5, -2},
{-2.4, -2}, {-2.3, -2}, {-2.2, -2}, {-2.1, -2}, {-2.0, -2}, {-1.9, -2},
{-1.8, -2}, {-1.7, -2}, {-1.6, -2}, {-1.5, -2}, {-1.4, -1}, {-1.3, -1},
{-1.2, -1}, {-1.1, -1}, {-1.0, -1}, {-0.9, -1}, {-0.8, -1}, {-0.7, -1},
{-0.6, -1}, {-0.5, 0}, {-0.4, 0}, {-0.3, 0}, {-0.2, 0}, {-0.1, 0}, {0.0, 0},
{0.1, 0}, {0.2, 0}, {0.3, 0}, {0.4, 0}, {0.5, 0}, {0.6, 1}, {0.7, 1}, {0.8,
1}, {0.9, 1}, {1.0, 1}, {1.1, 1}, {1.2, 1}, {1.3, 1}, {1.4, 1}, {1.5, 2},
{1.6, 2}, {1.7, 2}, {1.8, 2}, {1.9, 2}, {2.0, 2}, {2.1, 2}, {2.2, 2}, {2.3,
2}, {2.4, 2}, {2.5, 2}, {2.6, 3}, {2.7, 3}, {2.8, 3}, {2.9, 3}, {3.0, 3}}
>
Any ideas how to work around this bug?
I imagine the only way around it at the moment is to make specific
adjustments. The most obvious method might be:
=========================
set v to 42
if v is greater than 0 then
set v to v + 1
else if v is less than 0 then
set v to v - 1
end if
tell application "iTunes"
set t to selection's item 1
set t's volume adjustment to v
t's volume adjustment -- check
end tell
=========================
--> 42
Or, if you prefer a shorter version, I suppose you might try something like:
=========================
set v to 42
if v is not 0 then set v to v + (v + 1) div v * 2 - 1
tell application "iTunes"
set t to selection's item 1
set t's volume adjustment to v
t's volume adjustment -- check
end tell
=========================
--> 42
However, assuming a fix is forthcoming in a later version, both of the above
adjustments will eventually result in yet another inaccuracy. For example,
setting the variable 'v' to 42 will result in a (post-fix) volume adjustment
of 43.
So, to avoid the need to later rewrite every script that uses volume
adjustment, you might consider this sort of approach instead:
=========================
set v to 42
tell application "iTunes"
set t to selection's item 1
set t's volume adjustment to v
set x to t's volume adjustment
if x is not v then set t's volume adjustment to x + (v - x) * 2
t's volume adjustment -- check
end tell
=========================
--> 42
One final caveat. Given the current inconsistency, volume adjustment values
of 99 or -99 cannot be set. So the above suggestions would result in values
of 100 and -100 respectively.
--
Kai
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.