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

Preserve extra data when encoding/decoding Engine blobs #102

Merged
merged 3 commits into from
Aug 12, 2023
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
2 changes: 1 addition & 1 deletion 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.19.1
VERSION 0.19.2
DESCRIPTION "C++ library providing access to DJ record libraries")
set(PROJECT_HOMEPAGE_URL "https://github.com/xsco/libdjinterop")

Expand Down
6 changes: 6 additions & 0 deletions include/djinterop/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@
#cmakedefine DJINTEROP_STD_OPTIONAL
#cmakedefine DJINTEROP_STD_EXPERIMENTAL_OPTIONAL

#include <cstddef>
static_assert(sizeof(std::byte) == 1,
"Only platforms where sizeof(std::byte) == 1 are supported");
static_assert(alignof(std::byte) == 1,
"Only platforms where alignof(std::byte) == 1 are supported");

#endif // DJINTEROP_CONFIG_HPP
11 changes: 8 additions & 3 deletions include/djinterop/engine/v2/beat_data_blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#error This library needs at least a C++17 compliant compiler
#endif

#include <cstddef>
#include <cstdint>
#include <ostream>
#include <string>
Expand Down Expand Up @@ -106,17 +107,20 @@ struct DJINTEROP_PUBLIC beat_data_blob
/// List of markers making up the adjusted beat grid.
beat_grid_marker_blobs_type adjusted_beat_grid;

/// Extra data (if any) found in a decoded blob.
std::vector<std::byte> extra_data;

/// Encode this struct into binary blob form.
///
/// \return Returns a byte array.
[[nodiscard]] std::vector<char> to_blob() const;
[[nodiscard]] std::vector<std::byte> to_blob() const;

/// Decode an instance of this struct from binary blob form.
///
/// \param blob Binary blob.
/// \return Returns a decoded instance of this struct.
[[nodiscard]] static beat_data_blob from_blob(
const std::vector<char>& blob);
const std::vector<std::byte>& blob);

friend bool operator==(
const beat_data_blob& lhs, const beat_data_blob& rhs) noexcept
Expand All @@ -125,7 +129,8 @@ struct DJINTEROP_PUBLIC beat_data_blob
lhs.samples == rhs.samples &&
lhs.is_beatgrid_set == rhs.is_beatgrid_set &&
lhs.default_beat_grid == rhs.default_beat_grid &&
lhs.adjusted_beat_grid == rhs.adjusted_beat_grid;
lhs.adjusted_beat_grid == rhs.adjusted_beat_grid &&
lhs.extra_data == rhs.extra_data;
}

friend bool operator!=(
Expand Down
11 changes: 8 additions & 3 deletions include/djinterop/engine/v2/loops_blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#error This library needs at least a C++17 compliant compiler
#endif

#include <cstddef>
#include <cstdint>
#include <ostream>
#include <string>
Expand Down Expand Up @@ -98,21 +99,25 @@ struct DJINTEROP_PUBLIC loops_blob
/// List of loops.
std::vector<loop_blob> loops;

/// Extra data (if any) found in a decoded blob.
std::vector<std::byte> extra_data;

/// Encode this struct into binary blob form.
///
/// \return Returns a byte array.
[[nodiscard]] std::vector<char> to_blob() const;
[[nodiscard]] std::vector<std::byte> to_blob() const;

/// Decode an instance of this struct from binary blob form.
///
/// \param blob Binary blob.
/// \return Returns a decoded instance of this struct.
[[nodiscard]] static loops_blob from_blob(const std::vector<char>& blob);
[[nodiscard]] static loops_blob from_blob(
const std::vector<std::byte>& blob);

friend bool operator==(
const loops_blob& lhs, const loops_blob& rhs) noexcept
{
return lhs.loops == rhs.loops;
return lhs.loops == rhs.loops && lhs.extra_data == rhs.extra_data;
}

friend bool operator!=(
Expand Down
18 changes: 12 additions & 6 deletions include/djinterop/engine/v2/overview_waveform_data_blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#error This library needs at least a C++17 compliant compiler
#endif

#include <cstddef>
#include <cstdint>
#include <ostream>
#include <vector>
Expand Down Expand Up @@ -60,9 +61,10 @@ struct DJINTEROP_PUBLIC overview_waveform_point
friend std::ostream& operator<<(
std::ostream& os, const overview_waveform_point& obj) noexcept
{
os << "overview_waveform_point{low_value=" << obj.low_value
<< ", mid_value=" << obj.mid_value
<< ", high_value=" << obj.high_value << "}";
os << "overview_waveform_point{low_value="
<< static_cast<int>(obj.low_value)
<< ", mid_value=" << static_cast<int>(obj.mid_value)
<< ", high_value=" << static_cast<int>(obj.high_value) << "}";
return os;
}
};
Expand All @@ -79,17 +81,20 @@ struct DJINTEROP_PUBLIC overview_waveform_data_blob
/// Maximum values across all waveform points.
overview_waveform_point maximum_point;

/// Extra data (if any) found in a decoded blob.
std::vector<std::byte> extra_data;

/// Encode this struct into binary blob form.
///
/// \return Returns a byte array.
[[nodiscard]] std::vector<char> to_blob() const;
[[nodiscard]] std::vector<std::byte> to_blob() const;

/// Decode an instance of this struct from binary blob form.
///
/// \param blob Binary blob.
/// \return Returns a decoded instance of this struct.
[[nodiscard]] static overview_waveform_data_blob from_blob(
const std::vector<char>& blob);
const std::vector<std::byte>& blob);

