]> git.sesse.net Git - kdenlive/blob - src/gentime.h
Fix indent
[kdenlive] / src / gentime.h
1 /***************************************************************************
2                           time.h  -  description
3                              -------------------
4     begin                : Sat Sep 14 2002
5     copyright            : (C) 2002 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
18 #ifndef GENTIME_H
19 #define GENTIME_H
20
21 #include <QString>
22 #include <cmath>
23
24 /**
25  * @class GenTime
26  * @brief Encapsulates a time, which can be set in various forms and outputted in various forms.
27  * @author Jason Wood
28  */
29
30 class GenTime
31 {
32 public:
33     /** @brief Creates a GenTime object, with a time of 0 seconds. */
34     GenTime();
35
36     /** @brief Creates a GenTime object, with time given in seconds. */
37     explicit GenTime(double seconds);
38
39     /** @brief Creates a GenTime object, by passing number of frames and how many frames per second. */
40     GenTime(int frames, double framesPerSecond);
41
42     /** @brief Gets the time, in seconds. */
43     double seconds() const;
44
45     /** @brief Gets the time, in milliseconds */
46     double ms() const;
47
48     /** @brief Gets the time in frames.
49     * @param framesPerSecond Number of frames per second */
50     double frames(double framesPerSecond) const;
51
52     /** @brief Rounds the GenTime's value to the nearest frame.
53     * @param framesPerSecond Number of frames per second */
54     GenTime & roundNearestFrame(double framesPerSecond);
55
56     QString toString() const;
57
58
59     /*
60      * Operators.
61      */
62
63     /// Unary minus
64     GenTime operator -() {
65         return GenTime(-m_time);
66     }
67     
68     /// Addition
69     GenTime & operator+=(GenTime op) {
70         m_time += op.m_time;
71         return *this;
72     }
73
74     /// Subtraction
75     GenTime & operator-=(GenTime op) {
76         m_time -= op.m_time;
77         return *this;
78     }
79
80     /** @brief Adds two GenTimes. */
81     GenTime operator+(GenTime op) const {
82         return GenTime(m_time + op.m_time);
83     }
84
85     /** @brief Subtracts one genTime from another. */
86     GenTime operator-(GenTime op) const {
87         return GenTime(m_time - op.m_time);
88     }
89
90     /** @brief Multiplies one GenTime by a double value, returning a GenTime. */
91     GenTime operator*(double op) const {
92         return GenTime(m_time * op);
93     }
94
95     /** @brief Divides one GenTime by a double value, returning a GenTime. */
96     GenTime operator/(double op) const {
97         return GenTime(m_time / op);
98     }
99
100     bool operator<(GenTime op) const {
101         return m_time + s_delta < op.m_time;
102     }
103
104     bool operator>(GenTime op) const {
105         return m_time > op.m_time + s_delta;
106     }
107
108     bool operator>=(GenTime op) const {
109         return m_time + s_delta >= op.m_time;
110     }
111
112     bool operator<=(GenTime op) const {
113         return m_time <= op.m_time + s_delta;
114     }
115
116     bool operator==(GenTime op) const {
117         return fabs(m_time - op.m_time) < s_delta;
118     }
119
120     bool operator!=(GenTime op) const {
121         return fabs(m_time - op.m_time) >= s_delta;
122     }
123
124 private:
125     /** Holds the time in seconds for this object. */
126     double m_time;
127
128     /** A delta value that is used to get around floating point rounding issues. */
129     static double s_delta;
130 };
131
132 #endif