TimeValue Manual

内容表

关于

maxon::TimeValue is a MAXON API class used to create an object capable of handling time-related actions. A maxon::TimeValue object stores information on different time-scale basis, actually from hours to nanoseconds, making it possible to deliver unprecedented time granularity.

Creation and Initialization

A maxon::TimeValue can be created on the stack and initialized through the proper method:

// This example allocates a few maxon::TimeValue objects showing the different allocation methods.

// just allocate a TimeValue object const maxon::TimeValue timevalue;

// allocate and init a TimeValue object const maxon::TimeValue initdTimeValue( maxon::TimeValue::NOW );

// allocate and init a TimeValue object using frame and framerate const maxon::TimeValue framebasedTimeValue(10, FRAMERATE_FILM_NTSC );

// allocate a TimeValue object by cloning an existing one const maxon::TimeValue clonedTimeValue(initdTimeValue);

A value can be assigned to a maxon::TimeValue by using the assignment operator:

// This example shows how to assign a value to a TimeValue object.

// allocate a TimeValue object maxon::TimeValue timevalue;

// assign it the current time timevalue = maxon::TimeValue ( maxon::TimeValue::CurrentTime ());

Standard Operations

A maxon::TimeValue can be modified by using standard operators:

// This examples shows how to operate with mathematical-like operators.

// allocate a TimeValue object const maxon::TimeValue timevalueA( maxon::TimeValue::NOW );

// allocate a second TimeValue object const maxon::TimeValue timevalueB = timevalueA * 2;

// evaluate the sum const maxon::TimeValue sumAB = timevalueA + timevalueB;

// evaluate the "right-assigned" sum maxon::TimeValue sum0A; sum0A += timevalueA;

// evaluate the difference const maxon::TimeValue differenceBA = timevalueB - timevalueA;

// evaluate the product maxon::TimeValue productA3 = timevalueA * 3.0;

// evaluate the right-assigned product maxon::TimeValue productA6(productA3); productA6 *= 2.0;

// evaluate the quotient between two TimeValue objects const maxon::Float quotientAB = timevalueB / timevalueA;

// evaluate the quotient between a TimeValue object and a Float value const maxon::TimeValue quotientA3by2 = productA3 / 2.0;

比较

A maxon::TimeValue can be compared by using standard mathematical-like operators:

// This example shows how to compare two TimeValue instances.

// allocate a TimeValue object const maxon::TimeValue timevalueA( maxon::TimeValue::NOW );

// allocate a second TimeValue object const maxon::TimeValue timevalueB = timevalueA * 2;

// compare for the smaller if (timevalueA < timevalueB) DiagnosticOutput (diagIDString + "timevalueA [@] is smaller than timevalueB [@]" , timevalueA, timevalueB); // compare for equality else if (timevalueA == timevalueB) DiagnosticOutput (diagIDString + "timevalueA [@] is equal to timevalueB [@]" , timevalueA, timevalueB); else DiagnosticOutput (diagIDString + "timevalueA [@] is grater than timevalueB [@]" , timevalueA, timevalueB);

注意
From the above operators all the remaining operators (!=, >, >=, <=) are build and can thus be used as normal, too.

Get and Set operations

The value stored in a maxon::TimeValue can be set using:

Similarly the value stored in a maxon::TimeValue can be retrieved using:

// This example shows how to set the value of a TimeValue by specifying the desired time unit // and retrieve its value using a specific time unit.

// allocate another TimeValue object maxon::TimeValue timevalueSet, timevalueFinal;

// populate the object with the intended values timevalueSet. SetHours (10.0); timevalueFinal += timevalueSet; timevalueSet. SetMinutes (20.0); timevalueFinal += timevalueSet; timevalueSet. SetSeconds (30.0); timevalueFinal += timevalueSet; timevalueSet. SetMilliseconds (444.0); timevalueFinal += timevalueSet; timevalueSet. SetMicroseconds (555.0); timevalueFinal += timevalueSet; timevalueSet. SetNanoseconds (666.0); timevalueFinal += timevalueSet;

// extract hours, remaining minutes, remaining seconds and remaining millsecs const Int hours = ( maxon::Int )timevalueFinal. GetHours (); const Int minutes = (( maxon::Int )timevalueFinal. GetMinutes () - (hours * 60)); const Int seconds = (( maxon::Int )timevalueFinal. GetSeconds () - ((hours * 60 + minutes) * 60)); const Float millsecs = timevalueFinal. GetMilliseconds () - ( maxon::Float )(((hours * 60 + minutes) * 60) + seconds) * 1000;

Timer

Benchmarking or profiling parts of code can be delivered using the functions:

// This example shows how to use the TimeValue as a timer to accomplish profiling operations

// allocate a TimeValue object and set the current time maxon::TimeValue timer = maxon::TimeValue::GetTime (); DiagnosticOutput (diagIDString + "timer started at: @" , timer);

// do your "time-consuming" stuff like filling an array const maxon::Int itemsCnt = 1024; maxon::BaseArray<Float> hugearray; hugearray. Resize (itemsCnt) iferr_return ; maxon::BaseArray<Float>::Iterator itBegin = hugearray. Begin (); maxon::LinearCongruentialRandom<maxon::Float32> rndm; rndm. Init (1234); while (itBegin != hugearray. End ()) { *itBegin = rndm. Get01 (); itBegin++; }

