summaryrefslogtreecommitdiffstats
path: root/include/djinterop/enginelibrary.hpp
blob: a24f5025e0df4699e434eeaa1bb6f5037482416f (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
    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
#ifndef DJINTEROP_ENGINELIBRARY_HPP
#define DJINTEROP_ENGINELIBRARY_HPP

#if __cplusplus < 201703L
#error This library needs at least a C++17 compliant compiler
#endif

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

#include <djinterop/config.hpp>
#include <djinterop/database.hpp>
#include <djinterop/pad_color.hpp>
#include <djinterop/semantic_version.hpp>

namespace djinterop
{
class database;
struct beatgrid_marker;

namespace enginelibrary
{
/// The schema associated with SC5000 Firmware 1.0.0.
constexpr const semantic_version version_1_6_0{1, 6, 0};

/// The schema associated with SC5000 Firmware 1.0.3.
constexpr const semantic_version version_1_7_1{1, 7, 1};

/// The schema associated with Engine Prime 1.1.1.
constexpr const semantic_version version_1_9_1{1, 9, 1};

/// The schema associated with SC5000 Firmware 1.2.0.
constexpr const semantic_version version_1_11_1{1, 11, 1};

/// The schema associated with SC5000 Firmware 1.2.2.
constexpr const semantic_version version_1_13_0{1, 13, 0};

/// The schema associated with Engine Prime 1.2.2.
constexpr const semantic_version version_1_13_1{1, 13, 1};

/// The schema associated with SC5000 Firmware 1.3.1.
constexpr const semantic_version version_1_13_2{1, 13, 2};

/// The schema associated with SC5000 Firmware 1.4.0.
constexpr const semantic_version version_1_15_0{1, 15, 0};

/// The schema associated with SC5000 Firmware 1.5.1/1.5.2.
constexpr const semantic_version version_1_17_0{1, 17, 0};

/// The schema associated with Engine Prime 1.5.1.
constexpr const semantic_version version_1_18_0{1, 18, 0};

/// Set of available schemas.
constexpr const std::array<semantic_version, 10> all_versions{
    version_1_6_0,  version_1_7_1,  version_1_9_1,  version_1_11_1,
    version_1_13_0, version_1_13_1, version_1_13_2, version_1_15_0,
    version_1_17_0, version_1_18_0,
};

/// The most recent schema version supported by the library.
constexpr semantic_version version_latest = version_1_18_0;

/// The most recent "firmware-usable" schema version supported by the library.
constexpr semantic_version version_latest_firmware = version_1_17_0;

namespace standard_pad_colors
{
constexpr const pad_color pad_1{0xEA, 0xC5, 0x32, 0xFF};
constexpr const pad_color pad_2{0xEA, 0x8F, 0x32, 0xFF};
constexpr const pad_color pad_3{0xB8, 0x55, 0xBF, 0xFF};
constexpr const pad_color pad_4{0xBA, 0x2A, 0x41, 0xFF};
constexpr const pad_color pad_5{0x86, 0xC6, 0x4B, 0xFF};
constexpr const pad_color pad_6{0x20, 0xC6, 0x7C, 0xFF};
constexpr const pad_color pad_7{0x00, 0xA8, 0xB1, 0xFF};
constexpr const pad_color pad_8{0x15, 0x8E, 0xE2, 0xFF};

constexpr const std::array<pad_color, 8> pads{pad_1, pad_2, pad_3, pad_4,
                                              pad_5, pad_6, pad_7, pad_8};

}  // namespace standard_pad_colors

constexpr const char* default_database_dir_name = "Engine Library";

/// Gets a descriptive name for a given schema version.
std::string DJINTEROP_PUBLIC version_name(const semantic_version& version);

/// Creates a new, empty database in a directory using the schema version
/// provided.
///
/// By convention, the last part of the directory path is "Engine Library".  If
/// a database already exists in the target directory, an exception will be
/// thrown.
database DJINTEROP_PUBLIC create_database(
    const std::string& directory,
    const semantic_version& schema_version = version_latest);

/// Creates a new database from a set of SQL scripts.
///
/// The directory indicated by `script_directory` is expected to contain files
/// of the form "<dbname>.db.sql", which will be read and used to hydrate
/// SQLite databases with the name "<dbname>.db".  These hydrated SQLite
/// databases are then loaded into the returned `database` object.
database DJINTEROP_PUBLIC create_database_from_scripts(
    const std::string& db_directory, const std::string& script_directory);

/// Create or load an Engine Library database in a given directory.
///
/// If a database already exists in the directory, it will be loaded.  If not,
/// it will be created at the specified schema version.  In both cases, the
/// database is returned.  The boolean reference parameter `created` can be used
/// to determine whether the database was created or merely loaded.
database DJINTEROP_PUBLIC create_or_load_database(
    const std::string& directory, const semantic_version& schema_version,
    bool& created);

/// Returns a boolean indicating whether an Engine Library already exists in a
/// given directory.
bool DJINTEROP_PUBLIC database_exists(const std::string& directory);

/// Loads an Engine Library database from a given directory.
database DJINTEROP_PUBLIC load_database(const std::string& directory);

/// Given an Engine Library database, returns the path to its m.db sqlite
/// database file
///
/// If the given database is not an enginelibrary, then the behaviour of this
/// function is undefined.
std::string DJINTEROP_PUBLIC music_db_path(const database& db);

/// Normalizes a beat-grid, so that the beat indexes are in the form normally
/// expected by Engine Prime.
///
/// By convention, the Engine Prime analyses tracks so that the first beat is
/// at index -4 (yes, negative!) and the last beat is the first beat past the
/// usable end of the track, which may not necessarily be aligned to the first
/// beat of a 4-beat bar.  Therefore, the sample offsets typically recorded by
/// Engine Prime do not lie within the actual track.
std::vector<beatgrid_marker> DJINTEROP_PUBLIC
normalize_beatgrid(std::vector<beatgrid_marker> beatgrid, int64_t sample_count);

/// Given an enginelibrary database, returns the path to its p.db sqlite
/// database file
///
/// If the given database is not an enginelibrary, then the behaviour of this
/// function is undefined.
std::string DJINTEROP_PUBLIC perfdata_db_path(const database& db);

}  // namespace enginelibrary
}  // namespace djinterop

#endif  // DJINTEROP_ENGINELIBRARY_HPP