BaseTime Class Reference

#include <c4d_basetime.h>

Detailed Description

Cinema 4D uses a 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, there would be problems because of the limited data precision. For instance when using 30 fps the frame 29 = 29/30 could easily be misinterpreted as frame 28.

BaseTime internally stores the time values as exact fractions independent of the frame rate. For example frame 29 is stored as fraction with nominator 29 and denominator 30.
The class always tries to keep the nominator and denominator as small as possible. Hence 15/30 is stored as 1/2, so if using 30 fps GetFrame() would return 15, but if using 24 fps it would return frame 12.

Private Member Functions

void Reduce ()
 

Private Attributes

Float numerator
 
Float denominator
 

Friends

class BaseFile
 
class AESFile
 

Math Operators

const BaseTime operator* (const BaseTime &t1, const BaseTime &t2)
 
const BaseTime operator/ (const BaseTime &t1, const BaseTime &t2)
 
const BaseTime operator+ (const BaseTime &t1, const BaseTime &t2)
 
const BaseTime operator- (const BaseTime &t1, const BaseTime &t2)
 

Comparison Operators

Bool operator== (const BaseTime &t1, const BaseTime &t2)
 
Bool operator< (const BaseTime &t1, const BaseTime &t2)
 
Bool operator!= (const BaseTime &t1, const BaseTime &t2)
 
Bool operator<= (const BaseTime &t1, const BaseTime &t2)
 
Bool operator>= (const BaseTime &t1, const BaseTime &t2)
 
Bool operator> (const BaseTime &t1, const BaseTime &t2)
 

Constructor/Destructor

 BaseTime ()
 
 BaseTime (Float r)
 
 BaseTime (Float z, Float n)
 

Numerator/Denominator

Float Get () const
 
Float GetNumerator () const
 
Float GetDenominator () const
 
void SetNumerator (Float r)
 
void SetDenominator (Float r)
 

Frames

Int32 GetFrame (Float fps) const
 
void Quantize (Float fps)
 

Miscellaneous

Int32 TimeDif (const BaseTime &t2) const
 
maxon::HashInt GetHashCode () const
 

Constructor & Destructor Documentation

◆ BaseTime() [1/3]

BaseTime ( )

Default constructor.

◆ BaseTime() [2/3]

BaseTime ( Float  r)
explicit

Initializes the internal time value from a float value in seconds.
Constructor will multiply the seconds by 1000.0 and store it as a fraction with 1000.0 as denominator; after this the fraction will be reduced to its lowest form.

Parameters
[in]rThe time in seconds.

◆ BaseTime() [3/3]

BaseTime ( Float  z,
Float  n 
)
explicit

Initializes the internal time value to the given fraction of z/n.

Parameters
[in]zThe nominator.
[in]nThe denominator.

Member Function Documentation

◆ Reduce()

void Reduce ( )
private

◆ Get()

Float Get ( ) const

Gets the time in seconds.

Returns
The time in seconds.

◆ GetNumerator()

Float GetNumerator ( ) const

Gets the numerator part of the internally stored time.

Returns
The numerator.

◆ GetDenominator()

Float GetDenominator ( ) const

Gets the denominator part of the internally stored time.

Returns
The denominator.

◆ SetNumerator()

void SetNumerator ( Float  r)

Sets the numerator part of the internally stored time.

Parameters
[in]rThe numerator.

◆ SetDenominator()

void SetDenominator ( Float  r)

Sets the denominator part of the internally stored time.

Parameters
[in]rThe denominator.

◆ GetFrame()

Int32 GetFrame ( Float  fps) const

Gets the number of frames equivalent to the time for the given number of Frames per Second.

Parameters
[in]fpsThe Frames per Second to use to calculate the frame number for the time.
Returns
The frame number for the time.

◆ Quantize()

void Quantize ( Float  fps)

Quantizes the internally stored value so that it is a multiple of the given number of Frames per Second.

Parameters
[in]fpsThe number of Frames per Second to make the time a multiple of.

◆ TimeDif()

Int32 TimeDif ( const BaseTime t2) const

Check which is the largest between the time and t2.

Parameters
[in]t2The time to compare with.
Returns
-1 if the time is < t2, 0 if they are equal and 1 if the time is > t2.

◆ GetHashCode()

maxon::HashInt GetHashCode ( ) const

Gets a hash code for the BaseTime.

Since
R2023
Returns
The hash code.

Friends And Related Function Documentation

◆ BaseFile

friend class BaseFile
friend

◆ AESFile

friend class AESFile
friend

◆ operator*

const BaseTime operator* ( const BaseTime t1,
const BaseTime t2 
)
friend

Multiplies t1 and t2.

Parameters
[in]t1Left-operand time.
[in]t2Right-operand time.
Returns
Result of the multiplication.

◆ operator/

const BaseTime operator/ ( const BaseTime t1,
const BaseTime t2 
)
friend

Divides t1 and t2.

Parameters
[in]t1Left-operand time.
[in]t2Right-operand time.
Returns
Result of the division.

◆ operator+

const BaseTime operator+ ( const BaseTime t1,
const BaseTime t2 
)
friend

Adds t1 and t2.

Parameters
[in]t1Left-operand time.
[in]t2Right-operand time.
Returns
Result of the addition.

◆ operator-

const BaseTime operator- ( const BaseTime t1,
const BaseTime t2 
)
friend

Subtracts t1 and t2.

Parameters
[in]t1Left-operand time.
[in]t2Right-operand time.
Returns
Result of the subtraction.

◆ operator==

Bool operator== ( const BaseTime t1,
const BaseTime t2 
)
friend

Equality operator. Checks if t1 and t2 are equal.

Parameters
[in]t1Left-operand time.
[in]t2Right-operand time.
Returns
Result of the comparison.

◆ operator<

Bool operator< ( const BaseTime t1,
const BaseTime t2 
)
friend

Less than operator. Checks if t1 is less than t2.

Parameters
[in]t1Left-operand time.
[in]t2Right-operand time.
Returns
Result of the comparison.

◆ operator!=

Bool operator!= ( const BaseTime t1,
const BaseTime t2 
)
friend

Inequality operator. Checks if t1 and t2 are not equal.

Parameters
[in]t1Left-operand time.
[in]t2Right-operand time.
Returns
Result of the comparison.

◆ operator<=

Bool operator<= ( const BaseTime t1,
const BaseTime t2 
)
friend

Less than or equal operator. Checks if t1 is less than or equal to t2.

Parameters
[in]t1Left-operand time.
[in]t2Right-operand time.
Returns
Result of the comparison.

◆ operator>=

Bool operator>= ( const BaseTime t1,
const BaseTime t2 
)
friend

Greater than or equal operator. Checks if t1 is greater than or equal to t2.

Parameters
[in]t1Left-operand time.
[in]t2Right-operand time.
Returns
Result of the comparison.

◆ operator>

Bool operator> ( const BaseTime t1,
const BaseTime t2 
)
friend

Greater than operator. Checks if t1 is greater than t2.

Parameters
[in]t1Left-operand time.
[in]t2Right-operand time.
Returns
Result of the comparison.

Member Data Documentation

◆ numerator

Float numerator
private

◆ denominator

Float denominator
private