]> git.sesse.net Git - kdenlive/blob - src/timecode.h
- Fix drop frame timecode format. [1]
[kdenlive] / src / timecode.h
1 /***************************************************************************
2                         timecode  -  description
3                            -------------------
4   begin                : Wed Dec 17 2003
5   copyright            : (C) 2003 by Jason Wood
6   email                : jasonwood@blueyonder.co.uk
7 ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 #ifndef TIMECODE_H
18 #define TIMECODE_H
19
20 #include <QString>
21
22 #include "gentime.h"
23
24 class QValidator;
25 class QRegExpValidator;
26
27 /**
28 Handles the conversion of a GenTime into a nicely formatted string, taking into account things such as drop frame if necessary. Handles multiple formats, such as HH:MM:SS:FF, HH:MM:SS:F, All Frames, All Seconds, etc.
29
30 @author Jason Wood
31 */
32 class Timecode
33 {
34 public:
35     enum Formats { HH_MM_SS_FF, HH_MM_SS_HH, Frames, Seconds };
36
37     explicit Timecode(Formats format = HH_MM_SS_FF, double framesPerSecond = 25,
38                       bool dropFrame = false);
39
40     /**
41      * Set the current timecode format; this is the output format for this timecode.
42      */
43     void setFormat(double framesPerSecond, bool dropFrame = false,
44                    Formats format = HH_MM_SS_FF);
45
46     Formats format() const {
47         return m_format;
48     }
49
50     ~Timecode();
51
52     /** Returns the timecode for a given time */
53     QString getDisplayTimecode(const GenTime & time, bool frameDisplay) const;
54     QString getTimecode(const GenTime & time) const;
55     int getDisplayFrameCount(const QString duration, bool frameDisplay) const;
56     int getFrameCount(const QString duration) const;
57     static QString getEasyTimecode(const GenTime & time, const double &fps);
58     static QString getStringTimecode(int frames, const double &fps);
59     const QString getDisplayTimecodeFromFrames(int frames, bool frameDisplay) const;
60     const QString getTimecodeFromFrames(int frames) const;
61     double fps() const;
62     bool df() const;
63     const QValidator *validator() const;
64     QString reformatSeparators(QString duration) const;
65
66 private:
67     Formats m_format;
68     bool m_dropFrame;
69     int m_displayedFramesPerSecond;
70     double m_realFps;
71     QRegExpValidator *m_validator;
72
73     const QString getTimecodeHH_MM_SS_FF(const GenTime & time) const;
74     const QString getTimecodeHH_MM_SS_FF(int frames) const;
75
76     QString getTimecodeHH_MM_SS_HH(const GenTime & time) const;
77     QString getTimecodeFrames(const GenTime & time) const;
78     QString getTimecodeSeconds(const GenTime & time) const;
79     QString getTimecodeDropFrame(const GenTime & time) const;
80     QString getTimecodeDropFrame(int frames) const;
81 };
82
83 #endif