# HG changeset patch # User Chris Cannam # Date 1253880142 0 # Node ID 75f154085a4d60f3268533af663ccaac8c6e9b03 # Parent dd97f7b3d120efa543d4f3b5fb16c250e13d51ac * Add time display format preference diff -r dd97f7b3d120 -r 75f154085a4d base/Preferences.cpp --- a/base/Preferences.cpp Fri Sep 11 15:42:32 2009 +0000 +++ b/base/Preferences.cpp Fri Sep 25 12:02:22 2009 +0000 @@ -46,6 +46,7 @@ m_resampleOnLoad(false), m_viewFontSize(10), m_backgroundMode(BackgroundFromTheme), + m_timeToTextMode(TimeToTextMs), m_showSplash(true) { QSettings settings; @@ -63,6 +64,8 @@ m_resampleOnLoad = settings.value("resample-on-load", false).toBool(); m_backgroundMode = BackgroundMode (settings.value("background-mode", int(BackgroundFromTheme)).toInt()); + m_timeToTextMode = TimeToTextMode + (settings.value("time-to-text-mode", int(TimeToTextMs)).toInt()); m_viewFontSize = settings.value("view-font-size", 10).toInt(); m_showSplash = settings.value("show-splash", true).toBool(); settings.endGroup(); @@ -90,6 +93,7 @@ props.push_back("Resample On Load"); props.push_back("Temporary Directory Root"); props.push_back("Background Mode"); + props.push_back("Time To Text Mode"); props.push_back("View Font Size"); props.push_back("Show Splash Screen"); return props; @@ -128,6 +132,9 @@ if (name == "Background Mode") { return tr("Background colour preference"); } + if (name == "Time To Text Mode") { + return tr("Time display format"); + } if (name == "View Font Size") { return tr("Font size for text overlays"); } @@ -171,6 +178,9 @@ if (name == "Background Mode") { return ValueProperty; } + if (name == "Time To Text Mode") { + return ValueProperty; + } if (name == "View Font Size") { return RangeProperty; } @@ -231,6 +241,13 @@ return int(m_backgroundMode); } + if (name == "Time To Text Mode") { + if (min) *min = 0; + if (max) *max = 6; + if (deflt) *deflt = 0; + return int(m_timeToTextMode); + } + if (name == "View Font Size") { if (min) *min = 3; if (max) *max = 48; @@ -294,6 +311,17 @@ case LightBackground: return tr("Light background"); } } + if (name == "Time To Text Mode") { + switch (value) { + case TimeToTextMs: return tr("Standard (to millisecond)"); + case TimeToTextUs: return tr("High resolution (to microsecond)"); + case TimeToText24Frame: return tr("24 FPS"); + case TimeToText25Frame: return tr("25 FPS"); + case TimeToText30Frame: return tr("30 FPS"); + case TimeToText50Frame: return tr("50 FPS"); + case TimeToText60Frame: return tr("60 FPS"); + } + } return ""; } @@ -329,6 +357,8 @@ setOmitTempsFromRecentFiles(value ? true : false); } else if (name == "Background Mode") { setBackgroundMode(BackgroundMode(value)); + } else if (name == "Time To Text Mode") { + setTimeToTextMode(TimeToTextMode(value)); } else if (name == "View Font Size") { setViewFontSize(value); } else if (name == "Show Splash Screen") { @@ -480,6 +510,21 @@ } void +Preferences::setTimeToTextMode(TimeToTextMode mode) +{ + if (m_timeToTextMode != mode) { + + m_timeToTextMode = mode; + + QSettings settings; + settings.beginGroup("Preferences"); + settings.setValue("time-to-text-mode", int(mode)); + settings.endGroup(); + emit propertyChanged("Time To Text Mode"); + } +} + +void Preferences::setViewFontSize(int size) { if (m_viewFontSize != size) { diff -r dd97f7b3d120 -r 75f154085a4d base/Preferences.h --- a/base/Preferences.h Fri Sep 11 15:42:32 2009 +0000 +++ b/base/Preferences.h Fri Sep 25 12:02:22 2009 +0000 @@ -75,6 +75,17 @@ }; BackgroundMode getBackgroundMode() const { return m_backgroundMode; } + enum TimeToTextMode { + TimeToTextMs, + TimeToTextUs, + TimeToText24Frame, + TimeToText25Frame, + TimeToText30Frame, + TimeToText50Frame, + TimeToText60Frame + }; + TimeToTextMode getTimeToTextMode() const { return m_timeToTextMode; } + bool getShowSplash() const { return m_showSplash; } public slots: @@ -90,6 +101,7 @@ void setTemporaryDirectoryRoot(QString tempDirRoot); void setResampleOnLoad(bool); void setBackgroundMode(BackgroundMode mode); + void setTimeToTextMode(TimeToTextMode mode); void setViewFontSize(int size); void setShowSplash(bool); @@ -110,6 +122,7 @@ bool m_resampleOnLoad; int m_viewFontSize; BackgroundMode m_backgroundMode; + TimeToTextMode m_timeToTextMode; bool m_showSplash; }; diff -r dd97f7b3d120 -r 75f154085a4d base/RealTime.cpp --- 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 #include - -#if (__GNUC__ < 3) -#include -#define stringstream strstream -#else #include -#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; diff -r dd97f7b3d120 -r 75f154085a4d base/RealTime.h --- a/base/RealTime.h Fri Sep 11 15:42:32 2009 +0000 +++ b/base/RealTime.h Fri Sep 25 12:02:22 2009 +0000 @@ -127,6 +127,15 @@ std::string toText(bool fixedDp = false) const; /** + * Return a user-readable string in which seconds are divided into + * frames (presumably at a lower frame rate than audio rate, + * e.g. 24 or 25 video frames), in a form like HH:MM:SS:FF. fps + * gives the number of frames per second, and must be integral + * (29.97 not supported). + */ + std::string toFrameText(int fps) const; + + /** * Return a user-readable string to the nearest second, in a form * like "6s" (for less than a minute) or "2:21" (for more). */