- if (m_dropFrame) {
- // calculate how many frames need to be dropped every minute.
- int frames;
- int toDrop = (int) floor (600.0 * (m_displayedFramesPerSecond - fps) + 0.5);
-
- int perMinute = toDrop / 9;
- int tenthMinute = toDrop % 9;
-
- // calculate how many frames are in a normal minute, and how many are in a tenth minute.
- int normalMinuteFrames = (m_displayedFramesPerSecond * 60) - perMinute;
- int tenthMinuteFrames = (m_displayedFramesPerSecond * 60) - tenthMinute;;
-
- // 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 += ((int) minutes / 10) * tenMinutes;
- int mins = minutes % 10;
- if (mins > 0) {
- frames += tenthMinuteFrames;
- mins--;
- 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();
- return frames;
+ m_displayedFramesPerSecond = (int)(framesPerSecond + 0.5);
+ m_dropFrameTimecode = (framesPerSecond / 1.00 != (int)framesPerSecond) ;
+ m_format = format;
+ m_realFps = framesPerSecond;
+ 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
+ }
+}
+
+double Timecode::fps() const
+{
+ return m_realFps;
+}
+
+bool Timecode::df() const
+{
+ return m_dropFrameTimecode;
+}
+
+const QString Timecode::mask(const GenTime& t) const
+{
+ if (t < GenTime()) {
+ if (m_dropFrameTimecode) return "#99:99:99,99";
+ else return "#99:99:99:99";
+ }
+ if (m_dropFrameTimecode) return "99:99:99,99";
+ else return "99:99:99:99";
+}
+
+QString Timecode::reformatSeparators(QString duration) const
+{
+ if (m_dropFrameTimecode)
+ return duration.replace(8, 1, ',');
+ return duration.replace(8, 1, ':');
+}
+
+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 (duration.isEmpty()) {
+ return 0;
+ }
+ int hours, minutes, seconds, frames;
+ int offset = 0;
+ if (duration.at(0) == '-') {
+ offset = 1;
+ hours = duration.mid(1, 2).toInt();
+ } else {
+ hours = duration.left(2).toInt();
+ }
+ minutes = duration.mid(3 + offset, 2).toInt();
+ seconds = duration.mid(6 + offset, 2).toInt();
+ frames = duration.right(2).toInt();
+ if (m_dropFrameTimecode) {
+ //CONVERT DROP FRAME TIMECODE TO A FRAME NUMBER
+ //Code by David Heidelberger, adapted from Andrew Duncan
+ //Given ints called hours, minutes, seconds, frames, and a double called framerate
+
+ int totalMinutes = (60 * hours) + minutes; //Total number of minutes
+ int frameNumber = ((m_displayedFramesPerSecond * 3600 * hours) + (m_displayedFramesPerSecond * 60 * minutes) + (m_displayedFramesPerSecond * seconds) + frames) - (m_dropFrames * (totalMinutes - floor(totalMinutes / 10)));
+ return frameNumber;