BaseTime Manual

About

A BaseTime object is used to define a point in time in a BaseDocument. 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 BaseTime::GetFrame() would return 15, but if using 24 fps it would return frame 12.

Access

The current time of a BaseDocument can be handled using:

For timeline dimensions, preview time and used time see BaseDocument Manual.

To retrieve and modify BaseTime objects stored in a BaseContainer respectively use:

See also BaseContainer Manual.

To retrieve and modify BaseTime objects stored in a GeData object (GeData type is DA_TIME) respectively use:

See also GeData Manual.

Please notice that Cinema 4D can only handle a limited number of frames:

  • MAXTIME: The maximum number of frames Cinema 4D can handle in a timeline.

Animation keys are placed at certain frames. These frames can be respectively retrieved and modified using:

// This example checks if the given object is a particle emitter.
// If so, the emission start time is read and the current document time is set.
BaseObject* const object = doc->GetActiveObject();
if (object == nullptr)
return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION);
// check if the given object is a standard particle emitter
if (object->GetType() == Oparticle)
{
GeData data;
// read the "Start Emission" parameter
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
const BaseTime time = data.GetTime();
doc->SetTime(time);
}

Time and Frame

The frame number equivalent of the stored time depends on the current framerate:

// This example prints the current frame of the given document.
const BaseTime now = doc->GetTime();
const Int32 fps = doc->GetFps();
const Int32 frame = now.GetFrame(fps);
ApplicationOutput("Current Frame: " + String::IntToString(frame));

Properties

Set Time

BaseTime objects can be constructed by setting a time in seconds of by giving a frame and a framerate.

// This example adds a keyframe to the given animation track at the position 1.0 seconds.
CCurve* const curve = track->GetCurve();
if (curve != nullptr)
{
const BaseTime time { 1.0 };
const CKey* const key = curve->AddKey(time);
if (key == nullptr)
return maxon::UnknownError(MAXON_SOURCE_LOCATION);
}
// This example adds a keyframe to the given animation track at the position of frame 25.
CCurve* const curve = track->GetCurve();
if (curve != nullptr)
{
const Int32 fps = doc->GetFps();
const BaseTime time(25, fps);
const CKey* const key = curve->AddKey(time);
if (key == nullptr)
return maxon::UnknownError(MAXON_SOURCE_LOCATION);
}

Numerator/Denominator

The internal value of a BaseTime object is represented by a numerator and denominator. Both values can be retrieved and modified using:

Compare

Two BaseTime objects can be compared using a special function or the usual operators:

// This example compares the current document time with the value of one second.
const BaseTime oneSecond { 1.0 };
const BaseTime now = doc->GetTime();
const Int32 compare = now.TimeDif(oneSecond);
if (compare == -1)
ApplicationOutput("The current frame is less than one second");
else if (compare == 1)
ApplicationOutput("The current frame is greater than one second");

Disc I/O

BaseTime objects can be stored in a HyperFile using:

See also HyperFile Manual on BaseTime.

Further Reading

BaseTime
Definition: c4d_basetime.h:24
BaseDocument::GetFps
Int32 GetFps(void) const
BaseObject
Definition: c4d_baseobject.h:224
DescID
Definition: lib_description.h:327
BaseDocument::SetTime
void SetTime(const BaseTime &t)
CCurve
Definition: c4d_canimation.h:354
BaseTime::GetFrame
Int32 GetFrame(Float fps) const
Definition: c4d_basetime.h:107
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
CCurve::AddKey
CKey * AddKey(const BaseTime &time, Int32 *nidx=nullptr, Bool bUndo=false, Bool SynchronizeKeys=false)
Definition: c4d_canimation.h:412
GeData::GetTime
const BaseTime & GetTime(void) const
Definition: c4d_gedata.h:481
Oparticle
#define Oparticle
Particle emitter - ParticleObject.
Definition: ge_prepass.h:989
String::IntToString
static String IntToString(Int32 v)
Definition: c4d_string.h:495
BaseDocument::GetTime
BaseTime GetTime(void) const
GeData
Definition: c4d_gedata.h:82
Int32
maxon::Int32 Int32
Definition: ge_sys_math.h:60
ApplicationOutput
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:207
CKey
Definition: c4d_canimation.h:57
PARTICLEOBJECT_START
@ PARTICLEOBJECT_START
Definition: oparticle.h:28
BaseTime::TimeDif
Int32 TimeDif(const BaseTime &t2) const
Definition: c4d_basetime.h:213
DESCFLAGS_GET::NONE
@ NONE
None.
BaseDocument::GetActiveObject
BaseObject * GetActiveObject(void)
CTrack::GetCurve
CCurve * GetCurve(CCURVE type=CCURVE::CURVE, Bool bCreate=true)
Definition: c4d_canimation.h:824
C4DAtom::GetType
Int32 GetType() const
Definition: c4d_baselist.h:1364
C4DAtom::GetParameter
Bool GetParameter(const DescID &id, GeData &t_data, DESCFLAGS_GET flags)