Mercurial > hg > svcore
diff base/RealTime.cpp @ 612:75f154085a4d
* Add time display format preference
author | Chris Cannam |
---|---|
date | Fri, 25 Sep 2009 12:02:22 +0000 |
parents | 81963c51b488 |
children | 06f13a3b9e9e |
line wrap: on
line diff
--- a/base/RealTime.cpp Fri Sep 11 15:42:32 2009 +0000 +++ b/base/RealTime.cpp Fri Sep 25 12:02:22 2009 +0000 @@ -21,13 +21,7 @@ #include <iostream> #include <cstdlib> - -#if (__GNUC__ < 3) -#include <strstream> -#define stringstream strstream -#else #include <sstream> -#endif using std::cerr; using std::endl; @@ -35,6 +29,8 @@ #include "RealTime.h" #include "sys/time.h" +#include "Preferences.h" + // A RealTime consists of two ints that must be at least 32 bits each. // A signed 32-bit int can store values exceeding +/- 2 billion. This // means we can safely use our lower int for nanoseconds, as there are @@ -197,10 +193,6 @@ std::stringstream out; out << *this; -#if (__GNUC__ < 3) - out << std::ends; -#endif - std::string s = out.str(); if (!align && *this >= RealTime::zeroTime) { @@ -261,6 +253,21 @@ { if (*this < RealTime::zeroTime) return "-" + (-*this).toText(fixedDp); + Preferences *p = Preferences::getInstance(); + if (p) { + int fps = 0; + switch (p->getTimeToTextMode()) { + case Preferences::TimeToTextMs: break; + case Preferences::TimeToTextUs: fps = 1000000; break; + case Preferences::TimeToText24Frame: fps = 24; break; + case Preferences::TimeToText25Frame: fps = 25; break; + case Preferences::TimeToText30Frame: fps = 30; break; + case Preferences::TimeToText50Frame: fps = 50; break; + case Preferences::TimeToText60Frame: fps = 60; break; + } + if (fps != 0) return toFrameText(fps); + } + std::stringstream out; if (sec >= 3600) { @@ -298,12 +305,54 @@ out << ".000"; } -#if (__GNUC__ < 3) - out << std::ends; -#endif + std::string s = out.str(); + return s; +} + +std::string +RealTime::toFrameText(int fps) const +{ + if (*this < RealTime::zeroTime) return "-" + (-*this).toFrameText(fps); + + std::stringstream out; + + if (sec >= 3600) { + out << (sec / 3600) << ":"; + } + + if (sec >= 60) { + out << (sec % 3600) / 60 << ":"; + } + + if (sec >= 10) { + out << ((sec % 60) / 10); + } + + out << (sec % 10); + + int f = nsec / (ONE_BILLION / fps); + + int div = 1; + int n = fps - 1; + while ((n = n / 10)) { + div *= 10; + } + + out << ":"; + + std::cerr << "div = " << div << ", f = "<< f << std::endl; + + while (div) { + int d = (f / div) % 10; + out << d; + div /= 10; + } + std::string s = out.str(); + std::cerr << "converted " << toString() << " to " << s << std::endl; + return s; } @@ -332,11 +381,6 @@ out << "s"; } - -#if (__GNUC__ < 3) - out << std::ends; -#endif - std::string s = out.str(); return s;