1 /***************************************************************************
4 begin : Sat Sep 14 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
23 /**Encapsulates a time, which can be set in various forms and outputted in various forms.
30 /** Creates a time object, with a time of 0 seconds. */
33 /** Creates a time object, with time given in seconds. */
34 explicit GenTime(double seconds);
36 /** Creates a time object, by passing number of frames and how many frames per second */
37 GenTime(int frames, double framesPerSecond);
39 /** returns the time, in seconds */
40 double seconds() const {
43 /** Returns the time, in milliseconds */ double ms() const;
45 /** Returns the time in frames, after being given the number of frames per second */
46 double frames(double framesPerSecond) const;
48 GenTime & operator+=(GenTime op) {
52 /** Adds two GenTimes */ GenTime operator+(GenTime op) const {
53 return GenTime(m_time + op.m_time);
55 /** Subtracts one genTime from another */ GenTime operator-(GenTime op) const {
56 return GenTime(m_time - op.m_time);
58 /** Multiplies one GenTime by a double value, returning a GenTime */
59 GenTime operator*(double op) const {
60 return GenTime(m_time * op);
62 /** Divides one GenTime by a double value, returning a GenTime */
63 GenTime operator/(double op) const {
64 return GenTime(m_time / op);
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;
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;
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;
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;
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;
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;
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;
97 private: // Private attributes
98 /** Holds the time for this object. */
101 /** A delta value that is used to get around floating point rounding issues. */
102 static double s_delta;