summaryrefslogtreecommitdiffstats
path: root/src/track/keys.h
blob: 7e286c0d49fbf1ae8084e92e4abdfa4d7b7f037f (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
#pragma once

#include <QByteArray>
#include <QPair>
#include <QVector>

#include "proto/keys.pb.h"

#define KEY_MAP_VERSION "KeyMap-1.0"

typedef QVector<QPair<mixxx::track::io::key::ChromaticKey, double> > KeyChangeList;

class KeyFactory;

class Keys final {
  public:
    explicit Keys(const QByteArray* pByteArray = nullptr);

    // Serialization
    QByteArray toByteArray() const;

    // A string representing the version of the key-processing code that
    // produced this Keys instance. Used by KeysFactory for associating a given
    // serialization with the version that produced it.
    QString getVersion() const {
        return KEY_MAP_VERSION;
    }

    // A sub-version can be used to represent the preferences used to generate
    // the keys object.
    const QString& getSubVersion() const;
    void setSubVersion(const QString& subVersion);

    bool isValid() const;

    ////////////////////////////////////////////////////////////////////////////
    // Key calculations
    ////////////////////////////////////////////////////////////////////////////

    // Return the average key over the entire track if the key is valid.
    mixxx::track::io::key::ChromaticKey getGlobalKey() const;
    QString getGlobalKeyText() const;

  private:
    explicit Keys(const mixxx::track::io::key::KeyMap& m_keyMap);

    bool readByteArray(const QByteArray& byteArray);

    QString m_subVersion;
    mixxx::track::io::key::KeyMap m_keyMap;

    // For private constructor access.
    friend class KeyFactory;
};

bool operator==(const Keys& lhs, const Keys& rhs);

inline bool operator!=(const Keys& lhs, const Keys& rhs) {
    return !(lhs == rhs);
}