File indexing completed on 2022-11-29 14:07:21

0001 /*
0002    SPDX-FileCopyrightText: 2003 Jason Wood <jasonwood@blueyonder.co.uk>
0003    SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #pragma once
0007 
0008 #include <QString>
0009 
0010 #include "gentime.h"
0011 
0012 /**
0013  * Handles the conversion of a GenTime into a nicely formatted string, taking into account things such as drop frame if necessary.
0014  * Handles multiple formats, such as HH:MM:SS:FF, HH:MM:SS:F, All Frames, All Seconds, etc.
0015  *
0016  * For 29.97, 59.94, or 23.976 fps, the drop-frame timecode is used: For this frame rate, frames 0 and 1 are dropped every minute
0017  * but not every 10th to fix time shift; see https://en.wikipedia.org/wiki/SMPTE_timecode for details.
0018  *
0019  * To distinguish between normal and drop-frame timecode, they use a different format.
0020  *
0021  * HH:MM:SS:FF → Normal time code in hour/minute/second/frame format
0022  * HH:MM:SS,FF → Drop-frame time code
0023  *
0024  * @author Jason Wood
0025 */
0026 class Timecode
0027 {
0028 public:
0029     enum Formats { HH_MM_SS_FF, HH_MM_SS_HH, Frames, Seconds };
0030 
0031     explicit Timecode(Formats format = HH_MM_SS_FF, double framesPerSecond = 25);
0032 
0033     /**
0034      * Set the current timecode format; this is the output format for this timecode.
0035      */
0036     void setFormat(double framesPerSecond, Formats format = HH_MM_SS_FF);
0037 
0038     Formats format() const;
0039 
0040     ~Timecode();
0041 
0042     /** Returns the timecode for a given time */
0043     QString getDisplayTimecode(const GenTime &time, bool frameDisplay) const;
0044     QString getTimecode(const GenTime &time) const;
0045     int getFrameCount(const QString &duration) const;
0046     static QString getStringTimecode(int frames, const double &fps, bool showFrames = false);
0047     const QString getDisplayTimecodeFromFrames(int frames, bool frameDisplay) const;
0048     const QString getTimecodeFromFrames(int frames) const;
0049     double fps() const;
0050     const QString mask(const GenTime &t = GenTime()) const;
0051     QString reformatSeparators(QString duration) const;
0052 
0053 private:
0054     Formats m_format;
0055     bool m_dropFrameTimecode;
0056     int m_displayedFramesPerSecond;
0057     double m_realFps;
0058     double m_dropFrames;
0059     int m_framesPer10Minutes;
0060 
0061     const QString getTimecodeHH_MM_SS_FF(const GenTime &time) const;
0062     const QString getTimecodeHH_MM_SS_FF(int frames) const;
0063 
0064     const QString getTimecodeHH_MM_SS_HH(const GenTime &time) const;
0065     const QString getTimecodeFrames(const GenTime &time) const;
0066     const QString getTimecodeSeconds(const GenTime &time) const;
0067     const QString getTimecodeDropFrame(const GenTime &time) const;
0068     const QString getTimecodeDropFrame(int framenumber) const;
0069 };