Skip to content
Extraits de code Groupes Projets
Vérifiée Valider a6eca143 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

ASS: Get end and begin times for lines

parent 7e72f8d5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!7Add the ASS sub document and the ASS tree
...@@ -38,6 +38,9 @@ Line::Line(AssFactory *const factory, const QString &lineString) ...@@ -38,6 +38,9 @@ Line::Line(AssFactory *const factory, const QString &lineString)
layer = Utils::decodeLineToInteger(contentList[LineIndex::Layer], "Layer is not an integer"); layer = Utils::decodeLineToInteger(contentList[LineIndex::Layer], "Layer is not an integer");
effect = contentList[LineIndex::Effect]; effect = contentList[LineIndex::Effect];
nameOrActor = contentList[LineIndex::Name]; nameOrActor = contentList[LineIndex::Name];
start = Utils::Time::fromString(contentList[LineIndex::Start]).toUInt();
end = Utils::Time::fromString(contentList[LineIndex::End]).toUInt();
styleProperties.marginL = styleProperties.marginL =
Utils::decodeLineToInteger(contentList[LineIndex::MarginL], "MarginL is not an integer"); Utils::decodeLineToInteger(contentList[LineIndex::MarginL], "MarginL is not an integer");
styleProperties.marginR = styleProperties.marginR =
......
...@@ -11,7 +11,7 @@ namespace Vivy::Ass ...@@ -11,7 +11,7 @@ namespace Vivy::Ass
{ {
class Line; class Line;
class Syl { class Syl final {
private: private:
QVector<Char> content; QVector<Char> content;
StyleProperties styleProperties; StyleProperties styleProperties;
......
#include "Utils.hh" #include "Utils.hh"
#include <QRegExp>
#include <QFileInfo> #include <QFileInfo>
using namespace Vivy; using namespace Vivy;
...@@ -50,3 +51,34 @@ Utils::decodeLineToFloating(const QString &item, const QString &error) ...@@ -50,3 +51,34 @@ Utils::decodeLineToFloating(const QString &item, const QString &error)
throw std::runtime_error(("invalid line content: " + error).toStdString()); throw std::runtime_error(("invalid line content: " + error).toStdString());
return ret; return ret;
} }
// The string must be of the form: `H:MM:SS.cs`
Utils::Time
Utils::Time::fromString(const QString &str)
{
QRegExp re("^(\\d+):(\\d\\d):(\\d\\d)\\.(\\d\\d)$");
// Here the toUint is safe because the RegExp is OK
if (re.indexIn(str) != -1)
return { .hour = re.cap(1).toUInt(),
.minute = re.cap(2).toUInt(),
.second = re.cap(3).toUInt(),
.centisecond = re.cap(4).toUInt() };
else
throw std::runtime_error("The string is not of the format `H:MM:SS.cs`");
}
quint64
Utils::Time::toUInt() const noexcept
{
return ((hour * 3600) + (minute * 60) + second) * 100 + centisecond;
}
// Get a string from a time
QString
Utils::Time::toString() const noexcept
{
return QString::number(hour) + ":" + QString::number(minute) + ":" + QString::number(second) +
"." + QString::number(centisecond);
}
...@@ -84,6 +84,19 @@ toUnderlying(E e) noexcept ...@@ -84,6 +84,19 @@ toUnderlying(E e) noexcept
return static_cast<std::underlying_type_t<E>>(e); return static_cast<std::underlying_type_t<E>>(e);
} }
// Structure used to represent the time as it is presented in an ASS file.
struct Time final {
quint64 hour;
quint64 minute;
quint64 second;
quint64 centisecond;
static Time fromString(const QString &);
QString toString() const noexcept;
quint64 toUInt() const noexcept;
};
bool detectDocumentType(const QFileInfo &, DocumentType *); bool detectDocumentType(const QFileInfo &, DocumentType *);
bool decodeLineToBoolean(const QString &item, const QString &error); bool decodeLineToBoolean(const QString &item, const QString &error);
int decodeLineToInteger(const QString &item, const QString &error); int decodeLineToInteger(const QString &item, const QString &error);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter