Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engine DB 3.0.0 schema support #138

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 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.23.1
VERSION 0.23.2
DESCRIPTION "C++ library providing access to DJ record libraries")
set(PROJECT_HOMEPAGE_URL "https://github.com/xsco/libdjinterop")

Expand Down Expand Up @@ -56,6 +56,17 @@ add_library(
include/djinterop/engine/v2/quick_cues_blob.hpp
include/djinterop/engine/v2/track_data_blob.hpp
include/djinterop/engine/v2/track_table.hpp
include/djinterop/engine/v3/beat_data_blob.hpp
include/djinterop/engine/v3/engine_library.hpp
include/djinterop/engine/v3/information_table.hpp
include/djinterop/engine/v3/loops_blob.hpp
include/djinterop/engine/v3/overview_waveform_data_blob.hpp
include/djinterop/engine/v3/performance_data_table.hpp
include/djinterop/engine/v3/playlist_entity_table.hpp
include/djinterop/engine/v3/playlist_table.hpp
include/djinterop/engine/v3/quick_cues_blob.hpp
include/djinterop/engine/v3/track_data_blob.hpp
include/djinterop/engine/v3/track_table.hpp
include/djinterop/exceptions.hpp
include/djinterop/musical_key.hpp
include/djinterop/pad_color.hpp
Expand Down Expand Up @@ -147,6 +158,20 @@ add_library(
src/djinterop/engine/v2/track_table.cpp
src/djinterop/engine/v2/track_impl.cpp
src/djinterop/engine/v2/track_impl.hpp
src/djinterop/engine/v3/convert_beatgrid.hpp
src/djinterop/engine/v3/convert_hot_cues.hpp
src/djinterop/engine/v3/convert_loops.hpp
src/djinterop/engine/v3/convert_track.hpp
src/djinterop/engine/v3/convert_waveform.hpp
src/djinterop/engine/v3/crate_impl.cpp
src/djinterop/engine/v3/crate_impl.hpp
src/djinterop/engine/v3/database_impl.cpp
src/djinterop/engine/v3/database_impl.hpp
src/djinterop/engine/v3/engine_library.cpp
src/djinterop/engine/v3/performance_data_table.cpp
src/djinterop/engine/v3/track_impl.cpp
src/djinterop/engine/v3/track_impl.hpp
src/djinterop/engine/v3/track_table.cpp
src/djinterop/impl/crate_impl.cpp
src/djinterop/impl/crate_impl.hpp
src/djinterop/impl/database_impl.cpp
Expand Down Expand Up @@ -349,9 +374,11 @@ if (Boost_FOUND)
add_djinterop_test(engine/ database_test)
add_djinterop_test(engine/ engine_test)
add_djinterop_test(engine/ track_test)
add_djinterop_test(engine/v2/ track_table_test)
add_djinterop_test(engine/v2/ playlist_entity_table_test)
add_djinterop_test(engine/v2/ playlist_table_test)
add_djinterop_test(engine/v2/ track_table_test)
add_djinterop_test(engine/v3/ performance_data_table_test)
add_djinterop_test(engine/v3/ track_table_test)

else()
message(STATUS "Unit tests not available, as Boost cannot be found")
Expand Down
14 changes: 11 additions & 3 deletions include/djinterop/engine/engine_schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ enum class engine_schema
};

/// Set of supported schema versions.
constexpr std::array<engine_schema, 18> supported_schemas{
constexpr std::array<engine_schema, 19> supported_schemas{
engine_schema::schema_1_6_0, engine_schema::schema_1_7_1,
engine_schema::schema_1_9_1, engine_schema::schema_1_11_1,
engine_schema::schema_1_13_0, engine_schema::schema_1_13_1,
Expand All @@ -65,7 +65,8 @@ constexpr std::array<engine_schema, 18> supported_schemas{
engine_schema::schema_1_18_0_os, engine_schema::schema_2_18_0,
engine_schema::schema_2_20_1, engine_schema::schema_2_20_2,
engine_schema::schema_2_20_3, engine_schema::schema_2_21_0,
engine_schema::schema_2_21_1, engine_schema::schema_2_21_2};
engine_schema::schema_2_21_1, engine_schema::schema_2_21_2,
engine_schema::schema_3_0_0};

/// Set of supported schema 1.x versions.
constexpr std::array<engine_schema, 11> supported_v1_schemas{
Expand All @@ -83,15 +84,22 @@ constexpr std::array<engine_schema, 7> supported_v2_schemas{
engine_schema::schema_2_21_0, engine_schema::schema_2_21_1,
engine_schema::schema_2_21_2};

/// Set of supported schema 3.x versions.
constexpr std::array<engine_schema, 1> supported_v3_schemas{
engine_schema::schema_3_0_0};

/// The most recent schema version supported by the library.
constexpr engine_schema latest_schema = engine_schema::schema_2_21_2;
constexpr engine_schema latest_schema = engine_schema::schema_3_0_0;

/// The most recent schema 1.x version supported by the library.
constexpr engine_schema latest_v1_schema = engine_schema::schema_1_18_0_os;

/// The most recent schema 2.x version supported by the library.
constexpr engine_schema latest_v2_schema = engine_schema::schema_2_21_2;

/// The most recent schema 3.x version supported by the library.
constexpr engine_schema latest_v3_schema = engine_schema::schema_3_0_0;

/// Get a string representation of the schema.
inline std::string to_string(const engine_schema& v)
{
Expand Down
2 changes: 1 addition & 1 deletion include/djinterop/engine/v2/quick_cues_blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ constexpr const size_t MAX_QUICK_CUES = 8;

/// Sentinel value for a quick cue sample offset indicating that the quick cue
/// is not set.
static const double QUICK_CUE_SAMPLE_OFFSET_EMPTY = -1;
constexpr double QUICK_CUE_SAMPLE_OFFSET_EMPTY = -1;

/// Represents a quick cue in the quick cues blob.
struct DJINTEROP_PUBLIC quick_cue_blob
Expand Down
43 changes: 43 additions & 0 deletions include/djinterop/engine/v3/beat_data_blob.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
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

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

#include <djinterop/engine/v2/beat_data_blob.hpp>

namespace djinterop::engine::v3
{
/// Represents a marker within a beat grid, part of the beat data blob.
///
/// Two or more markers form a beat grid, identifying the position of beats
/// within a track, with the assumption that beats between each pair of markers
/// occur at a constant tempo.
///
/// In Engine databases, the first marker is customarily at beat -4 (i.e. before
/// the start of the track), and the last marker is at beat N+1 (i.e. the first
/// beat after the end of the track). Any markers in between are custom
/// downbeats and can occur at any point in the track.
using beat_grid_marker_blob = djinterop::engine::v2::beat_grid_marker_blob;

/// Represents the beat data blob.
using beat_data_blob = djinterop::engine::v2::beat_data_blob;

} // namespace djinterop::engine::v3
129 changes: 129 additions & 0 deletions include/djinterop/engine/v3/engine_library.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
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

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

#include <memory>
#include <string>

#include <djinterop/config.hpp>
#include <djinterop/database.hpp>
#include <djinterop/engine/base_engine_library.hpp>
#include <djinterop/engine/engine_schema.hpp>
#include <djinterop/engine/v3/information_table.hpp>
#include <djinterop/engine/v3/performance_data_table.hpp>
#include <djinterop/engine/v3/playlist_entity_table.hpp>
#include <djinterop/engine/v3/playlist_table.hpp>
#include <djinterop/engine/v3/track_table.hpp>

namespace djinterop::engine
{
struct engine_library_context;
}

namespace djinterop::engine::v3
{

/// Represents an Engine Library with schema 3.x.
///
/// A Library with this schema is achieved by having a specific directory
/// structure in which one or more SQLite databases are stored. The top-level
/// directory is typically named `Engine Library`, and there must then be a
/// sub-directory beneath that named `Database2`. The main SQLite database
/// resides in that directory, and is named `m.db`.
///
/// Note that the directory that should be passed to constructors and member
/// functions of this class must be the `Engine Library` directory, not the
/// `Database2` directory.
class DJINTEROP_PUBLIC engine_library : public base_engine_library
{
public:
using base_engine_library::base_engine_library;

/// Construct by loading from an existing directory.
///
/// \param directory Directory to load from.
explicit engine_library(const std::string& directory);

/// Make a new, empty library of a given version.
///
/// \param directory Directory in which to create the new library.
/// \param schema Version to create.
/// \return Returns the new Engine library.
static engine_library create(
const std::string& directory, const engine_schema& schema)
{
return engine_library{base_engine_library::create(directory, schema)};
}

/// Make a new, empty, in-memory library of a given version.
///
/// Any changes made to the library will not persist beyond destruction
/// of the class instance.
///
/// \param schema Version to create.
/// \return Returns the new temporary Engine library.
static engine_library create_temporary(const engine_schema& schema)
{
return engine_library{base_engine_library::create_temporary(schema)};
}

/// Test whether an Engine Library already exists in the given directory.
///
/// \param directory Directory to test.
/// \return Returns a flag indicating whether an Engine library exists.
static bool exists(const std::string& directory)
{
return base_engine_library::exists(directory);
}

/// Get a class representing the `Information` table.
[[nodiscard]] information_table information() const
{
return information_table{context_};
}

/// Get a class representing the `PerformanceData` table.
[[nodiscard]] performance_data_table performance_data() const
{
return performance_data_table{context_};
}

/// Get a class representing the `PlaylistEntity` table.
[[nodiscard]] playlist_entity_table playlist_entity() const
{
return playlist_entity_table{context_};
}

/// Get a class representing the `Playlist` table.
[[nodiscard]] playlist_table playlist() const
{
return playlist_table{context_};
}

/// Get a class representing the `Track` table.
[[nodiscard]] track_table track() const { return track_table{context_}; }

/// Get the unified database interface for this Engine library.
[[nodiscard]] djinterop::database database() const override;
};

} // namespace djinterop::engine::v3
37 changes: 37 additions & 0 deletions include/djinterop/engine/v3/information_table.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
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

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

#include <djinterop/engine/v2/information_table.hpp>

namespace djinterop::engine::v3
{
/// Represents the single-row contents of the `Information` table.
using information_row = djinterop::engine::v2::information_row;

/// Represents the `Information` table in an Engine v2 database.
///
/// Note that the `Information` table in a valid database always has exactly
/// one row. Zero rows or more than one is considered an invalid database.
using information_table = djinterop::engine::v2::information_table;

} // namespace djinterop::engine::v3
37 changes: 37 additions & 0 deletions include/djinterop/engine/v3/loops_blob.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
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

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

#include <djinterop/engine/v2/loops_blob.hpp>

namespace djinterop::engine::v3
{
/// Maximum number of supported loops.
constexpr size_t MAX_LOOPS = djinterop::engine::v2::MAX_LOOPS;

/// Represents a loop within the loops blob.
using loop_blob = djinterop::engine::v2::loop_blob;

/// Represents the loops blob.
using loops_blob = djinterop::engine::v2::loops_blob;

} // namespace djinterop::engine::v3
34 changes: 34 additions & 0 deletions include/djinterop/engine/v3/overview_waveform_data_blob.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
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

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

#include <djinterop/engine/v2/overview_waveform_data_blob.hpp>

namespace djinterop::engine::v3
{
/// Represents a point on the overview waveform.
using overview_waveform_point = djinterop::engine::v2::overview_waveform_point;

/// Represents the overview waveform data blob.
using overview_waveform_data_blob = djinterop::engine::v2::overview_waveform_data_blob;

} // namespace djinterop::engine::v3
Loading