// stop the timer timer. Stop (); DiagnosticOutput (diagIDString + "Filling @ float items in the array have required @" , itemsCnt, timer);

Conversion

A maxon::TimeValue can be converted to/from a different type using:

// This example shows how to accomplish TimeValue conversion to/from maxon::String.

// allocate a TimeValue and get it represented via a string const maxon::TimeValue timevalueNow( maxon::TimeValue::NOW ); const maxon::String stringNow = timevalueNow.ToString( nullptr );

// convert from string to timevalue const maxon::String stringSeconds { "30.00" }; maxon::TimeValue timevalueSec; timevalueSec. TimeFromString (stringSeconds, TIMEFORMAT::SECONDS , FRAMERATE_DEFAULT ) iferr_return ; // convert from timevalue to string const maxon::String seconds = timevalueSec. TimeToString ();

// convert from string to timevalue const maxon::String stringPAL { "750.00" }; maxon::TimeValue timevaluePAL; timevaluePAL. TimeFromString (stringPAL, TIMEFORMAT::FRAMES , FRAMERATE_PAL ) iferr_return ; // convert to frame using a standard PAL frame rate (25fps) const maxon::String framesInPAL = timevaluePAL. TimeToString ( TIMEFORMAT::FRAMES , FRAMERATE_PAL );

// convert from string to timevalue const maxon::String stringDEFAULT { "900.00" }; maxon::TimeValue timevalueDEFAULT; timevalueDEFAULT. TimeFromString (stringDEFAULT, TIMEFORMAT::FRAMES , FRAMERATE_DEFAULT ) iferr_return ; // convert to frame using a default frame rate (30fps) const maxon::String framesInDEFAULT = timevalueDEFAULT. TimeToString ( TIMEFORMAT::FRAMES , FRAMERATE_DEFAULT );

// convert from string to timevalue const maxon::String stringNTSC { "899.10" }; maxon::TimeValue timevalueNTSC; timevalueNTSC. TimeFromString (stringNTSC, TIMEFORMAT::FRAMES , FRAMERATE_NTSC ) iferr_return ; // convert to frame using a standard NTSC frame rate (29.97fps) const maxon::String framesInNTSC = timevalueNTSC. TimeToString ( TIMEFORMAT::FRAMES , FRAMERATE_NTSC );

// convert from string to timevalue const maxon::String stringFILM { "720.00" }; maxon::TimeValue timevalueFILM; timevalueFILM. TimeFromString (stringFILM, TIMEFORMAT::FRAMES , FRAMERATE_FILM ) iferr_return ; // convert to frame using a standard filmic frame rate (24fps) const maxon::String framesInFILM = timevalueFILM. TimeToString ( TIMEFORMAT::FRAMES , FRAMERATE_FILM );

// convert from string to timevalue const maxon::String stringSMTPE { "00:15:26:05" }; maxon::TimeValue timevalueSMTPE; timevalueSMTPE. TimeFromString (stringSMTPE, TIMEFORMAT::SMPTE , FRAMERATE_FILM ) iferr_return ; // convert to standard SMTP time representation using film frame rate (24fps) const maxon::String framesInSMTPE = timevalueSMTPE. TimeToString ( TIMEFORMAT::SMPTE , FRAMERATE_FILM );

Utilities

A few helpful methods are provided with the maxon::TimeValue as utilities:

// This example shows how to use the utilities found in the TimeValue class

// allocate a TimeValue object const maxon::TimeValue now( maxon::TimeValue::NOW );

// retrieve the hashcode of the object const maxon::UInt hashNow = now.GetHashCode();

// allocate a TimeValue object and set to 200ms (note 1 PAL frame is 40ms) maxon::TimeValue timevalue; timevalue. SetMilliseconds (200); const Int framePAL = timevalue. GetFrame ( FRAMERATE_PAL );

// define a delta TimeValue and set to 45 millisecs maxon::TimeValue timeoffset; timeoffset. SetMilliseconds (45); // add previous timevalue to delta timeoffset += timevalue; // quantize to the nearest PAL frame timevalue. Quantize ( FRAMERATE_PAL ); const Int quantizedframePAL = timeoffset. GetFrame ( FRAMERATE_PAL );

A maxon::TimeValue object can be read from and written to disk by serializing the data contained using the conventional functions.

// This example shows how to store and retrieve a TimeValue from a file. const maxon::TimeValue savedTimevalue( maxon::TimeValue::NOW );

// file URL const maxon::Url url = (targetFolder + "timevalue.txt" _s) iferr_return ; const maxon::Id fileID { "net.maxonexample.timevalue" };

// save to file maxon::WriteDocument (url, maxon::OPENSTREAMFLAGS::NONE , fileID, savedTimevalue, maxon::IOFORMAT::JSON ) iferr_return ;

// read from file maxon::TimeValue loadedTimevalue; maxon::ReadDocument (url, fileID, loadedTimevalue) iferr_return ;

