]> git.sesse.net Git - kdenlive/blobdiff - src/timecode.cpp
code cleanup
[kdenlive] / src / timecode.cpp
index 28b75c91d3db436e5c91efe4c5e7d64be15482c3..1b25df21f13adaf5a5de50bd488ab890d36c4cab 100644 (file)
@@ -23,7 +23,7 @@ Timecode::Timecode(Formats format, double framesPerSecond, bool dropFrame) :
         m_format(format),
         m_dropFrame(dropFrame),
         m_displayedFramesPerSecond(framesPerSecond + 0.5),
-       m_realFps(framesPerSecond)
+        m_realFps(framesPerSecond)
 {
 }
 
@@ -31,12 +31,18 @@ Timecode::~Timecode()
 {
 }
 
-int Timecode::fps() const
+double Timecode::fps() const
 {
-    return m_displayedFramesPerSecond;
+    return m_realFps; //m_displayedFramesPerSecond;
 }
 
 
+int Timecode::getDisplayFrameCount(const QString duration, bool frameDisplay) const
+{
+    if (frameDisplay) return duration.toInt();
+    return getFrameCount(duration);
+}
+
 int Timecode::getFrameCount(const QString duration) const
 {
     if (m_dropFrame) {
@@ -69,6 +75,12 @@ int Timecode::getFrameCount(const QString duration) const
     return (int)((duration.section(':', 0, 0).toInt()*3600.0 + duration.section(':', 1, 1).toInt()*60.0 + duration.section(':', 2, 2).toInt()) * m_realFps + duration.section(':', 3, 3).toInt());
 }
 
+QString Timecode::getDisplayTimecode(const GenTime & time, bool frameDisplay) const
+{
+    if (frameDisplay) return QString::number((int) time.frames(m_realFps));
+    return getTimecode(time);
+}
+
 QString Timecode::getTimecode(const GenTime & time) const
 {
     switch (m_format) {
@@ -92,7 +104,13 @@ QString Timecode::getTimecode(const GenTime & time) const
     }
 }
 
-QString Timecode::getTimecodeFromFrames(int frames) const
+const QString Timecode::getDisplayTimecodeFromFrames(int frames, bool frameDisplay) const
+{
+    if (frameDisplay) return QString::number(frames);
+    return getTimecodeHH_MM_SS_FF(frames);
+}
+
+const QString Timecode::getTimecodeFromFrames(int frames) const
 {
     return getTimecodeHH_MM_SS_FF(frames);
 }
@@ -102,7 +120,7 @@ QString Timecode::getTimecodeFromFrames(int frames) const
 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 seconds = (int)(frames / fps);
     int minutes = seconds / 60;
     seconds = seconds % 60;
     int hours = minutes / 60;
@@ -121,9 +139,9 @@ QString Timecode::getStringTimecode(int frames, const double &fps)
 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);
-    frames = frames % ((int) fps);
+    int frames = (int) time.frames(fps);
+    int seconds = (int)(frames / fps);
+    frames = frames - ((int)(fps * seconds));
 
     int minutes = seconds / 60;
     seconds = seconds % 60;
@@ -163,7 +181,7 @@ QString Timecode::getEasyTimecode(const GenTime & time, const double &fps)
 }
 
 
-QString Timecode::getTimecodeHH_MM_SS_FF(const GenTime & time) const
+const QString Timecode::getTimecodeHH_MM_SS_FF(const GenTime & time) const
 {
     if (m_dropFrame)
         return getTimecodeDropFrame(time);
@@ -171,10 +189,10 @@ QString Timecode::getTimecodeHH_MM_SS_FF(const GenTime & time) const
     return getTimecodeHH_MM_SS_FF((int) time.frames(m_realFps));
 }
 
-QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const
+const QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const
 {
     if (m_dropFrame) {
-       return getTimecodeDropFrame(frames);
+        return getTimecodeDropFrame(frames);
     }
     int seconds = frames / m_displayedFramesPerSecond;
     frames = frames % m_displayedFramesPerSecond;
@@ -241,7 +259,7 @@ QString Timecode::getTimecodeDropFrame(int frames) const
 
     // calculate how many frames need to be dropped every minute.
     int toDrop = (int) floor(600.0 * (m_displayedFramesPerSecond - m_realFps)  + 0.5);
-    
+
     int perMinute = toDrop / 9;
     int tenthMinute = toDrop % 9;