timecode functions: added convenience function and improved error reporting

Added a convenience function for converting rational time to a timecode
and timecode converters now return error messages if something goes wrong.
This commit is contained in:
itsmattkc
2020-03-23 15:26:31 +11:00
parent 053ea10393
commit 52a8966abd
2 changed files with 9 additions and 2 deletions
+7 -2
View File
@@ -34,7 +34,7 @@ QString Timecode::timestamp_to_timecode(const int64_t &timestamp,
bool show_plus_if_positive)
{
if (timebase.isNull()) {
return QString();
return QStringLiteral("INVALID TIMEBASE");
}
double timestamp_dbl = (rational(timestamp) * timebase).toDouble();
@@ -126,7 +126,7 @@ QString Timecode::timestamp_to_timecode(const int64_t &timestamp,
return QString::number(qRound(timestamp_dbl * 1000));
}
return QString();
return QStringLiteral("INVALID TIMECODE MODE");
}
int64_t Timecode::timecode_to_timestamp(const QString &timecode, const rational &timebase, const Display &display, bool* ok)
@@ -244,6 +244,11 @@ rational Timecode::timestamp_to_time(const int64_t &timestamp, const rational &t
return rational(timestamp) * timebase;
}
QString Timecode::time_to_timecode(const rational &time, const rational &timebase, const Timecode::Display &display, bool show_plus_if_positive)
{
return timestamp_to_timecode(time_to_timestamp(time, timebase), timebase, display, show_plus_if_positive);
}
bool Timecode::TimebaseIsDropFrame(const rational &timebase)
{
return (timebase.numerator() == 1001);