Main Index : Reference :

BaseTime


Description

The internal time class of CINEMA 4D.

Definition

class BaseTime
{
public:
  BaseTime();

  [bool] SetFrame([float] frame, [float] fps);
  [bool] SetSecond([float] second);
  
  [int] GetFrame([float] fps);
  [float] GetSecond();

  [bool] Quantize([float] fps);

  [bool] Mul([BaseTime] t);
  [bool] Div([BaseTime] t);
  [bool] Add([BaseTime] t);
  [bool] Sub([BaseTime] t);

  [bool] IsEQ([BaseTime] t);
  [bool] IsNE([BaseTime] t);

  [bool] IsLT([BaseTime] t);
  [bool] IsGT([BaseTime] t);

  [bool] IsLE([BaseTime] t);
  [bool] IsGE([BaseTime] t);

  [bool] CopyTo([BaseTime] dest);
  [BaseTime] GetClone();
}

Explanation

C4D uses a very sophisticated system for specifying time values. If only frame numbers were used, changing the frame rate would cause keys either to overlap or disappear. If only float values (seconds) were used instead (as in the V5 SDK), there would be problems because of the limited data precision. For example when using 30 fps the frame 29 = 29/30 could easily be misinterpreted as frame 28!

Therefore C4D has a time class that internally stores the time values as exact fractions independent of the frame rate. For example frame 29 is stored as 29/30. The class always tries to keep the nominator and denominator as small as possible. Hence 15/30 is stored as 1/2. Now when using 30 fps GetFrame() will return 15, but when using 24 fps it will return frame 12.

Of course one can still use float values (seconds). They are internally multiplied by 1000.0 and stored as fractions. This is not recommended because of the aforementioned rounding errors.

Members

SetFrame( frame, fps )

[bool] SetFrame([float] frame, [float] fps);

Initializes the internal time value from a frame number, frame, and a framerate, fps. Returns TRUE if successful.

SetSecond( second )

[bool] SetSecond([float] second);

Initializes the internal time value from a float value, second, by multiplying it by 1000.0 and storing it as a fraction. Returns TRUE if successful.


GetFrame( fps )

[int] GetFrame([float] fps);

Returns the frame number that the internal time value specifies with a certain framerate, fps. For example if the time is 2/3 seconds (exactly) and the framerate is 30 fps, the functions returns 20.

GetSecond()

[float] GetSecond();

Returns the internal time value in seconds as a float.


Quantize( fps )

[bool] Quantize([float] fps);

Quantizes the internal value so that it is a multiple of the specified framerate, fps. Returns TRUE if successful.


Mul( t )

[bool] Mul([BaseTime] t);

Multiplies the internal time value by t. Returns TRUE if successful.

Div( t )

[bool] Div([BaseTime] t);

Divides the internal time value by t. Returns TRUE if successful.

Add( t )

[bool] Add([BaseTime] t);

Add t to the internal time value. Returns TRUE if successful.

Sub( t )

[bool] Sub([BaseTime] t);

Subtracts t from the internal time value. Returns TRUE if successful.


IsEQ( t )

[bool] IsEQ([BaseTime] t);

Returns TRUE if the internal time value is equal to t.

IsNE( t )

[bool] IsNE([BaseTime] t);

Returns TRUE if the internal time value isn't equal to t.


IsLT( t )

[bool] IsLT([BaseTime] t);

Returns TRUE if the internal time value is less than t.

IsGT( t )

[bool] IsGT([BaseTime] t);

Returns TRUE if the internal time value is greater than t.


IsLE( t )

[bool] IsLE([BaseTime] t);

Returns TRUE if the internal time value is less than or equal to t.

IsGE( t )

[bool] IsGE([BaseTime] t);

Returns TRUE if the internal time value is greater than or equal to t.


CopyTo( dest )

[bool] CopyTo([BaseTime] dest);

Copies the time value to dest.

GetClone()

[BaseTime] GetClone();

Returns a copy of the class. Returns TRUE if successful.

Example

// Prints the document time in seconds and frames
var t = doc->GetTime();
var sec = t->GetSecond()
var frame = t->GetFrame(doc->GetFps());
println(sec, " s  ", frame, "F");