]> git.sesse.net Git - kdenlive/blob - src/gentime.h
Reindent the codebase using 'linux' bracket placement.
[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 /**Encapsulates a time, which can be set in various forms and outputted in various forms.
24   *@author Jason Wood
25   */
26
27 class GenTime
28 {
29 public:
30     /** Creates a time object, with a time of 0 seconds. */
31     GenTime();
32
33     /** Creates a time object, with time given in seconds. */
34     explicit GenTime(double seconds);
35
36     /** Creates a time object, by passing number of frames and how many frames per second */
37     GenTime(int frames, double framesPerSecond);
38
39     /** returns the time, in seconds */
40     double seconds() const {
41         return m_time;
42     }
43     /** Returns the time, in milliseconds */ double ms() const;
44
45     /** Returns the time in frames, after being given the number of frames per second */
46     double frames(double framesPerSecond) const;
47
48     GenTime & operator+=(GenTime op) {
49         m_time += op.m_time;
50         return *this;
51     }
52     /** Adds two GenTimes */ GenTime operator+(GenTime op) const {
53         return GenTime(m_time + op.m_time);
54     }
55     /** Subtracts one genTime from another */ GenTime operator-(GenTime op) const {
56         return GenTime(m_time - op.m_time);
57     }
58     /** Multiplies one GenTime by a double value, returning a GenTime */
59     GenTime operator*(double op) const {
60         return GenTime(m_time * op);
61     }
62     /** Divides one GenTime by a double value, returning a GenTime */
63     GenTime operator/(double op) const {
64         return GenTime(m_time / op);
65     }
66     /* Implementation of < operator; Works identically as with basic types. */
67     bool operator<(GenTime op) const {
68         return m_time + s_delta < op.m_time;
69     }
70     /* Implementation of > operator; Works identically as with basic types. */
71     bool operator>(GenTime op) const {
72         return m_time > op.m_time + s_delta;
73     }
74     /* Implementation of >= operator; Works identically as with basic types. */
75     bool operator>=(GenTime op) const {
76         return m_time + s_delta >= op.m_time;
77     }
78     /* Implementation of <= operator; Works identically as with basic types. */
79     bool operator<=(GenTime op) const {
80         return m_time <= op.m_time + s_delta;
81     }
82     /* Implementation of == operator; Works identically as with basic types. */
83     bool operator==(GenTime op) const {
84         return fabs(m_time - op.m_time) < s_delta;
85     }
86     /* Implementation of != operator; Works identically as with basic types. */
87     bool operator!=(GenTime op) const {
88         return fabs(m_time - op.m_time) >= s_delta;
89     }
90     /* Rounds the GenTIme's value to the nearest frame */
91     GenTime & roundNearestFrame(double framesPerSecond) {
92         m_time = floor((m_time * framesPerSecond) + 0.5) / framesPerSecond;
93         return *this;
94     }
95
96     ~GenTime();
97 private:   // Private attributes
98     /** Holds the time for this object. */
99     double m_time;
100
101     /** A delta value that is used to get around floating point rounding issues. */
102     static double s_delta;
103 };
104
105 #endif