forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyzerprogress.h
25 lines (19 loc) · 907 Bytes
/
analyzerprogress.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#pragma once
#include "util/math.h"
typedef double AnalyzerProgress;
constexpr AnalyzerProgress kAnalyzerProgressUnknown = -1.0;
constexpr AnalyzerProgress kAnalyzerProgressNone = 0.0; // 0.0 %
constexpr AnalyzerProgress kAnalyzerProgressHalf = 0.5; // 50.0 %
constexpr AnalyzerProgress kAnalyzerProgressFinalizing = 0.95; // 95.0 %
constexpr AnalyzerProgress kAnalyzerProgressDone = 1.0; // 100.0%
Q_DECLARE_METATYPE(AnalyzerProgress);
// Integer [0, 100]
inline
int analyzerProgressPercent(AnalyzerProgress analyzerProgress) {
DEBUG_ASSERT(analyzerProgress >= kAnalyzerProgressNone);
const auto analyzerProgressClamped =
math_min(analyzerProgress, kAnalyzerProgressDone);
return static_cast<int>(std::round(
100 * (analyzerProgressClamped - kAnalyzerProgressNone) /
(kAnalyzerProgressDone - kAnalyzerProgressNone)));
}