friend bool operator==(
const overview_waveform_data_blob& lhs,
Expand All @@ -98,7 +103,8 @@ struct DJINTEROP_PUBLIC overview_waveform_data_blob
return lhs.samples_per_waveform_point ==
rhs.samples_per_waveform_point &&
lhs.waveform_points == rhs.waveform_points &&
lhs.maximum_point == rhs.maximum_point;
lhs.maximum_point == rhs.maximum_point &&
lhs.extra_data == rhs.extra_data;
}

friend bool operator!=(
Expand Down
11 changes: 8 additions & 3 deletions include/djinterop/engine/v2/quick_cues_blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#error This library needs at least a C++17 compliant compiler
#endif

#include <cstddef>
#include <ostream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -105,25 +106,29 @@ struct DJINTEROP_PUBLIC quick_cues_blob
/// Default cue point.
double default_main_cue;

/// Extra data (if any) found in a decoded blob.
std::vector<std::byte> extra_data;

/// Encode this struct into binary blob form.
///
/// \return Returns a byte array.
[[nodiscard]] std::vector<char> to_blob() const;
[[nodiscard]] std::vector<std::byte> to_blob() const;

/// Decode an instance of this struct from binary blob form.
///
/// \param blob Binary blob.
/// \return Returns a decoded instance of this struct.
[[nodiscard]] static quick_cues_blob from_blob(
const std::vector<char>& blob);
const std::vector<std::byte>& blob);

friend bool operator==(
const quick_cues_blob& lhs, const quick_cues_blob& rhs) noexcept
{
return lhs.quick_cues == rhs.quick_cues &&
lhs.adjusted_main_cue == rhs.adjusted_main_cue &&
lhs.is_main_cue_adjusted == rhs.is_main_cue_adjusted &&
lhs.default_main_cue == rhs.default_main_cue;
lhs.default_main_cue == rhs.default_main_cue &&
lhs.extra_data == rhs.extra_data;
}

friend bool operator!=(
Expand Down
34 changes: 25 additions & 9 deletions include/djinterop/engine/v2/track_data_blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#error This library needs at least a C++17 compliant compiler
#endif

#include <cstddef>
#include <cstdint>
#include <ostream>
#include <vector>
Expand All @@ -38,31 +39,43 @@ struct DJINTEROP_PUBLIC track_data_blob
/// Number of samples in the track.
int64_t samples;

/// Number (possibly?) indicating average loudness.
double average_loudness;

/// Musical key.
int32_t key;

/// Number (possibly?) indicating average loudness.
double average_loudness_1;

/// Number (possibly?) indicating average loudness.
double average_loudness_2;

/// Number (possibly?) indicating average loudness.
double average_loudness_3;

/// Extra data (if any) found in a decoded blob.
std::vector<std::byte> extra_data;

/// Encode this struct into binary blob form.
///
/// \return Returns a byte array.
[[nodiscard]] std::vector<char> to_blob() const;
[[nodiscard]] std::vector<std::byte> to_blob() const;

/// Decode an instance of this struct from binary blob form.
///
/// \param blob Binary blob.
/// \return Returns a decoded instance of this struct.
[[nodiscard]] static track_data_blob from_blob(
const std::vector<char>& blob);
const std::vector<std::byte>& blob);

friend bool operator==(
const track_data_blob& lhs, const track_data_blob& rhs) noexcept
{
return lhs.sample_rate == rhs.sample_rate &&
lhs.samples == rhs.samples &&
lhs.average_loudness == rhs.average_loudness &&
lhs.key == rhs.key;
lhs.key == rhs.key &&
lhs.average_loudness_1 == rhs.average_loudness_1 &&
lhs.average_loudness_2 == rhs.average_loudness_2 &&
lhs.average_loudness_3 == rhs.average_loudness_3 &&
lhs.extra_data == rhs.extra_data;
}

friend bool operator!=(
Expand All @@ -76,8 +89,11 @@ struct DJINTEROP_PUBLIC track_data_blob
{
os << "track_data_blob{sample_rate=" << obj.sample_rate
<< ", samples=" << obj.samples
<< ", average_loudness=" << obj.average_loudness
<< ", key=" << obj.key << "}";
<< ", key=" << obj.key
<< ", average_loudness_1=" << obj.average_loudness_1
<< ", average_loudness_2=" << obj.average_loudness_2
<< ", average_loudness_3=" << obj.average_loudness_3
<< "}";
return os;
}
};
Expand Down
2 changes: 1 addition & 1 deletion include/djinterop/pad_color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ inline bool operator!=(const pad_color& x, const pad_color& y)
inline std::ostream& operator<<(std::ostream& o, const djinterop::pad_color& v)
{
o << "pad_color{r=" << (int)v.r << ", g=" << (int)v.g << ", b=" << (int)v.b
<< ", a=" << (int)v.a;
<< ", a=" << (int)v.a << "}";
return o;
}
} // namespace djinterop
Expand Down
Loading