X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Ftimecode.cpp;h=3b5749773f5a3ffe26051b57e0a88c6ae0b5746c;hb=b691c7f8faddc1d7f2bf6acdba5cee879e810548;hp=83ed7d77044a36ba05cdd90e4e2977516d387bb1;hpb=ca29ebdd78229edb2eb03d75a846ab116c5c970e;p=kdenlive diff --git a/src/timecode.cpp b/src/timecode.cpp index 83ed7d77..3b574977 100644 --- a/src/timecode.cpp +++ b/src/timecode.cpp @@ -87,23 +87,23 @@ return frameNumber; #include "timecode.h" -Timecode::Timecode(Formats format, double framesPerSecond, bool dropFrame) +Timecode::Timecode(Formats format, double framesPerSecond) { m_validator = new QRegExpValidator(0); - setFormat(framesPerSecond, dropFrame, format); + setFormat(framesPerSecond, format); } Timecode::~Timecode() { } -void Timecode::setFormat(double framesPerSecond, bool dropFrame, Formats format) +void Timecode::setFormat(double framesPerSecond, Formats format) { m_displayedFramesPerSecond = (int)(framesPerSecond + 0.5); - m_dropFrameTimecode = dropFrame; + m_dropFrameTimecode = (framesPerSecond / 1.00 != (int)framesPerSecond) ; m_format = format; m_realFps = framesPerSecond; - if (dropFrame) { + if (m_dropFrameTimecode) { m_dropFrames = round(m_realFps * .066666); //Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate m_framesPer10Minutes = round(m_realFps * 600); //Number of frames per ten minutes } @@ -217,12 +217,21 @@ const QString Timecode::getTimecodeFromFrames(int frames) const QString Timecode::getStringTimecode(int frames, const double &fps) { // Returns the timecode in an hh:mm:ss format + + bool negative = false; + if (frames < 0) { + negative = true; + frames = qAbs(frames); + } + int seconds = (int)(frames / fps); int minutes = seconds / 60; seconds = seconds % 60; int hours = minutes / 60; minutes = minutes % 60; QString text; + if (negative) + text.append('-'); text.append(QString::number(hours).rightJustified(2, '0', false)); text.append(':'); text.append(QString::number(minutes).rightJustified(2, '0', false)); @@ -237,6 +246,13 @@ 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); + + bool negative = false; + if (frames < 0) { + negative = true; + frames = qAbs(frames); + } + int seconds = (int)(frames / fps); frames = frames - ((int)(fps * seconds)); @@ -248,6 +264,8 @@ QString Timecode::getEasyTimecode(const GenTime & time, const double &fps) QString text; bool trim = false; + if (negative) + text.append('-'); if (hours != 0) { text.append(QString::number(hours).rightJustified(2, '0', false)); text.append(' ' + i18n("hour") + ' '); @@ -280,9 +298,9 @@ QString Timecode::getEasyTimecode(const GenTime & time, const double &fps) const QString Timecode::getTimecodeHH_MM_SS_FF(const GenTime & time) const { - if (m_dropFrameTimecode) + if (m_dropFrameTimecode) { return getTimecodeDropFrame(time); - + } return getTimecodeHH_MM_SS_FF((int) time.frames(m_realFps)); } @@ -291,6 +309,13 @@ const QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const if (m_dropFrameTimecode) { return getTimecodeDropFrame(frames); } + + bool negative = false; + if (frames < 0) { + negative = true; + frames = qAbs(frames); + } + int seconds = frames / m_displayedFramesPerSecond; frames = frames % m_displayedFramesPerSecond; @@ -300,6 +325,8 @@ const QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const minutes = minutes % 60; QString text; + if (negative) + text.append('-'); text.append(QString::number(hours).rightJustified(2, '0', false)); text.append(':'); text.append(QString::number(minutes).rightJustified(2, '0', false)); @@ -311,9 +338,16 @@ const QString Timecode::getTimecodeHH_MM_SS_FF(int frames) const return text; } -QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const +const QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const { int hundredths = (int)(time.seconds() * 100); + + bool negative = false; + if (hundredths < 0) { + negative = true; + hundredths = qAbs(hundredths); + } + int seconds = hundredths / 100; hundredths = hundredths % 100; int minutes = seconds / 60; @@ -322,7 +356,8 @@ QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const minutes = minutes % 60; QString text; - + if (negative) + text.append('-'); text.append(QString::number(hours).rightJustified(2, '0', false)); text.append(':'); text.append(QString::number(minutes).rightJustified(2, '0', false)); @@ -337,35 +372,41 @@ QString Timecode::getTimecodeHH_MM_SS_HH(const GenTime & time) const return text; } -QString Timecode::getTimecodeFrames(const GenTime & time) const +const QString Timecode::getTimecodeFrames(const GenTime & time) const { return QString::number(time.frames(m_realFps)); } -QString Timecode::getTimecodeSeconds(const GenTime & time) const +const QString Timecode::getTimecodeSeconds(const GenTime & time) const { return QString::number(time.seconds()); } -QString Timecode::getTimecodeDropFrame(const GenTime & time) const +const QString Timecode::getTimecodeDropFrame(const GenTime & time) const { return getTimecodeDropFrame((int)time.frames(m_realFps)); } -QString Timecode::getTimecodeDropFrame(int framenumber) const +const QString Timecode::getTimecodeDropFrame(int framenumber) const { //CONVERT A FRAME NUMBER TO DROP FRAME TIMECODE //Based on code by David Heidelberger, adapted from Andrew Duncan //Given an int called framenumber and a double called framerate //Framerate should be 29.97, 59.94, or 23.976, otherwise the calculations will be off. + bool negative = false; + if (framenumber < 0) { + negative = true; + framenumber = qAbs(framenumber); + } + int d = floor(framenumber / m_framesPer10Minutes); int m = framenumber % m_framesPer10Minutes; - if (m > 1) { - framenumber = framenumber + (m_dropFrames * 9 * d) + m_dropFrames * (floor((m - m_dropFrames) / (round(m_realFps * 60) - m_dropFrames))); + if (m > m_dropFrames) { + framenumber += (m_dropFrames * 9 * d) + m_dropFrames * (floor((m - m_dropFrames) / (round(m_realFps * 60) - m_dropFrames))); } else { - framenumber = framenumber + m_dropFrames * 9 * d; + framenumber += m_dropFrames * 9 * d; } int frames = framenumber % m_displayedFramesPerSecond; @@ -374,6 +415,8 @@ QString Timecode::getTimecodeDropFrame(int framenumber) const int hours = floor(floor(floor(framenumber / m_displayedFramesPerSecond) / 60) / 60); QString text; + if (negative) + text.append('-'); text.append(QString::number(hours).rightJustified(2, '0', false)); text.append(':'); text.append(QString::number(minutes).rightJustified(2, '0', false));