So if I do the following in the Javascript Console window, a and b are the same value.
a = 1/3
Result: 0.33333333333333
b = a
Result: 0.33333333333333
b
Result: 0.33333333333333
However, if I do the following, item.workAreDuration isn't actually assigned the same value as a.
a = 1/3
Result: 0.33333333333333
item.workAreaDuration=a
Result: 0.33333333333333
item.workAreaDuration
Result: 0.33333334326744
Any ideas why this is happening?
Sounds like a possible bug, but I just tried this code in CS3, CS4, CS5 AND CS5.5 on OS X and got the same result in all of them. If it i a bug, it's been around for awhile. ![]()
I also thought maybe it was a single frameDuration offset thing like when you use outPoint, but the difference didn't match up. Not sure what specifically is causing this, but maybe the algorithm for the timeline time is setup to prevent infinite number results and/or keeps the values within a compatible range based on the current timeline FPS, which would make sense given that there is no such thing as a half or fractional frame in video really.
I did some test and it seems the internal value that is stored is not a float but a 24bit signed integer for the decimal part of the number where each seconds is divided in 8388607 (or 0x7FFFFF) equal parts.
So it is not a bug, but merely an internal precision thing that is still overkill.
If you need it, here is a function that will give the same result. It appear they are rounding the value you give to the 7th decimal.
function workareaduration(val){
var full = val - (val%1);
var dec = Math.ceil(Math.round(val*10000000)*.0000001%1/(1/0x7fffff))*(1/0x7fff ff)
return full + dec
}
workareaduration(0.33333333333333)
That's good to know that workAreaStart is relative to displayStartTime.
As for being able to set workAreaDuration to a float value, the function above doesn't really solve the problem I'm having. The timeline I'm working with is in frames and I would like to be able to do this:
comp.workAreaDuration = currentFormatToTime("00100", 24)
timeToCurrentFormat(comp.workAreaDuration, 24)
but timeToCurrentFormat() returns 99 rather than 100 since the float value assigned is only accurate to the 7th decimal. ![]()
The functions currentFormatToTime() and timeToCurrentFormat() seem to work ok. I can assign the value from currentFormatToTime() to a variable and get the correct float value.
a = currentFormatToTime("00100", 24)
The variable 'a' gets assigned 4.16666666666667 as I would expect.
But if I try assigning the value from currentFormatToTime() to comp.workAreaDuration, I get 4.16666650772095 instead.
comp.workAreaDuration = currentFormatToTime("00100", 24)
Even the following doesn't set comp.workAreaDuration to 4.16666666666667.
var frameNumber = 100;
comp.workAreaDuration = comp.frameDuration * frameNumber;
So it boils down to that assigning something like 1/3 or 100/24 to an arbitrary variable vs assigning it to comp.workAreaDuration gives you different results.
a = 100/24;
comp.workAreaDuration = 100/24;
If you run this code, it hopefully explains better what the problem is. It looks like duration and workAreaStart get assigned the correct float value, but displayStartTime and workAreaDuration do not.
First in a new project, create a new composition (Composition->New Composition...).
Then run this code in the script editor.
var a = 1/24;
var comp = app.project.item(1);
comp.displayStartTime = 1/24;
var b = 200/24;
comp.duration = 200/24;
var c = 1/24;
comp.workAreaStart = 1/24;
var d = 100/24;
comp.workAreaDuration = 100/24;
alert("a=1/24\t\t\t"+a+"\ndisplayStartTime=1/24\t"+comp.displayStartTime+
"\n\nb=200/24\t\t\t"+b+"\nduration=200/24\t\t"+comp.duration+
"\n\nc=1/24\t\t\t"+c+"\nworkAreaStart=1/24\t\t"+comp.workAreaStart+
"\n\nd=100/24\t\t\t"+d+"\nworkAreaDuration=100/24\t"+comp.workAreaDuration);
Ok, I think I might have figured out something that'll work for what I'm trying to do.
comp.workAreaDuration = 100/24;
var frame = Math.round(comp.workAreaDuration * comp.frameRate);
Seems that curentFormatToTime() might be just flooring the frame value so that I get frame 99 instead of 100. If I round the value of workAreaDuration*frameRate, I get the correct frame number.
North America
Europe, Middle East and Africa
Asia Pacific