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