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

chore: update rekordbox kaitai definitions #13293

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
32 changes: 9 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,6 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/library/recording/dlgrecording.cpp
src/library/recording/dlgrecording.ui
src/library/recording/recordingfeature.cpp
src/library/rekordbox/kaitaistructs/rekordbox_anlz.cpp
src/library/rekordbox/kaitaistructs/rekordbox_pdb.cpp
src/library/rekordbox/rekordboxfeature.cpp
src/library/rhythmbox/rhythmboxfeature.cpp
src/library/scanner/importfilestask.cpp
Expand Down Expand Up @@ -1576,26 +1574,6 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Enabling QML Debugging! This poses a security risk as Mixxx will open a TCP port for debugging")
endif()

# Disable warnings in generated source files
if(GNU_GCC OR LLVM_CLANG)
set_property(
SOURCE src/library/rekordbox/kaitaistructs/rekordbox_anlz.cpp
APPEND_STRING
PROPERTY COMPILE_OPTIONS -Wno-unused-parameter
)
set_property(
SOURCE src/library/rekordbox/kaitaistructs/rekordbox_pdb.cpp
APPEND_STRING
PROPERTY COMPILE_OPTIONS -Wno-unused-parameter -Wno-switch
)
elseif(MSVC)
set_property(
SOURCE src/library/rekordbox/kaitaistructs/rekordbox_pdb.cpp
APPEND_STRING
PROPERTY COMPILE_OPTIONS /wd4244
)
endif()

option(WARNINGS_PEDANTIC "Let the compiler show even more warnings" OFF)
if(MSVC)
if(WARNINGS_PEDANTIC)
Expand Down Expand Up @@ -2508,12 +2486,20 @@ target_link_libraries(mixxx-lib PRIVATE FpClassify)
find_package(mp3lame REQUIRED)
target_link_libraries(mixxx-lib PRIVATE mp3lame::mp3lame)

add_library(rekordbox_metadata STATIC EXCLUDE_FROM_ALL
lib/rekordbox-metadata/rekordbox_pdb.cpp
lib/rekordbox-metadata/rekordbox_anlz.cpp
)
target_include_directories(rekordbox_metadata SYSTEM PUBLIC lib/rekordbox-metadata)
target_link_libraries(mixxx-lib PRIVATE rekordbox_metadata)

# Kaitai for reading Rekordbox libraries
add_library(Kaitai STATIC EXCLUDE_FROM_ALL
lib/kaitai/kaitaistream.cpp
lib/kaitai/kaitai/kaitaistream.cpp
)
Comment on lines +2489 to 2499
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a lot of code quality complaints on the output of the kaitai compiler, so I moved the generated code to lib/ (first and foremost because the linters already ignore that and second because it also makes sense to treat autogenerated code that way).

target_include_directories(Kaitai SYSTEM PUBLIC lib/kaitai)
target_compile_definitions(Kaitai PRIVATE KS_STR_ENCODING_NONE)
target_link_libraries(rekordbox_metadata PRIVATE Kaitai)
target_link_libraries(mixxx-lib PRIVATE Kaitai)

# For determining MP3 timing offset cases in Rekordbox library feature
Expand Down
52 changes: 52 additions & 0 deletions lib/kaitai/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required (VERSION 3.11)
project (kaitai_struct_cpp_stl_runtime CXX)
enable_testing()

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
option(BUILD_TESTS "Build tests" ON)

set (CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(ZLIB)
find_package(Iconv)

set (HEADERS
kaitai/kaitaistream.h
kaitai/kaitaistruct.h
kaitai/exceptions.h
)

set (SOURCES
kaitai/kaitaistream.cpp
)

set(STRING_ENCODING_TYPE "ICONV" CACHE STRING "Set the way strings have to be encoded (ICONV|WIN32API|NONE|...)")

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_library (${PROJECT_NAME} ${HEADERS} ${SOURCES})
set_property(TARGET ${PROJECT_NAME} PROPERTY PUBLIC_HEADER ${HEADERS})
target_include_directories(${PROJECT_NAME} INTERFACE ${PROJECT_SOURCE_DIR})

if (ZLIB_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE ZLIB::ZLIB)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DKS_ZLIB)
endif()

if(Iconv_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE Iconv::Iconv)
endif()

include(Common.cmake)

install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include/kaitai
)

# Add the tests
if(BUILD_TESTS)
add_subdirectory(tests)
endif()
17 changes: 17 additions & 0 deletions lib/kaitai/Common.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if (STRING_ENCODING_TYPE STREQUAL "ICONV")
target_compile_definitions(${PROJECT_NAME} PRIVATE -DKS_STR_ENCODING_ICONV)
elseif (STRING_ENCODING_TYPE STREQUAL "WIN32API")
target_compile_definitions(${PROJECT_NAME} PRIVATE -DKS_STR_ENCODING_WIN32API)
elseif (STRING_ENCODING_TYPE STREQUAL "NONE")
target_compile_definitions(${PROJECT_NAME} PRIVATE -DKS_STR_ENCODING_NONE)
else()
# User action requested
endif()

# Maximum warnings emission, treat all warnings as errors
#
# This method was taken from https://www.pragmaticlinux.com/2022/07/enable-compiler-warnings-with-cmake/
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>
)
22 changes: 18 additions & 4 deletions lib/kaitai/LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
Copyright 2016-2019 Kaitai Project: MIT license
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Copyright (c) 2016-2022 Kaitai Project

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
File renamed without changes.
224 changes: 224 additions & 0 deletions lib/kaitai/kaitai/exceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
#ifndef KAITAI_EXCEPTIONS_H
#define KAITAI_EXCEPTIONS_H

#include <kaitai/kaitaistream.h>

#include <string>
#include <stdexcept>

