summaryrefslogtreecommitdiffstats
path: root/src/djinterop/enginelibrary/performance_data_format.hpp
blob: 22e6cb58d164649417be8a3e4f35039d1f03e875 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
    This file is part of libdjinterop.

    libdjinterop is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    libdjinterop is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with libdjinterop.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <array>
#include <cstdint>
#include <vector>

#include <djinterop/optional.hpp>
#include <djinterop/performance_data.hpp>

namespace djinterop
{
enum class musical_key;

namespace enginelibrary
{
struct beat_data
{
    stdx::optional<sampling_info> sampling;
    std::vector<beatgrid_marker> default_beatgrid;
    std::vector<beatgrid_marker> adjusted_beatgrid;

    beat_data() noexcept = default;

    friend bool operator==(
        const beat_data& first, const beat_data& second) noexcept
    {
        return first.sampling == second.sampling &&
               first.default_beatgrid == second.default_beatgrid &&
               first.adjusted_beatgrid == second.adjusted_beatgrid;
    }

    std::vector<char> encode() const;
    static beat_data decode(const std::vector<char>& compressed_data);
};

struct high_res_waveform_data
{
    double samples_per_entry;
    std::vector<waveform_entry> waveform;

    high_res_waveform_data() noexcept = default;

    friend bool operator==(
        const high_res_waveform_data& first,
        const high_res_waveform_data& second) noexcept
    {
        return first.samples_per_entry == second.samples_per_entry &&
               first.waveform == second.waveform;
    }

    std::vector<char> encode() const;
    static high_res_waveform_data decode(
        const std::vector<char>& compressed_data);
};

struct loops_data
{
    std::array<stdx::optional<loop>, 8> loops;  // Don't use curly braces here!

    loops_data() noexcept = default;

    friend bool operator==(
        const loops_data& first, const loops_data& second) noexcept
    {
        return first.loops == second.loops;
    }

    std::vector<char> encode() const;
    static loops_data decode(
        const std::vector<char>& raw_data);  // not compressed
};

struct overview_waveform_data
{
    double samples_per_entry;
    std::vector<waveform_entry> waveform;

    overview_waveform_data() noexcept = default;

    friend bool operator==(
        const overview_waveform_data& first,
        const overview_waveform_data& second) noexcept
    {
        return first.samples_per_entry == second.samples_per_entry &&
               first.waveform == second.waveform;
    }

    std::vector<char> encode() const;
    static overview_waveform_data decode(
        const std::vector<char>& compressed_data);
};

struct quick_cues_data
{
    std::array<stdx::optional<hot_cue>, 8> hot_cues;
    double adjusted_main_cue = 0;
    double default_main_cue = 0;

    quick_cues_data() noexcept = default;

    friend bool operator==(
        const quick_cues_data& first, const quick_cues_data& second) noexcept
    {
        return first.hot_cues == second.hot_cues &&
               first.adjusted_main_cue == second.adjusted_main_cue &&
               first.default_main_cue == second.default_main_cue;
    }

    std::vector<char> encode() const;
    static quick_cues_data decode(const std::vector<char>& compressed_data);
};

struct track_data
{
    stdx::optional<sampling_info> sampling;
    stdx::optional<double> average_loudness;  // range (0, 1]
    stdx::optional<musical_key> key;

    track_data() noexcept = default;

    friend bool operator==(
        const track_data& first, const track_data& second) noexcept
    {
        return first.sampling == second.sampling &&
               first.average_loudness == second.average_loudness &&
               first.key == second.key;
    }

    std::vector<char> encode() const;
    static track_data decode(const std::vector<char>& compressed_data);
};

}  // namespace enginelibrary
}  // namespace djinterop