#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
}
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));
{
// 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));
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") + ' ');
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));
}
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;
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));
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;
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));
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;
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));