From: John F. <jo...@us...> - 2013-06-24 15:59:13
|
Update of /cvsroot/ingex/ingex/common In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv10041 Modified Files: Timecode.cpp Timecode.h Log Message: Further updates to class Index: Timecode.h =================================================================== RCS file: /cvsroot/ingex/ingex/common/Timecode.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Timecode.h 3 Jun 2013 11:02:46 -0000 1.14 --- Timecode.h 24 Jun 2013 15:59:10 -0000 1.15 *************** *** 77,80 **** --- 77,85 ---- public: // constructors + enum EpochEnumType + { + MIDNIGHT, + SMPTE + }; Timecode(); Timecode(uint64_t frames_since_epoch, TimecodeFormat::EnumType e); *************** *** 94,107 **** unsigned int FrameRateDenominator() const { return TimecodeFormat::Get(mFormatEnum).Rate().denominator; } bool DropFrame() const { return TimecodeFormat::Get(mFormatEnum).DropFrame(); } ! //unsigned int Hours() const; ! //unsigned int Minutes() const; ! //unsigned int Seconds() const; ! //unsigned int Frames() const; ! //unsigned int FrameOfPair(); unsigned int ColorFrame() const; unsigned int NominalFps(); std::string FormatName() const { return TimecodeFormat::Get(mFormatEnum).Name(); } void Jam(unsigned int hours, unsigned int minutes, bool color_frame_id, unsigned int color_frame); ! void GetHoursMinsEtc(unsigned int & hours, unsigned int & minutes, unsigned int & seconds, unsigned int & frames, unsigned int & frame_of_pair) const; // operator overload --- 99,113 ---- unsigned int FrameRateDenominator() const { return TimecodeFormat::Get(mFormatEnum).Rate().denominator; } bool DropFrame() const { return TimecodeFormat::Get(mFormatEnum).DropFrame(); } ! unsigned int Hours() const; ! unsigned int Minutes() const; ! unsigned int Seconds() const; ! unsigned int Frames() const; ! unsigned int FrameOfPair() const; unsigned int ColorFrame() const; unsigned int NominalFps(); std::string FormatName() const { return TimecodeFormat::Get(mFormatEnum).Name(); } void Jam(unsigned int hours, unsigned int minutes, bool color_frame_id, unsigned int color_frame); ! //void GetHoursMinsEtc(unsigned int & hours, unsigned int & minutes, unsigned int & seconds, unsigned int & frames, unsigned int & frame_of_pair) const; ! void LocalOffset(int offset) { mLocalOffset = offset; } // operator overload *************** *** 114,118 **** // data TimecodeFormat::EnumType mFormatEnum; ! unsigned int mFrameCount; // methods void Set(unsigned int hours, unsigned int minutes, unsigned int seconds, unsigned int frames, unsigned int frame_of_pair); --- 120,127 ---- // data TimecodeFormat::EnumType mFormatEnum; ! uint64_t mFrameCount; ! EpochEnumType mEpochEnum; ! int mUtcOffset; ! int mLocalOffset; // methods void Set(unsigned int hours, unsigned int minutes, unsigned int seconds, unsigned int frames, unsigned int frame_of_pair); Index: Timecode.cpp =================================================================== RCS file: /cvsroot/ingex/ingex/common/Timecode.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Timecode.cpp 3 Jun 2013 11:02:45 -0000 1.21 --- Timecode.cpp 24 Jun 2013 15:59:10 -0000 1.22 *************** *** 183,187 **** // Default constructor initialises null timecode Timecode::Timecode() ! : mFormatEnum(TimecodeFormat::TC_NONE), mFrameCount(0) { } --- 183,187 ---- // Default constructor initialises null timecode Timecode::Timecode() ! : mFormatEnum(TimecodeFormat::TC_NONE), mFrameCount(0), mEpochEnum(MIDNIGHT), mUtcOffset(0), mLocalOffset(0) { } *************** *** 189,193 **** // Constructor Timecode::Timecode(uint64_t frames_since_epoch, TimecodeFormat::EnumType e) ! : mFormatEnum(e), mFrameCount(frames_since_epoch) { } --- 189,193 ---- // Constructor Timecode::Timecode(uint64_t frames_since_epoch, TimecodeFormat::EnumType e) ! : mFormatEnum(e), mFrameCount(frames_since_epoch), mEpochEnum(MIDNIGHT), mUtcOffset(0), mLocalOffset(0) { } *************** *** 195,199 **** // Constructor Timecode::Timecode(unsigned int hours, unsigned int minutes, unsigned int seconds, unsigned int frames, unsigned int frame_of_pair, TimecodeFormat::EnumType e) ! : mFormatEnum(e) { Set(hours, minutes, seconds, frames, frame_of_pair); --- 195,199 ---- // Constructor Timecode::Timecode(unsigned int hours, unsigned int minutes, unsigned int seconds, unsigned int frames, unsigned int frame_of_pair, TimecodeFormat::EnumType e) ! : mFormatEnum(e), mEpochEnum(MIDNIGHT), mUtcOffset(0), mLocalOffset(0) { Set(hours, minutes, seconds, frames, frame_of_pair); *************** *** 202,206 **** // Constructor Timecode::Timecode(const std::string & s, TimecodeFormat::EnumType e) ! : mFormatEnum(e) { bool ok = false; --- 202,206 ---- // Constructor Timecode::Timecode(const std::string & s, TimecodeFormat::EnumType e) ! : mFormatEnum(e), mEpochEnum(MIDNIGHT), mUtcOffset(0), mLocalOffset(0) { bool ok = false; *************** *** 234,238 **** // Copy constructor Timecode::Timecode(const Timecode & tc) ! : mFormatEnum(tc.mFormatEnum), mFrameCount(tc.mFrameCount) { } --- 234,238 ---- // Copy constructor Timecode::Timecode(const Timecode & tc) ! : mFormatEnum(tc.mFormatEnum), mFrameCount(tc.mFrameCount), mEpochEnum(tc.mEpochEnum), mUtcOffset(tc.mUtcOffset), mLocalOffset(tc.mLocalOffset) { } *************** *** 245,248 **** --- 245,251 ---- mFormatEnum = tc.mFormatEnum; mFrameCount = tc.mFrameCount; + mEpochEnum = tc.mEpochEnum; + mUtcOffset = tc.mUtcOffset; + mLocalOffset = tc.mLocalOffset; } return *this; *************** *** 251,262 **** std::string Timecode::Text() const { ! unsigned int hours, minutes, seconds, frames, frame_of_pair; ! GetHoursMinsEtc(hours, minutes, seconds, frames, frame_of_pair); - char text[20]; switch (mFormatEnum) { case TimecodeFormat::TC_NONE: - sprintf(text, "??:??:??:??"); break; case TimecodeFormat::TC_23NDF: --- 254,262 ---- std::string Timecode::Text() const { ! char sep = ':'; switch (mFormatEnum) { case TimecodeFormat::TC_NONE: break; case TimecodeFormat::TC_23NDF: *************** *** 268,297 **** case TimecodeFormat::TC_59NDF: case TimecodeFormat::TC_60: ! if (0 == frame_of_pair) { // with colon ! sprintf(text,"%02d:%02d:%02d:%02d", hours, minutes, seconds, frames); } else { // with full-stop ! sprintf(text,"%02d:%02d:%02d.%02d", hours, minutes, seconds, frames); } break; case TimecodeFormat::TC_29DF: case TimecodeFormat::TC_59DF: ! if (0 == frame_of_pair) { // with semi-colon ! sprintf(text,"%02d:%02d:%02d;%02d", hours, minutes, seconds, frames); } else { // with comma ! sprintf(text,"%02d:%02d:%02d,%02d", hours, minutes, seconds, frames); } break; } return text; } --- 268,307 ---- case TimecodeFormat::TC_59NDF: case TimecodeFormat::TC_60: ! if (0 == FrameOfPair()) { // with colon ! sep = ':'; } else { // with full-stop ! sep = '.'; } break; case TimecodeFormat::TC_29DF: case TimecodeFormat::TC_59DF: ! if (0 == FrameOfPair()) { // with semi-colon ! sep = ';'; } else { // with comma ! sep = ','; } break; } + char text[20]; + if (TimecodeFormat::TC_NONE == mFormatEnum) + { + sprintf(text, "??:??:??:??"); + } + else + { + sprintf(text,"%02d:%02d:%02d%c%02d", Hours(), Minutes(), Seconds(), sep, Frames()); + } + return text; } *************** *** 299,305 **** std::string Timecode::TextNoSeparators() const { - unsigned int hours, minutes, seconds, frames, frame_of_pair; - GetHoursMinsEtc(hours, minutes, seconds, frames, frame_of_pair); - char text[20]; switch (mFormatEnum) --- 309,312 ---- *************** *** 309,313 **** break; default: ! sprintf(text,"%02d%02d%02d%02d", hours, minutes, seconds, frames); break; } --- 316,320 ---- break; default: ! sprintf(text,"%02d%02d%02d%02d", Hours(), Minutes(), Seconds(), Frames()); break; } *************** *** 322,337 **** // e.g. 0 corresponds to fields I and II - unsigned int hours, minutes, seconds, frames, frame_of_pair; - GetHoursMinsEtc(hours, minutes, seconds, frames, frame_of_pair); - unsigned int color_frame; switch (mFormatEnum) { case TimecodeFormat::TC_25: ! color_frame = (seconds + frames + 3) % 4; break; case TimecodeFormat::TC_29DF: case TimecodeFormat::TC_29NDF: ! color_frame = frames % 2; break; default: --- 329,341 ---- // e.g. 0 corresponds to fields I and II unsigned int color_frame; switch (mFormatEnum) { case TimecodeFormat::TC_25: ! color_frame = (Seconds() + Frames() + 3) % 4; break; case TimecodeFormat::TC_29DF: case TimecodeFormat::TC_29NDF: ! color_frame = Frames() % 2; break; default: *************** *** 422,425 **** --- 426,620 ---- } + unsigned int Timecode::Hours() const + { + unsigned int hours = 0; + unsigned int nominal_fps = TimecodeFormat::Get(mFormatEnum).NominalRate(); + + switch (mFormatEnum) + { + case TimecodeFormat::TC_23NDF: + case TimecodeFormat::TC_24: + case TimecodeFormat::TC_25: + case TimecodeFormat::TC_29NDF: + case TimecodeFormat::TC_30: + case TimecodeFormat::TC_50: + case TimecodeFormat::TC_59NDF: + case TimecodeFormat::TC_60: + hours = mFrameCount / (nominal_fps * 60 * 60); + break; + case TimecodeFormat::TC_29DF: + hours = mFrameCount / DF_FRAMES_PER_HOUR; + break; + case TimecodeFormat::TC_59DF: + hours = mFrameCount / (2 * DF_FRAMES_PER_HOUR); + break; + case TimecodeFormat::TC_NONE: + hours = 0; + break; + } + + //hours %= 24; + return hours; + } + + unsigned int Timecode::Minutes() const + { + unsigned int hours; + unsigned int minutes = 0; + unsigned int nominal_fps = TimecodeFormat::Get(mFormatEnum).NominalRate(); + unsigned int f2; + uint64_t tmp_frames; + + switch (mFormatEnum) + { + case TimecodeFormat::TC_23NDF: + case TimecodeFormat::TC_24: + case TimecodeFormat::TC_25: + case TimecodeFormat::TC_29NDF: + case TimecodeFormat::TC_30: + case TimecodeFormat::TC_50: + case TimecodeFormat::TC_59NDF: + case TimecodeFormat::TC_60: + minutes = mFrameCount / (nominal_fps * 60); + minutes %= 60; + break; + case TimecodeFormat::TC_29DF: + hours = mFrameCount / DF_FRAMES_PER_HOUR; + f2 = mFrameCount - hours * DF_FRAMES_PER_HOUR; + minutes = (mFrameCount + 2 * (f2 / 1800) - 2 * (f2 / 18000) - DF_FRAMES_PER_HOUR * hours) / 1800; + break; + case TimecodeFormat::TC_59DF: + tmp_frames = mFrameCount / 2; + hours = tmp_frames / DF_FRAMES_PER_HOUR; + f2 = tmp_frames - hours * DF_FRAMES_PER_HOUR; + minutes = (tmp_frames + 2 * f2 / 1800 - 2 * f2 / 18000 - DF_FRAMES_PER_HOUR * hours) / 1800; + break; + case TimecodeFormat::TC_NONE: + minutes = 0; + break; + } + + return minutes; + } + + unsigned int Timecode::Seconds() const + { + unsigned int hours; + unsigned int minutes; + unsigned int seconds = 0; + unsigned int nominal_fps = TimecodeFormat::Get(mFormatEnum).NominalRate(); + unsigned int f2; + uint64_t tmp_frames; + + switch (mFormatEnum) + { + case TimecodeFormat::TC_23NDF: + case TimecodeFormat::TC_24: + case TimecodeFormat::TC_25: + case TimecodeFormat::TC_29NDF: + case TimecodeFormat::TC_30: + case TimecodeFormat::TC_50: + case TimecodeFormat::TC_59NDF: + case TimecodeFormat::TC_60: + seconds = mFrameCount / nominal_fps; + seconds %= 60; + break; + case TimecodeFormat::TC_29DF: + tmp_frames = mFrameCount; + hours = tmp_frames / DF_FRAMES_PER_HOUR; + f2 = tmp_frames - hours * DF_FRAMES_PER_HOUR; + minutes = (tmp_frames + 2 * (f2 / 1800) - 2 * (f2 / 18000) - DF_FRAMES_PER_HOUR * hours) / 1800; + seconds = (tmp_frames - DF_FRAMES_PER_MINUTE * minutes - 2 * (minutes / 10) - DF_FRAMES_PER_HOUR * hours) / 30; + break; + case TimecodeFormat::TC_59DF: + tmp_frames = mFrameCount / 2; + hours = tmp_frames / DF_FRAMES_PER_HOUR; + f2 = tmp_frames - hours * DF_FRAMES_PER_HOUR; + minutes = (tmp_frames + 2 * f2 / 1800 - 2 * f2 / 18000 - DF_FRAMES_PER_HOUR * hours) / 1800; + seconds = (tmp_frames - DF_FRAMES_PER_MINUTE * minutes - 2 * minutes / 10 - DF_FRAMES_PER_HOUR * hours) / 30; + break; + case TimecodeFormat::TC_NONE: + seconds = 0; + break; + } + + return seconds; + } + + unsigned int Timecode::Frames() const + { + unsigned int hours; + unsigned int minutes; + unsigned int seconds; + unsigned int frames = 0; + unsigned int nominal_fps = TimecodeFormat::Get(mFormatEnum).NominalRate(); + unsigned int f2; + uint64_t tmp_frames; + + switch (mFormatEnum) + { + case TimecodeFormat::TC_23NDF: + case TimecodeFormat::TC_24: + case TimecodeFormat::TC_25: + case TimecodeFormat::TC_29NDF: + case TimecodeFormat::TC_30: + frames = mFrameCount % nominal_fps; + break; + case TimecodeFormat::TC_50: + case TimecodeFormat::TC_59NDF: + case TimecodeFormat::TC_60: + frames = (mFrameCount % nominal_fps) / 2; + break; + case TimecodeFormat::TC_29DF: + tmp_frames = mFrameCount; + hours = tmp_frames / DF_FRAMES_PER_HOUR; + f2 = tmp_frames - hours * DF_FRAMES_PER_HOUR; + minutes = (tmp_frames + 2 * (f2 / 1800) - 2 * (f2 / 18000) - DF_FRAMES_PER_HOUR * hours) / 1800; + seconds = (tmp_frames - DF_FRAMES_PER_MINUTE * minutes - 2 * (minutes / 10) - DF_FRAMES_PER_HOUR * hours) / 30; + frames = tmp_frames - 30 * seconds - DF_FRAMES_PER_MINUTE * minutes - 2 * (minutes / 10) - DF_FRAMES_PER_HOUR * hours; + break; + case TimecodeFormat::TC_59DF: + tmp_frames = mFrameCount / 2; + hours = tmp_frames / DF_FRAMES_PER_HOUR; + f2 = tmp_frames - hours * DF_FRAMES_PER_HOUR; + minutes = (tmp_frames + 2 * f2 / 1800 - 2 * f2 / 18000 - DF_FRAMES_PER_HOUR * hours) / 1800; + seconds = (tmp_frames - DF_FRAMES_PER_MINUTE * minutes - 2 * minutes / 10 - DF_FRAMES_PER_HOUR * hours) / 30; + frames = tmp_frames - 30 * seconds - DF_FRAMES_PER_MINUTE * minutes - 2 * (minutes / 10) - DF_FRAMES_PER_HOUR * hours; + break; + case TimecodeFormat::TC_NONE: + frames = 0; + break; + } + + return frames; + } + + unsigned int Timecode::FrameOfPair() const + { + unsigned int frame_of_pair = 0; + + switch (mFormatEnum) + { + case TimecodeFormat::TC_23NDF: + case TimecodeFormat::TC_24: + case TimecodeFormat::TC_25: + case TimecodeFormat::TC_29DF: + case TimecodeFormat::TC_29NDF: + case TimecodeFormat::TC_30: + case TimecodeFormat::TC_NONE: + frame_of_pair = 0; + break; + case TimecodeFormat::TC_50: + case TimecodeFormat::TC_59DF: + case TimecodeFormat::TC_59NDF: + case TimecodeFormat::TC_60: + frame_of_pair = mFrameCount % 2; + break; + } + + return frame_of_pair; + } + + /* void Timecode::GetHoursMinsEtc(unsigned int & hours, unsigned int & minutes, unsigned int & seconds, unsigned int & frames, unsigned int & frame_of_pair) const { *************** *** 567,570 **** --- 762,766 ---- hours %= 24; } + */ /** |