-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
wkey.cpp
67 lines (60 loc) · 2.1 KB
/
wkey.cpp
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
#include "widget/wkey.h"
#include "library/library_prefs.h"
#include "moc_wkey.cpp"
#include "track/keys.h"
#include "track/keyutils.h"
WKey::WKey(const QString& group, QWidget* pParent)
: WLabel(pParent),
m_dOldValue(0),
m_keyNotation(mixxx::library::prefs::kKeyNotationConfigKey, this),
m_engineKeyDistance(group,
"visual_key_distance",
this,
ControlFlag::AllowMissingOrInvalid) {
setValue(m_dOldValue);
m_keyNotation.connectValueChanged(this, &WKey::keyNotationChanged);
m_engineKeyDistance.connectValueChanged(this, &WKey::setCents);
}
void WKey::onConnectedControlChanged(double dParameter, double dValue) {
Q_UNUSED(dParameter);
// Enums are not currently represented using parameter space so it doesn't
// make sense to use the parameter here yet.
setValue(dValue);
}
void WKey::setup(const QDomNode& node, const SkinContext& context) {
WLabel::setup(node, context);
m_displayCents = context.selectBool(node, "DisplayCents", false);
m_displayKey = context.selectBool(node, "DisplayKey", true);
}
void WKey::setValue(double dValue) {
m_dOldValue = dValue;
mixxx::track::io::key::ChromaticKey key =
KeyUtils::keyFromNumericValue(dValue);
if (key != mixxx::track::io::key::INVALID) {
// Render this key with the user-provided notation.
QString keyStr = "";
if (m_displayKey) {
keyStr = KeyUtils::keyToString(key);
}
if (m_displayCents) {
double diff_cents = m_engineKeyDistance.get();
int cents_to_display = static_cast<int>(diff_cents * 100);
char sign = ' ';
if (diff_cents < 0) {
sign = '-';
} else if (diff_cents > 0) {
sign = '+';
}
keyStr.append(QString(" %1%2c").arg(sign).arg(qAbs(cents_to_display)));
}
setText(keyStr);
} else {
setText("");
}
}
void WKey::setCents() {
setValue(m_dOldValue);
}
void WKey::keyNotationChanged(double dValue) {
setValue(dValue);
}