timecode: allow specific rounding routines
This commit is contained in:
@@ -239,7 +239,7 @@ rational Timecode::timecode_to_time(const QString &timecode, const rational &tim
|
||||
return timestamp_to_time(timestamp, timebase);
|
||||
}
|
||||
|
||||
rational Timecode::snap_time_to_timebase(const rational &time, const rational &timebase, bool floor)
|
||||
rational Timecode::snap_time_to_timebase(const rational &time, const rational &timebase, Rounding floor)
|
||||
{
|
||||
// Just convert to a timestamp in timebase units and back
|
||||
int64_t timestamp = time_to_timestamp(time, timebase, floor);
|
||||
@@ -275,19 +275,23 @@ QString Timecode::TimeToString(int64_t ms)
|
||||
.arg(ss, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
int64_t Timecode::time_to_timestamp(const rational &time, const rational &timebase, bool floor)
|
||||
int64_t Timecode::time_to_timestamp(const rational &time, const rational &timebase, Rounding floor)
|
||||
{
|
||||
return time_to_timestamp(time.toDouble(), timebase, floor);
|
||||
}
|
||||
|
||||
int64_t Timecode::time_to_timestamp(const double &time, const rational &timebase, bool floor)
|
||||
int64_t Timecode::time_to_timestamp(const double &time, const rational &timebase, Rounding floor)
|
||||
{
|
||||
double d = time * timebase.flipped().toDouble();
|
||||
|
||||
if (floor) {
|
||||
return qFloor(d);
|
||||
} else {
|
||||
switch (floor) {
|
||||
case kRound:
|
||||
default:
|
||||
return qRound64(d);
|
||||
case kFloor:
|
||||
return qFloor(d);
|
||||
case kCeil:
|
||||
return qCeil(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user