// We need to use "noexcept" in virtual destructor of our exceptions
// subclasses. Different compilers have different ideas on how to
// achieve that: C++98 compilers prefer `throw()`, C++11 and later
// use `noexcept`. We define KS_NOEXCEPT macro for that.

#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)
#define KS_NOEXCEPT noexcept
#else
#define KS_NOEXCEPT throw()
#endif

namespace kaitai {

/**
* Common ancestor for all errors related to `bytes_to_str` operation. Also used
* to signal misc non-specific `bytes_to_str` failures.
*/
class bytes_to_str_error: public std::runtime_error {
public:
bytes_to_str_error(const std::string what):
std::runtime_error(std::string("bytes_to_str error: ") + what) {}

virtual ~bytes_to_str_error() KS_NOEXCEPT {};
};

/**
* Exception to signal that `bytes_to_str` operation was requested to use some encoding
* that is not available in given runtime environment.
*/
class unknown_encoding: public bytes_to_str_error {
public:
unknown_encoding(const std::string enc_name):
bytes_to_str_error(std::string("unknown encoding: `") + enc_name + std::string("`")) {}

virtual ~unknown_encoding() KS_NOEXCEPT {};
};

/**
* Exception to signal that `bytes_to_str` operation failed to decode given byte sequence.
*/
class illegal_seq_in_encoding: public bytes_to_str_error {
public:
illegal_seq_in_encoding(const std::string what):
bytes_to_str_error("illegal sequence: " + what) {}

virtual ~illegal_seq_in_encoding() KS_NOEXCEPT {};
};

/**
* Common ancestor for all error originating from Kaitai Struct usage.
* Stores KSY source path, pointing to an element supposedly guilty of
* an error.
*/
class kstruct_error: public std::runtime_error {
public:
kstruct_error(const std::string what, const std::string src_path):
std::runtime_error(src_path + ": " + what),
m_src_path(src_path)
{
}

virtual ~kstruct_error() KS_NOEXCEPT {};

protected:
const std::string m_src_path;
};

/**
* Error that occurs when default endianness should be decided with
* a switch, but nothing matches (although using endianness expression
* implies that there should be some positive result).
*/
class undecided_endianness_error: public kstruct_error {
public:
undecided_endianness_error(const std::string src_path):
kstruct_error("unable to decide on endianness for a type", src_path)
{
}

virtual ~undecided_endianness_error() KS_NOEXCEPT {};
};

/**
* Common ancestor for all validation failures. Stores pointer to
* KaitaiStream IO object which was involved in an error.
*/
class validation_failed_error: public kstruct_error {
public:
validation_failed_error(const std::string what, kstream* io, const std::string src_path):
kstruct_error("at pos " + kstream::to_string(io->pos()) + ": validation failed: " + what, src_path),
m_io(io)
{
}

// "at pos #{io.pos}: validation failed: #{msg}"

virtual ~validation_failed_error() KS_NOEXCEPT {};

protected:
kstream* m_io;
};

/**
* Signals validation failure: we required "actual" value to be equal to
* "expected", but it turned out that it's not.
*/
template<typename T>
class validation_not_equal_error: public validation_failed_error {
public:
validation_not_equal_error(const T& expected, const T& actual, kstream* io, const std::string src_path):
validation_failed_error("not equal", io, src_path),
m_expected(expected),
m_actual(actual)
{
}

// "not equal, expected #{expected.inspect}, but got #{actual.inspect}"

virtual ~validation_not_equal_error() KS_NOEXCEPT {};

protected:
const T& m_expected;
const T& m_actual;
};

/**
* Signals validation failure: we required "actual" value to be greater
* than or equal to "min", but it turned out that it's not.
*/
template<typename T>
class validation_less_than_error: public validation_failed_error {
public:
validation_less_than_error(const T& min, const T& actual, kstream* io, const std::string src_path):
validation_failed_error("not in range", io, src_path),
m_min(min),
m_actual(actual)
{
}

// "not in range, min #{min.inspect}, but got #{actual.inspect}"

virtual ~validation_less_than_error() KS_NOEXCEPT {};

protected:
const T& m_min;
const T& m_actual;
};

/**
* Signals validation failure: we required "actual" value to be less
* than or equal to "max", but it turned out that it's not.
*/
template<typename T>
class validation_greater_than_error: public validation_failed_error {
public:
validation_greater_than_error(const T& max, const T& actual, kstream* io, const std::string src_path):
validation_failed_error("not in range", io, src_path),
m_max(max),
m_actual(actual)
{
}

// "not in range, max #{max.inspect}, but got #{actual.inspect}"

virtual ~validation_greater_than_error() KS_NOEXCEPT {};

protected:
const T& m_max;
const T& m_actual;
};

/**
* Signals validation failure: we required "actual" value to be from
* the list, but it turned out that it's not.
*/
template<typename T>
class validation_not_any_of_error: public validation_failed_error {
public:
validation_not_any_of_error(const T& actual, kstream* io, const std::string src_path):
validation_failed_error("not any of the list", io, src_path),
m_actual(actual)
{
}

// "not any of the list, got #{actual.inspect}"

virtual ~validation_not_any_of_error() KS_NOEXCEPT {};

protected:
const T& m_actual;
};

/**
* Signals validation failure: we required "actual" value to match
* the expression, but it turned out that it doesn't.
*/
template<typename T>
class validation_expr_error: public validation_failed_error {
public:
validation_expr_error(const T& actual, kstream* io, const std::string src_path):
validation_failed_error("not matching the expression", io, src_path),
m_actual(actual)
{
}

// "not matching the expression, got #{actual.inspect}"

virtual ~validation_expr_error() KS_NOEXCEPT {};

protected:
const T& m_actual;
};

}

#endif
Loading
Loading