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.
29 /** Creates a time object, with a time of 0 seconds. */
32 /** Creates a time object, with time given in seconds. */
33 explicit GenTime(double seconds);
35 /** Creates a time object, by passing number of frames and how many frames per second */
36 GenTime(int frames, double framesPerSecond);
38 /** returns the time, in seconds */
39 double seconds() const {
42 /** Returns the time, in milliseconds */ double ms() const;
44 /** Returns the time in frames, after being given the number of frames per second */
45 double frames(double framesPerSecond) const;
47 GenTime & operator+=(GenTime op) {
51 /** Adds two GenTimes */ GenTime operator+(GenTime op) const {
52 return GenTime(m_time + op.m_time);
54 /** Subtracts one genTime from another */ GenTime operator-(GenTime op) const {
55 return GenTime(m_time - op.m_time);
57 /** Multiplies one GenTime by a double value, returning a GenTime */
58 GenTime operator*(double op) const {
59 return GenTime(m_time * op);
61 /** Divides one GenTime by a double value, returning a GenTime */
62 GenTime operator/(double op) const {
63 return GenTime(m_time / op);
65 /* Implementation of < operator; Works identically as with basic types. */
66 bool operator<(GenTime op) const {
67 return m_time + s_delta < op.m_time;
69 /* Implementation of > operator; Works identically as with basic types. */
70 bool operator>(GenTime op) const {
71 return m_time > op.m_time + s_delta;
73 /* Implementation of >= operator; Works identically as with basic types. */
74 bool operator>=(GenTime op) const {
75 return m_time + s_delta >= op.m_time;
77 /* Implementation of <= operator; Works identically as with basic types. */
78 bool operator<=(GenTime op) const {
79 return m_time <= op.m_time + s_delta;
81 /* Implementation of == operator; Works identically as with basic types. */
82 bool operator==(GenTime op) const {
83 return fabs(m_time - op.m_time) < s_delta;
85 /* Implementation of != operator; Works identically as with basic types. */
86 bool operator!=(GenTime op) const {
87 return fabs(m_time - op.m_time) >= s_delta;
89 /* Rounds the GenTIme's value to the nearest frame */
90 GenTime & roundNearestFrame(double framesPerSecond) {
91 m_time = floor((m_time * framesPerSecond) + 0.5) / framesPerSecond;
96 private: // Private attributes
97 /** Holds the time for this object. */
100 /** A delta value that is used to get around floating point rounding issues. */
101 static double s_delta;