blob: 88677fa858fee96727d0041766910f19f3f644ad (
plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#ifndef MIXXX_BPM_H
#define MIXXX_BPM_H
#include <QtDebug>
#include "util/math.h"
namespace mixxx {
// DTO for storing BPM information.
class Bpm final {
public:
static constexpr double kValueUndefined = 0.0;
static constexpr double kValueMin = 0.0; // lower bound (exclusive)
static constexpr double kValueMax = 300.0; // higher bound (inclusive)
Bpm()
: Bpm(kValueUndefined) {
}
explicit Bpm(double value)
: m_value(value) {
}
static double normalizeValue(double value);
// Adjusts floating-point values to match their string representation
// in file tags to account for rounding errors.
void normalizeBeforeExport() {
m_value = normalizeValue(m_value);
}
static bool isValidValue(double value) {
return kValueMin < value;
}
bool hasValue() const {
return isValidValue(m_value);
}
double getValue() const {
return m_value;
}
void setValue(double value) {
m_value = value;
}
void resetValue() {
m_value = kValueUndefined;
}
static double valueFromString(const QString& str, bool* pValid = nullptr);
static QString valueToString(double value);
static int valueToInteger(double value) {
return std::round(value);
}
private:
double m_value;
};
inline
bool operator==(const Bpm& lhs, const Bpm& rhs) {
return lhs.getValue() == rhs.getValue();
}
inline
bool operator!=(const Bpm& lhs, const Bpm& rhs) {
return !(lhs == rhs);
}
inline
QDebug operator<<(QDebug dbg, const Bpm& arg) {
return dbg << arg.getValue();
}
}
Q_DECLARE_TYPEINFO(mixxx::Bpm, Q_MOVABLE_TYPE);
Q_DECLARE_METATYPE(mixxx::Bpm)
#endif // MIXXX_BPM_H
|