Skip to content

Commit

Permalink
Simplify Engine schema, add schema for desktop 3.x (#130)
Browse files Browse the repository at this point in the history
Simplify Engine schema, add desktop schema 3.x
  • Loading branch information
mr-smidge authored Nov 17, 2024
1 parent 726b6ba commit 4cd4f7a
Show file tree
Hide file tree
Showing 33 changed files with 1,628 additions and 1,022 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(libdjinterop
VERSION 0.22.1
VERSION 0.23.0
DESCRIPTION "C++ library providing access to DJ record libraries")
set(PROJECT_HOMEPAGE_URL "https://github.com/xsco/libdjinterop")

Expand Down Expand Up @@ -62,6 +62,7 @@ add_library(
src/djinterop/engine/schema/schema_2_21_0.cpp
src/djinterop/engine/schema/schema_2_21_1.cpp
src/djinterop/engine/schema/schema_2_21_2.cpp
src/djinterop/engine/schema/schema_3_0_0.cpp
src/djinterop/engine/schema/schema.cpp
src/djinterop/engine/v1/engine_crate_impl.cpp
src/djinterop/engine/v1/engine_database_impl.cpp
Expand Down Expand Up @@ -176,7 +177,7 @@ install(FILES
DESTINATION "${DJINTEROP_INSTALL_INCLUDEDIR}")
install(FILES
include/djinterop/engine/engine.hpp
include/djinterop/engine/engine_version.hpp
include/djinterop/engine/engine_schema.hpp
DESTINATION "${DJINTEROP_INSTALL_INCLUDEDIR}/engine")
install(FILES
include/djinterop/engine/v2/beat_data_blob.hpp
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ What is supported:

The library supports the following firmware and application versions:

* SC5000 Firmware from 1.0.3 to 3.4.0.
* SC5000 Firmware from 1.0.3 to 4.1.0.
* Other players (e.g. SC6000/M) may work, but this is currently untested.
* Engine DJ Desktop (aka Engine Prime) from 1.0.1 to 3.4.0.
* Engine DJ Desktop (aka Engine Prime) from 1.0.1 to 4.1.0.

What is not supported (yet):

Expand Down
7 changes: 4 additions & 3 deletions example/engine_library_v2_low_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ int main()

auto dir = "Engine Library";
auto exists = ev2::engine_library::exists(dir);
auto library = exists ? ev2::engine_library{dir}
: ev2::engine_library::create(dir, e::latest_v2);
auto library = exists
? ev2::engine_library{dir}
: ev2::engine_library::create(dir, e::latest_v2_schema);

std::cout << (exists ? "Loaded" : "Created")
<< " engine library:" << std::endl;
std::cout << "Version: " << library.version().name << std::endl;
std::cout << "Version: " << library.schema() << std::endl;
std::cout << "Path: " << dir << std::endl;
std::cout << "UUID: " << library.information().get().uuid << std::endl;

Expand Down
4 changes: 2 additions & 2 deletions example/engine_prime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ int main()
using namespace std::string_literals;

auto dir = "Engine Library"s;
auto version = e::latest;
auto schema = e::latest_schema;
bool created;
auto db = e::create_or_load_database(dir, version, created);
auto db = e::create_or_load_database(dir, schema, created);
std::cout << (created ? "Created " : "Loaded ") << "database in directory "
<< dir << std::endl;
std::cout << "DB version is " << db.version_name() << std::endl;
Expand Down
237 changes: 30 additions & 207 deletions include/djinterop/engine/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

#include <djinterop/config.hpp>
#include <djinterop/database.hpp>
#include <djinterop/engine/engine_version.hpp>
#include <djinterop/exceptions.hpp>
#include <djinterop/engine/engine_schema.hpp>
#include <djinterop/pad_color.hpp>
#include <djinterop/performance_data.hpp>

Expand All @@ -42,214 +41,38 @@ struct beatgrid_marker;

namespace engine
{
/// Engine DJ OS 1.0.0.
constexpr const engine_version os_1_0_0{
semantic_version{1, 0, 0}, engine_database_type::os, "Engine DJ OS 1.0.0",
semantic_version{1, 6, 0}};

/// Engine DJ OS 1.0.3.
constexpr const engine_version os_1_0_3{
semantic_version{1, 0, 3}, engine_database_type::os, "Engine DJ OS 1.0.3",
semantic_version{1, 7, 1}};

/// Engine Prime 1.1.1.
constexpr const engine_version desktop_1_1_1{
semantic_version{1, 1, 1}, engine_database_type::desktop,
"Engine Prime 1.1.1", semantic_version{1, 9, 1}};

/// Engine DJ OS 1.2.0.
constexpr const engine_version os_1_2_0{
semantic_version{1, 2, 0}, engine_database_type::os, "Engine DJ OS 1.2.0",
semantic_version{1, 11, 1}};

/// Engine DJ OS 1.2.2.
constexpr const engine_version os_1_2_2{
semantic_version{1, 2, 2}, engine_database_type::os, "Engine DJ OS 1.2.2",
semantic_version{1, 13, 0}};

/// Engine Prime 1.2.2.
constexpr const engine_version desktop_1_2_2{
semantic_version{1, 2, 2}, engine_database_type::desktop,
"Engine Prime 1.2.2", semantic_version{1, 13, 1}};

/// Engine DJ OS 1.3.1.
constexpr const engine_version os_1_3_1{
semantic_version{1, 3, 1}, engine_database_type::os, "Engine DJ OS 1.3.1",
semantic_version{1, 13, 2}};

/// Engine DJ OS 1.4.0.
constexpr const engine_version os_1_4_0{
semantic_version{1, 4, 0}, engine_database_type::os, "Engine DJ OS 1.4.0",
semantic_version{1, 15, 0}};

/// Engine DJ OS 1.5.1/1.5.2.
constexpr const engine_version os_1_5_1{
semantic_version{1, 5, 1}, engine_database_type::os,
"Engine DJ OS 1.5.1/1.5.2", semantic_version{1, 17, 0}};

/// Engine Prime 1.5.1/1.6.0/1.6.1.
constexpr const engine_version desktop_1_5_1{
semantic_version{1, 5, 1}, engine_database_type::desktop,
"Engine Prime 1.5.1/1.6.0/1.6.1", semantic_version{1, 18, 0}};

/// Engine DJ OS 1.6.0/1.6.1/1.6.2.
constexpr const engine_version os_1_6_0{
semantic_version{1, 6, 0}, engine_database_type::os,
"Engine DJ OS 1.6.0/1.6.1/1.6.2", semantic_version{1, 18, 0}};

/// Engine DJ Desktop 2.0.x, 2.1.x.
constexpr const engine_version desktop_2_0_0{
semantic_version{2, 0, 0}, engine_database_type::desktop,
"Engine DJ Desktop 2.0.x to 2.1.x", semantic_version{2, 18, 0}};

/// Engine DJ OS 2.0.x, 2.1.x
constexpr const engine_version os_2_0_0{
semantic_version{2, 0, 0}, engine_database_type::os,
"Engine DJ OS 2.0.x to 2.1.x", semantic_version{2, 18, 0}};

/// Engine DJ Desktop 2.2.x, 2.3.x
constexpr const engine_version desktop_2_2_0{
semantic_version{2, 2, 0}, engine_database_type::desktop,
"Engine DJ Desktop 2.2.x to 2.3.x", semantic_version{2, 20, 1}};

/// Engine DJ OS 2.2.x, 2.3.x
constexpr const engine_version os_2_2_0{
semantic_version{2, 2, 0}, engine_database_type::os,
"Engine DJ OS 2.2.x to 2.3.x", semantic_version{2, 20, 1}};

/// Engine DJ Desktop 2.4.0
constexpr const engine_version desktop_2_4_0{
semantic_version{2, 4, 0}, engine_database_type::desktop,
"Engine DJ Desktop 2.4.0", semantic_version{2, 20, 2}};

/// Engine DJ OS 2.4.0
constexpr const engine_version os_2_4_0{
semantic_version{2, 4, 0}, engine_database_type::os, "Engine DJ OS 2.4.0",
semantic_version{2, 20, 2}};

/// Engine DJ Desktop 3.0.0, 3.0.1
constexpr const engine_version desktop_3_0_0{
semantic_version{3, 0, 0}, engine_database_type::desktop,
"Engine DJ Desktop 3.0.0 to 3.0.1", semantic_version{2, 20, 3}};

/// Engine DJ OS 3.0.0, 3.0.1
constexpr const engine_version os_3_0_0{
semantic_version{3, 0, 0}, engine_database_type::os,
"Engine DJ OS 3.0.0 to 3.0.1", semantic_version{2, 20, 3}};

/// Engine DJ desktop 3.1.0 to 3.4.0
constexpr const engine_version desktop_3_1_0{
semantic_version{3, 1, 0}, engine_database_type::desktop,
"Engine DJ Desktop 3.1.0 to 3.4.0", semantic_version{2, 21, 0}};

/// Engine DJ OS 3.1.0 to 3.2.0
constexpr const engine_version os_3_1_0{
semantic_version{3, 1, 0}, engine_database_type::os,
"Engine DJ OS 3.1.0 to 3.4.0", semantic_version{2, 21, 0}};

/// Engine DJ desktop 4.0.0
constexpr const engine_version desktop_4_0_0{
semantic_version{4, 0, 0}, engine_database_type::desktop,
"Engine DJ Desktop 4.0.0", semantic_version{2, 21, 1}};

/// Engine DJ OS 4.0.0
constexpr const engine_version os_4_0_0{
semantic_version{4, 0, 0}, engine_database_type::os,
"Engine DJ OS 4.0.0", semantic_version{2, 21, 1}};

/// Engine DJ desktop 4.0.1
constexpr const engine_version desktop_4_0_1{
semantic_version{4, 0, 1}, engine_database_type::desktop,
"Engine DJ Desktop 4.0.1", semantic_version{2, 21, 2}};

/// Engine DJ OS 4.0.1
constexpr const engine_version os_4_0_1{
semantic_version{4, 0, 1}, engine_database_type::os,
"Engine DJ OS 4.0.1", semantic_version{2, 21, 2}};

/// Set of available versions.
constexpr const std::array<engine_version, 25> all_versions{
os_1_0_0, os_1_0_3, desktop_1_1_1, os_1_2_0, os_1_2_2,
desktop_1_2_2, os_1_3_1, os_1_4_0, os_1_5_1, desktop_1_5_1,
os_1_6_0, desktop_2_0_0, os_2_0_0, desktop_2_2_0, os_2_2_0,
desktop_2_4_0, os_2_4_0, desktop_3_0_0, os_3_0_0, desktop_3_1_0,
os_3_1_0, desktop_4_0_0, os_4_0_0, desktop_4_0_1, os_4_0_1};

/// Set of available V1 versions.
constexpr const std::array<engine_version, 11> all_v1_versions{
os_1_0_0, os_1_0_3, desktop_1_1_1, os_1_2_0, os_1_2_2, desktop_1_2_2,
os_1_3_1, os_1_4_0, os_1_5_1, desktop_1_5_1, os_1_6_0};

/// Set of available V2 versions.
constexpr const std::array<engine_version, 14> all_v2_versions{
desktop_2_0_0, os_2_0_0, desktop_2_2_0, os_2_2_0, desktop_2_4_0,
os_2_4_0, desktop_3_0_0, os_3_0_0, desktop_3_1_0, os_3_1_0,
desktop_4_0_0, os_4_0_0, desktop_4_0_1, os_4_0_1};

/// The most recent version supported by the library.
constexpr engine_version latest = os_4_0_1;

/// The most recent V2 version supported by the library.
constexpr engine_version latest_v2 = os_4_0_1;

/// The most recent OS-type version supported by the library.
constexpr engine_version latest_os = os_4_0_1;

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};
constexpr pad_color pad_1{0xEA, 0xC5, 0x32, 0xFF};
constexpr pad_color pad_2{0xEA, 0x8F, 0x32, 0xFF};
constexpr pad_color pad_3{0xB8, 0x55, 0xBF, 0xFF};
constexpr pad_color pad_4{0xBA, 0x2A, 0x41, 0xFF};
constexpr pad_color pad_5{0x86, 0xC6, 0x4B, 0xFF};
constexpr pad_color pad_6{0x20, 0xC6, 0x7C, 0xFF};
constexpr pad_color pad_7{0x00, 0xA8, 0xB1, 0xFF};
constexpr pad_color pad_8{0x15, 0x8E, 0xE2, 0xFF};

constexpr 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";

/// The `unsupported_engine_database` exception is thrown when an Engine
/// database schema version is encountered that is not yet supported by this
/// version of the library.
class DJINTEROP_PUBLIC unsupported_engine_database : public unsupported_database
{
public:
explicit unsupported_engine_database(
const semantic_version& version) noexcept :
unsupported_database{
std::string{"Unsupported database version " + to_string(version)}},
version{version}
{
}

explicit unsupported_engine_database(
const std::string& what_arg, const semantic_version& version) noexcept :
unsupported_database{what_arg}, version{version}
{
}

const semantic_version version;
};

/// Creates a new, empty database in a directory using the 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 engine_version& version = latest);
const std::string& directory, const engine_schema& schema = latest_schema);

/// Creates a new temporary database.
///
/// Any changes made to the database will not be persisted anywhere, and will
/// be lost upon destruction of the returned variable.
database DJINTEROP_PUBLIC
create_temporary_database(const engine_version& version = latest);
create_temporary_database(const engine_schema& schema = latest_schema);

/// Creates a new database from a set of SQL scripts.
///
Expand All @@ -260,12 +83,12 @@ create_temporary_database(const engine_version& version = latest);
///
/// \param db_directory Directory in which to create database.
/// \param script_directory Directory containing scripts.
/// \param loaded_version Output reference parameter indicating the version of
/// \param loaded_schema Output reference parameter indicating the version of
/// the created database.
/// \return Returns the created database.
database DJINTEROP_PUBLIC create_database_from_scripts(
const std::string& db_directory, const std::string& script_directory,
engine_version& loaded_version);
engine_schema& loaded_schema);

/// Creates a new database from a set of SQL scripts.
///
Expand All @@ -280,7 +103,7 @@ database DJINTEROP_PUBLIC create_database_from_scripts(
inline database DJINTEROP_PUBLIC create_database_from_scripts(
const std::string& db_directory, const std::string& script_directory)
{
engine_version unused{};
engine_schema unused{};
return create_database_from_scripts(db_directory, script_directory, unused);
}

Expand All @@ -290,32 +113,32 @@ inline database DJINTEROP_PUBLIC create_database_from_scripts(
/// it will be created at the specified schema version.
///
/// \param directory Directory to create or load in.
/// \param version Version to create, if the database does not already exist.
/// \param schema Schema version, if the database does not already exist.
/// \param created Output reference parameter indicating whether a new database
/// was created or not.
/// \param loaded_version Output reference parameter indicating the version of
/// any existing database that was loaded. The value is
/// not defined if a new database was created.
/// \param loaded_schema Output reference parameter indicating the schema
/// version of any existing database that was loaded. The value is not defined
/// if a new database was created.
/// \return Returns the created or loaded database.
database DJINTEROP_PUBLIC create_or_load_database(
const std::string& directory, const engine_version& version, bool& created,
engine_version& loaded_version);
const std::string& directory, const engine_schema& schema, bool& created,
engine_schema& loaded_schema);

/// 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.
///
/// \param directory Directory to create or load in.
/// \param version Version to create, if the database does not already exist.
/// \param schema Schema version, if the database does not already exist.
/// \param created Output reference parameter indicating whether a new database
/// was created or not.
/// \return Returns the created or loaded database.
inline database DJINTEROP_PUBLIC create_or_load_database(
const std::string& directory, const engine_version& version, bool& created)
const std::string& directory, const engine_schema& schema, bool& created)
{
engine_version unused{};
return create_or_load_database(directory, version, created, unused);
engine_schema unused{};
return create_or_load_database(directory, schema, created, unused);
}

/// Returns a boolean indicating whether an Engine Library already exists in a
Expand All @@ -325,19 +148,19 @@ bool DJINTEROP_PUBLIC database_exists(const std::string& directory);
/// Loads an Engine Library database from a given directory.
///
/// \param directory Directory to load from.
/// \param loaded_version Output reference parameter indicating the version of
/// \param loaded_schema Output reference parameter indicating the version of
/// the loaded database.
/// \return Returns the loaded database.
database DJINTEROP_PUBLIC
load_database(const std::string& directory, engine_version& loaded_version);
load_database(const std::string& directory, engine_schema& loaded_schema);

/// Loads an Engine Library database from a given directory.
///
/// \param directory Directory to load from.
/// \return Returns the loaded database.
inline database DJINTEROP_PUBLIC load_database(const std::string& directory)
{
engine_version unused{};
engine_schema unused{};
return load_database(directory, unused);
}

Expand Down
Loading

0 comments on commit 4cd4f7a

Please sign in to comment.