X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fgentime.cpp;h=82e0d9c7a61839795d273abea24aa9c102af7d8a;hb=56aee6aedeeed3efd10ada8fe3c229eddc01ef05;hp=5bb266648fce7d28bb1f8e1bd936d7dff073a711;hpb=2a223cff6e45c560c28857b72c0cb7e584f9a4ef;p=kdenlive diff --git a/src/gentime.cpp b/src/gentime.cpp index 5bb26664..82e0d9c7 100644 --- a/src/gentime.cpp +++ b/src/gentime.cpp @@ -19,30 +19,43 @@ double GenTime::s_delta = 0.00001; -/** Creates a time object, with a time of 0 seconds. */ -GenTime::GenTime() { +GenTime::GenTime() +{ m_time = 0.0; } -/** Creates a time object, with time given in seconds. */ -GenTime::GenTime(double seconds) { +GenTime::GenTime(double seconds) +{ m_time = seconds; } -/** Creates a time object, by passing number of frames and how many frames per second */ -GenTime::GenTime(int frames, double framesPerSecond) { +GenTime::GenTime(int frames, double framesPerSecond) +{ m_time = (double) frames / framesPerSecond; } -/** Returns the time, in milliseconds */ -double GenTime::ms() const { +double GenTime::seconds() const +{ + return m_time; +} + +double GenTime::ms() const +{ return m_time * 1000; } -/** Returns the time in frames, after being given the number of frames per second */ -double GenTime::frames(double framesPerSecond) const { - return (int) floor(m_time * framesPerSecond + 0.5); +double GenTime::frames(double framesPerSecond) const +{ + return floor(m_time * framesPerSecond + 0.5); +} + +GenTime& GenTime::roundNearestFrame(double framesPerSecond) +{ + m_time = floor((m_time * framesPerSecond) + 0.5) / framesPerSecond; + return *this; } -GenTime::~GenTime() { +QString GenTime::toString() const +{ + return QString("%1 s").arg(m_time, 0, 'f', 2); }