blob: 2d6e5c6b0ee3f07e75aa52d86e6bed6de27206fa (
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
|
#include <QMutexLocker>
#include <QtDebug>
#include "track/keys.h"
using mixxx::track::io::key::ChromaticKey;
using mixxx::track::io::key::KeyMap;
Keys::Keys(const QByteArray* pByteArray) {
if (nullptr != pByteArray) {
readByteArray(*pByteArray);
}
}
Keys::Keys(const KeyMap& keyMap)
: m_keyMap(keyMap) {
}
QByteArray Keys::toByteArray() const {
std::string output;
m_keyMap.SerializeToString(&output);
return QByteArray(output.data(), static_cast<int>(output.length()));
}
const QString& Keys::getSubVersion() const {
return m_subVersion;
}
void Keys::setSubVersion(const QString& subVersion) {
m_subVersion = subVersion;
}
bool Keys::isValid() const {
return m_keyMap.global_key() != mixxx::track::io::key::INVALID ||
m_keyMap.global_key_text().length() > 0;
}
ChromaticKey Keys::getGlobalKey() const {
return m_keyMap.global_key();
}
QString Keys::getGlobalKeyText() const {
return QString::fromStdString(m_keyMap.global_key_text());
}
bool Keys::readByteArray(const QByteArray& byteArray) {
if (!m_keyMap.ParseFromArray(byteArray.constData(), byteArray.size())) {
qDebug() << "ERROR: Could not parse Keys from QByteArray of size"
<< byteArray.size();
return false;
}
return true;
}
bool operator==(const Keys& lhs, const Keys& rhs) {
return lhs.getSubVersion() == rhs.getSubVersion() &&
// TODO: Is there a more efficient way to compare protobuf types?
lhs.toByteArray() == rhs.toByteArray();
}
|