comparison base/RealTimeSV.cpp @ 1542:6415ac3becb6 zoom

Use proper decimal delimiter
author Chris Cannam
date Fri, 28 Sep 2018 18:06:05 +0100
parents 71207822a7e0
children c36ffc195988
comparison
equal deleted inserted replaced
1541:71207822a7e0 1542:6415ac3becb6
59 return -fromSeconds(-sec); 59 return -fromSeconds(-sec);
60 } 60 }
61 } 61 }
62 62
63 RealTime 63 RealTime
64 RealTime::fromMilliseconds(int msec) 64 RealTime::fromMilliseconds(int64_t msec)
65 { 65 {
66 return RealTime(msec / 1000, (msec % 1000) * 1000000); 66 int64_t sec = msec / 1000;
67 } 67 if (sec > INT_MAX || sec < INT_MIN) {
68 68 cerr << "WARNING: millisecond value out of range for RealTime, "
69 RealTime 69 << "returning zero instead: " << msec << endl;
70 RealTime::fromMicroseconds(int usec) 70 return RealTime::zeroTime;
71 { 71 }
72 return RealTime(usec / 1000000, (usec % 1000000) * 1000); 72
73 return RealTime(int(sec), int(msec % 1000) * 1000000);
74 }
75
76 RealTime
77 RealTime::fromMicroseconds(int64_t usec)
78 {
79 int64_t sec = usec / 1000000;
80 if (sec > INT_MAX || sec < INT_MIN) {
81 cerr << "WARNING: microsecond value out of range for RealTime, "
82 << "returning zero instead: " << usec << endl;
83 return RealTime::zeroTime;
84 }
85
86 return RealTime(int(sec), int(usec % 1000000) * 1000);
73 } 87 }
74 88
75 RealTime 89 RealTime
76 RealTime::fromTimeval(const struct timeval &tv) 90 RealTime::fromTimeval(const struct timeval &tv)
77 { 91 {
262 { 276 {
263 if (*this < RealTime::zeroTime) return "-" + (-*this).toText(fixedDp); 277 if (*this < RealTime::zeroTime) return "-" + (-*this).toText(fixedDp);
264 278
265 Preferences *p = Preferences::getInstance(); 279 Preferences *p = Preferences::getInstance();
266 bool hms = true; 280 bool hms = true;
281 std::string frameDelimiter = ":";
267 282
268 if (p) { 283 if (p) {
269 hms = p->getShowHMS(); 284 hms = p->getShowHMS();
270 int fps = 0; 285 int fps = 0;
271 switch (p->getTimeToTextMode()) { 286 switch (p->getTimeToTextMode()) {
272 case Preferences::TimeToTextMs: break; 287 case Preferences::TimeToTextMs:
273 case Preferences::TimeToTextUs: fps = 1000000; break; 288 break;
289 case Preferences::TimeToTextUs:
290 fps = 1000000;
291 frameDelimiter = ".";
292 break;
274 case Preferences::TimeToText24Frame: fps = 24; break; 293 case Preferences::TimeToText24Frame: fps = 24; break;
275 case Preferences::TimeToText25Frame: fps = 25; break; 294 case Preferences::TimeToText25Frame: fps = 25; break;
276 case Preferences::TimeToText30Frame: fps = 30; break; 295 case Preferences::TimeToText30Frame: fps = 30; break;
277 case Preferences::TimeToText50Frame: fps = 50; break; 296 case Preferences::TimeToText50Frame: fps = 50; break;
278 case Preferences::TimeToText60Frame: fps = 60; break; 297 case Preferences::TimeToText60Frame: fps = 60; break;
279 } 298 }
280 if (fps != 0) return toFrameText(fps, hms); 299 if (fps != 0) {
300 return toFrameText(fps, hms, frameDelimiter);
301 }
281 } 302 }
282 303
283 return toMSText(fixedDp, hms); 304 return toMSText(fixedDp, hms);
284 } 305 }
285 306
342 363
343 return s; 364 return s;
344 } 365 }
345 366
346 std::string 367 std::string
347 RealTime::toFrameText(int fps, bool hms) const 368 RealTime::toFrameText(int fps, bool hms, std::string frameDelimiter) const
348 { 369 {
349 if (*this < RealTime::zeroTime) return "-" + (-*this).toFrameText(fps, hms); 370 if (*this < RealTime::zeroTime) {
371 return "-" + (-*this).toFrameText(fps, hms);
372 }
350 373
351 std::stringstream out; 374 std::stringstream out;
352 375
353 writeSecPart(out, hms, sec); 376 writeSecPart(out, hms, sec);
354 377
361 int n = fps - 1; 384 int n = fps - 1;
362 while ((n = n / 10)) { 385 while ((n = n / 10)) {
363 div *= 10; 386 div *= 10;
364 } 387 }
365 388
366 out << ":"; 389 out << frameDelimiter;
367 390
368 // cerr << "div = " << div << ", f = "<< f << endl; 391 // cerr << "div = " << div << ", f = "<< f << endl;
369 392
370 while (div) { 393 while (div) {
371 int d = (f / div) % 10; 394 int d = (f / div) % 10;