延伸阅读

maxon::ReadDocument
std::enable_if< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, Result< void > >::type ReadDocument(const Url &url, const Id &id, T &object, const DataDictionary &dict=DataDictionary())
定义: io.h:35
maxon::TimeValue::SetMicroseconds
void SetMicroseconds(Float64 microseconds)
定义: timevalue.h:286
maxon::TimeValue::GetHours
Float64 GetHours() const
定义: timevalue.h:187
maxon::TimeValue::CurrentTime
定义: timevalue.h:36
maxon::FRAMERATE_FILM
const Float64 FRAMERATE_FILM
Movie frame rate is 24 fps.
定义: timevalue.h:18
Int
maxon::Int Int
定义: ge_sys_math.h:62
maxon::BaseArray::End
MAXON_ATTRIBUTE_FORCE_INLINE ConstIterator End() const
定义: basearray.h:1352
maxon::TimeValue::SetNanoseconds
void SetNanoseconds(Float64 nanoseconds)
定义: timevalue.h:313
maxon::FRAMERATE_DEFAULT
const Float64 FRAMERATE_DEFAULT
Default frame rate of 30 fps.
定义: timevalue.h:15
Float
maxon::Float Float
定义: ge_sys_math.h:64
SMPTE
SMPTE
display time as SMPTE time code
定义: timevalue.h:22
maxon::String
定义: string.h:1197
maxon::TimeValue::Quantize
void Quantize(Float64 frameRate)
quantize the time for a given frame rate, so that its frame value is a multiple of the specified fram...
FRAMES
FRAMES
display time as a frame number
定义: timevalue.h:21
maxon::BaseArray::Resize
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
定义: basearray.h:1077
maxon::TimeValue::SetHours
void SetHours(Float64 hours)
定义: timevalue.h:196
maxon::Id
定义: apibaseid.h:250
iferr_return
#define iferr_return
定义: resultbase.h:1434
maxon::OPENSTREAMFLAGS::NONE
@ NONE
No flags set.
maxon::TimeValue::GetSeconds
Float64 GetSeconds() const
定义: timevalue.h:223
maxon::TimeValue::NOW
static const CurrentTime NOW
定义: timevalue.h:38
maxon::Float
Float64 Float
定义: apibase.h:193
maxon::TimeValue::SetMinutes
void SetMinutes(Float64 minutes)
定义: timevalue.h:214
maxon::BaseArray< Float >
maxon::FRAMERATE_PAL
const Float64 FRAMERATE_PAL
PAL frame rate is 25 fps.
定义: timevalue.h:17
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::TimeValue::SetMilliseconds
void SetMilliseconds(Float64 milliseconds)
定义: timevalue.h:259
maxon::Url
定义: url.h:819
maxon::TimeValue::GetMinutes
Float64 GetMinutes() const
定义: timevalue.h:205
maxon::BaseIterator
定义: block.h:104
maxon::IOFORMAT::JSON
@ JSON
maxon::TimeValue::GetTime
static TimeValue GetTime()
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
定义: apibase.h:184
maxon::LinearCongruentialRandom
定义: lib_math.h:18
maxon::LinearCongruentialRandom::Init
void Init(UInt32 seed)
maxon::TimeValue::GetMilliseconds
Float64 GetMilliseconds() const
定义: timevalue.h:241
maxon::TimeValue::Stop
const TimeValue & Stop()
maxon::WriteDocument
Result< void > WriteDocument(const Url &url, OPENSTREAMFLAGS flags, const Id &id, const T &object, IOFORMAT format=IOFORMAT::DEFAULT, const DataDictionary &dict=DataDictionary())
定义: io.h:67
maxon::FRAMERATE_NTSC
const Float64 FRAMERATE_NTSC
NTSC frame rate is approximately 29.97 fps.
定义: timevalue.h:16
maxon::TimeValue::TimeToString
String TimeToString(TIMEFORMAT timeFormat=TIMEFORMAT::SECONDS, Float64 frameRate=1) const
maxon::TimeValue::TimeFromString
Result< void > TimeFromString(const String &str, TIMEFORMAT timeFormat, Float64 frameRate)
maxon::BaseArray::Begin
MAXON_ATTRIBUTE_FORCE_INLINE ConstIterator Begin() const
定义: basearray.h:1332
maxon::TimeValue
The TimeValue class encapsulates a timer value.
定义: timevalue.h:33
SECONDS
SECONDS
display time in seconds
定义: timevalue.h:20
maxon::UInt
UInt64 UInt
unsigned 32/64 bit int, size depends on the platform
定义: apibase.h:185
maxon::TimeValue::SetSeconds
void SetSeconds(Float64 seconds)
定义: timevalue.h:232
maxon::FRAMERATE_FILM_NTSC
const Float64 FRAMERATE_FILM_NTSC
Modified movie frame rate to avoid frame roll when transfering video to NTSC, approx....
定义: timevalue.h:19
maxon::TimeValue::GetFrame
Int GetFrame(Float64 frameRate) const
maxon::LinearCongruentialRandom::Get01
FLOAT Get01()
Returns the next random value in the range of [0..1].

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1