From b6f5ab1e96623ec8d8244c44a63c0aa240f9a7bb Mon Sep 17 00:00:00 2001 From: Elliu <goyard.louis@gmail.com> Date: Sun, 1 Aug 2021 20:28:22 +0200 Subject: [PATCH] Duration from microseconds to seconds using std::chrono --- src/Lib/AbstractMediaContext.hh | 13 +++++++------ src/UI/DocumentViews/TimingAxis.hh | 14 +++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Lib/AbstractMediaContext.hh b/src/Lib/AbstractMediaContext.hh index 089b4db2..a73f92ef 100644 --- a/src/Lib/AbstractMediaContext.hh +++ b/src/Lib/AbstractMediaContext.hh @@ -101,9 +101,9 @@ public: qreal getDuration() const noexcept { - TODO(Use std::chrono here) - // The whole file duration, not individual streams. - return static_cast<qreal>(dataFormat->duration) / 1000000; + return qreal(std::chrono::duration<qreal, std::ratio<1, 1>>( + std::chrono::microseconds(dataFormat->duration)) + .count()); } protected: @@ -192,11 +192,12 @@ public: return StreamWeakPtr{ spareNullSreamPtr }; } - qreal getLength() const noexcept + qreal getDuration() const noexcept { - TODO(Use std::chrono here) // The whole file duration, not individual streams. - return static_cast<qreal>(format->duration) / 1000000; + return qreal(std::chrono::duration<qreal, std::ratio<1, 1>>( + std::chrono::microseconds(format->duration)) + .count()); } StreamWeakPtr getDefaultStream() const noexcept diff --git a/src/UI/DocumentViews/TimingAxis.hh b/src/UI/DocumentViews/TimingAxis.hh index 0ed6ea2e..70bebf92 100644 --- a/src/UI/DocumentViews/TimingAxis.hh +++ b/src/UI/DocumentViews/TimingAxis.hh @@ -14,7 +14,7 @@ namespace Vivy class TimingAxis final : public QGraphicsItem { public: explicit TimingAxis(qreal soundLength, int x0, int x1, int y) noexcept; - ~TimingAxis() noexcept = default; + ~TimingAxis() noexcept override = default; QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; @@ -23,13 +23,13 @@ private: static inline constexpr QColor axisColour = QColor(0, 0, 127); QVector<qreal> availableTicks = { 0.01, 0.1, 1, 10, 60, 3600, 86400 }; - qreal minBetweenMinor = 5; + qreal minBetweenMinor{ 5 }; - qreal penWidth = { 1 }; - qreal soundLength = { 0 }; - int x0 = { 0 }; - int x1 = { 0 }; - int y = { 0 }; + qreal penWidth{ 1 }; + qreal soundLength{ 0 }; + int x0{ 0 }; + int x1{ 0 }; + int y{ 0 }; protected: }; -- GitLab