]> git.sesse.net Git - kdenlive/blobdiff - src/timecode.cpp
Improved Dvd Wizard (new chapters dialog)
[kdenlive] / src / timecode.cpp
index deb86526ae6e0676d109251c427b21c2142e5c79..e2fe09e26a0eb38d0ece6b2ce324e33e6db3a577 100644 (file)
 #include <kdebug.h>
 #include <klocale.h>
 
-Timecode::Timecode(Formats format, int framesPerSecond,
-                   bool dropFrame): m_format(format), m_dropFrame(dropFrame),
-        m_displayedFramesPerSecond(framesPerSecond) {
+Timecode::Timecode(Formats format, int framesPerSecond, bool dropFrame) :
+        m_format(format),
+        m_dropFrame(dropFrame),
+        m_displayedFramesPerSecond(framesPerSecond)
+{
 }
 
-Timecode::~Timecode() {
+Timecode::~Timecode()
+{
+}
+
+int Timecode::fps() const
+{
+    return m_displayedFramesPerSecond;
 }
 
 
-int Timecode::getFrameCount(const QString duration, double fps) const {
+int Timecode::getFrameCount(const QString duration, double fps) const
+{
     if (m_dropFrame) {
         // calculate how many frames need to be dropped every minute.
         int frames;
@@ -43,8 +52,8 @@ int Timecode::getFrameCount(const QString duration, double fps) const {
 
         // Number of actual frames in a 10 minute interval :
         int tenMinutes = (normalMinuteFrames * 9) + tenthMinuteFrames;
-        frames = 6 * duration.section(":", 0, 0).toInt() * tenMinutes;
-        int minutes = duration.section(":", 1, 1).toInt();
+        frames = 6 * duration.section(':', 0, 0).toInt() * tenMinutes;
+        int minutes = duration.section(':', 1, 1).toInt();
         frames += ((int) minutes / 10) * tenMinutes;
         int mins = minutes % 10;
         if (mins > 0) {
@@ -53,13 +62,14 @@ int Timecode::getFrameCount(const QString duration, double fps) const {
             if (mins > 0) frames += mins * normalMinuteFrames;
         }
         if (minutes % 10 > 0) frames -= perMinute;
-        frames += duration.section(":", 2, 2).toInt() * m_displayedFramesPerSecond + duration.section(":", 3, 3).toInt();
+        frames += duration.section(':', 2, 2).toInt() * m_displayedFramesPerSecond + duration.section(':', 3, 3).toInt();
         return frames;
     }
-    return (int)((duration.section(":", 0, 0).toInt()*3600.0 + duration.section(":", 1, 1).toInt()*60.0 + duration.section(":", 2, 2).toInt()) * fps + duration.section(":", 3, 3).toInt());
+    return (int)((duration.section(':', 0, 0).toInt()*3600.0 + duration.section(':', 1, 1).toInt()*60.0 + duration.section(':', 2, 2).toInt()) * fps + duration.section(':', 3, 3).toInt());
 }
 
-QString Timecode::getTimecode(const GenTime & time, double fps) const {
+QString Timecode::getTimecode(const GenTime & time, double fps) const
+{
     switch (m_format) {
     case HH_MM_SS_FF:
         return getTimecodeHH_MM_SS_FF(time, fps);
@@ -81,12 +91,34 @@ QString Timecode::getTimecode(const GenTime & time, double fps) const {
     }
 }
 
-QString Timecode::getTimecodeFromFrames(int frames) {
+QString Timecode::getTimecodeFromFrames(int frames)
+{
     return getTimecodeHH_MM_SS_FF(frames);
 }
 
+
 //static
-QString Timecode::getEasyTimecode(const GenTime & time, const double &fps) {
+QString Timecode::getStringTimecode(int frames, const double &fps)
+{
+    // Returns the timecode in an hh:mm:ss format
+    int seconds = frames / (int) floor(fps + 0.5);
+    int minutes = seconds / 60;
+    seconds = seconds % 60;
+    int hours = minutes / 60;
+    minutes = minutes % 60;
+    QString text;
+    text.append(QString::number(hours).rightJustified(2, '0', false));
+    text.append(':');
+    text.append(QString::number(minutes).rightJustified(2, '0', false));
+    text.append(':');
+    text.append(QString::number(seconds).rightJustified(2, '0', false));
+    return text;
+}
+
+
+//static
+QString Timecode::getEasyTimecode(const GenTime & time, const double &fps)
+{
     // Returns the timecode in an easily read display, like 3 min. 5 sec.
     int frames = (int)time.frames(fps);
     int seconds = frames / (int) floor(fps + 0.5);
@@ -101,43 +133,45 @@ QString Timecode::getEasyTimecode(const GenTime & time, const double &fps) {
     bool trim = false;
 
     if (hours != 0) {
-        text.append(QString::number(hours).rightJustified(2, '0', FALSE));
-        text.append(" " + i18n("hour") + " ");
+        text.append(QString::number(hours).rightJustified(2, '0', false));
+        text.append(' ' + i18n("hour") + ' ');
         trim = true;
     }
     if (minutes != 0 || trim) {
         if (!trim) {
             text.append(QString::number(minutes));
         } else
-            text.append(QString::number(minutes).rightJustified(2, '0', FALSE));
-        text.append(" " + i18n("min.") + " ");
+            text.append(QString::number(minutes).rightJustified(2, '0', false));
+        text.append(' ' + i18n("min.") + ' ');
         trim = true;
     }
     if (seconds != 0 || trim) {
         if (!trim) {
             text.append(QString::number(seconds));
         } else
-            text.append(QString::number(seconds).rightJustified(2, '0', FALSE));
-        text.append(" " + i18n("sec."));
+            text.append(QString::number(seconds).rightJustified(2, '0', false));
+        text.append(' ' + i18n("sec."));
         trim = true;
     }
     if (!trim) {
         text.append(QString::number(frames));
-        text.append(" " + i18n("frames"));
+        text.append(' ' + i18n("frames"));
     }
 
     return text;
 }
 
 
-QString Timecode::getTimecodeHH_MM_SS_FF(const GenTime & time, double fps) const {
+QString Timecode::getTimecodeHH_MM_SS_FF(const GenTime & time, double fps) const
+{
     if (m_dropFrame)
         return getTimecodeDropFrame(time, fps);
 
     return getTimecodeHH_MM_SS_FF((int)time.frames(fps));
 }
 
-QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const {
+QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const
+{
     int seconds = frames / m_displayedFramesPerSecond;
     frames = frames % m_displayedFramesPerSecond;
 
@@ -147,19 +181,19 @@ QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const {
     minutes = minutes % 60;
 
     QString text;
-
-    text.append(QString::number(hours).rightJustified(2, '0', FALSE));
-    text.append(":");
-    text.append(QString::number(minutes).rightJustified(2, '0', FALSE));
-    text.append(":");
-    text.append(QString::number(seconds).rightJustified(2, '0', FALSE));
-    text.append(":");
-    text.append(QString::number(frames).rightJustified(2, '0', FALSE));
+    text.append(QString::number(hours).rightJustified(2, '0', false));
+    text.append(':');
+    text.append(QString::number(minutes).rightJustified(2, '0', false));
+    text.append(':');
+    text.append(QString::number(seconds).rightJustified(2, '0', false));
+    text.append(':');
+    text.append(QString::number(frames).rightJustified(2, '0', false));
 
     return text;
 }
 
-QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const {
+QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const
+{
     int hundredths = (int)(time.seconds() * 100);
     int seconds = hundredths / 100;
     hundredths = hundredths % 100;
@@ -170,26 +204,29 @@ QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const {
 
     QString text;
 
-    text.append(QString::number(hours).rightJustified(2, '0', FALSE));
-    text.append(":");
-    text.append(QString::number(minutes).rightJustified(2, '0', FALSE));
-    text.append(":");
-    text.append(QString::number(seconds).rightJustified(2, '0', FALSE));
-    text.append(":");
-    text.append(QString::number(hundredths).rightJustified(2, '0', FALSE));
+    text.append(QString::number(hours).rightJustified(2, '0', false));
+    text.append(':');
+    text.append(QString::number(minutes).rightJustified(2, '0', false));
+    text.append(':');
+    text.append(QString::number(seconds).rightJustified(2, '0', false));
+    text.append(':');
+    text.append(QString::number(hundredths).rightJustified(2, '0', false));
 
     return text;
 }
 
-QString Timecode::getTimecodeFrames(const GenTime & time, double fps) const {
+QString Timecode::getTimecodeFrames(const GenTime & time, double fps) const
+{
     return QString::number(time.frames(fps));
 }
 
-QString Timecode::getTimecodeSeconds(const GenTime & time) const {
+QString Timecode::getTimecodeSeconds(const GenTime & time) const
+{
     return QString::number(time.seconds());
 }
 
-QString Timecode::getTimecodeDropFrame(const GenTime & time, double fps) const {
+QString Timecode::getTimecodeDropFrame(const GenTime & time, double fps) const
+{
     // Calculate the timecode using dropframes to remove the difference in fps. Note that this algorithm should work
     // for NTSC times, but is untested for any others - it is in no way an "official" algorithm, unless it's by fluke.
     int frames = (int)time.frames(fps);
@@ -236,14 +273,14 @@ QString Timecode::getTimecodeDropFrame(const GenTime & time, double fps) const {
     // THANK FUCK FOR THAT.
 
     QString text;
-    text.append(QString::number(hours).rightJustified(2, '0', FALSE));
-    text.append(":");
+    text.append(QString::number(hours).rightJustified(2, '0', false));
+    text.append(':');
     text.append(QString::number(tenMinuteIntervals));
     text.append(QString::number(numMinutes));
-    text.append(":");
-    text.append(QString::number(seconds).rightJustified(2, '0', FALSE));
-    text.append(":");
-    text.append(QString::number(frames).rightJustified(2, '0', FALSE));
+    text.append(':');
+    text.append(QString::number(seconds).rightJustified(2, '0', false));
+    text.append(':');
+    text.append(QString::number(frames).rightJustified(2, '0', false));
 
     return text;
 }