File indexing completed on 2024-10-06 04:27:54

0001 /*
0002     SPDX-FileCopyrightText: 2002 Jason Wood <jasonwood@blueyonder.co.uk>
0003 
0004     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "gentime.h"
0008 
0009 double GenTime::s_delta = 0.00001;
0010 
0011 GenTime::GenTime()
0012 {
0013     m_time = 0.0;
0014 }
0015 
0016 GenTime::GenTime(double seconds)
0017 {
0018     m_time = seconds;
0019 }
0020 
0021 GenTime::GenTime(int frames, double framesPerSecond)
0022 {
0023     m_time = (double)frames / framesPerSecond;
0024 }
0025 
0026 double GenTime::seconds() const
0027 {
0028     return m_time;
0029 }
0030 
0031 double GenTime::ms() const
0032 {
0033     return m_time * 1000;
0034 }
0035 
0036 int GenTime::frames(double framesPerSecond) const
0037 {
0038     return (int)floor(m_time * framesPerSecond + 0.5);
0039 }
0040 
0041 QString GenTime::toString() const
0042 {
0043     return QStringLiteral("%1 s").arg(m_time, 0, 'f', 2);
0044 }
0045 
0046 GenTime GenTime::operator-()
0047 {
0048     return GenTime(-m_time);
0049 }
0050 
0051 GenTime &GenTime::operator+=(GenTime op)
0052 {
0053     m_time += op.m_time;
0054     return *this;
0055 }
0056 
0057 GenTime &GenTime::operator-=(GenTime op)
0058 {
0059     m_time -= op.m_time;
0060     return *this;
0061 }
0062 
0063 GenTime GenTime::operator+(GenTime op) const
0064 {
0065     return GenTime(m_time + op.m_time);
0066 }
0067 
0068 GenTime GenTime::operator-(GenTime op) const
0069 {
0070     return GenTime(m_time - op.m_time);
0071 }
0072 
0073 GenTime GenTime::operator*(double op) const
0074 {
0075     return GenTime(m_time * op);
0076 }
0077 
0078 GenTime GenTime::operator/(double op) const
0079 {
0080     return GenTime(m_time / op);
0081 }
0082 
0083 bool GenTime::operator<(GenTime op) const
0084 {
0085     return m_time + s_delta < op.m_time;
0086 }
0087 
0088 bool GenTime::operator>(GenTime op) const
0089 {
0090     return m_time > op.m_time + s_delta;
0091 }
0092 
0093 bool GenTime::operator>=(GenTime op) const
0094 {
0095     return m_time + s_delta >= op.m_time;
0096 }
0097 
0098 bool GenTime::operator<=(GenTime op) const
0099 {
0100     return m_time <= op.m_time + s_delta;
0101 }
0102 
0103 bool GenTime::operator==(GenTime op) const
0104 {
0105     return fabs(m_time - op.m_time) < s_delta;
0106 }
0107 
0108 bool GenTime::operator!=(GenTime op) const
0109 {
0110     return fabs(m_time - op.m_time) >= s_delta;
0111 }
0112 
0113 // static
0114 void GenTime::setFps(double fps)
0115 {
0116     s_delta = 0.9 / fps;
0117 }