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

implement features from bs.2076-3 draft #167

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
12 changes: 12 additions & 0 deletions include/adm/detail/named_option_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,17 @@ namespace adm {
setNamedOptionHelper(std::forward<Element>(element), std::move(args)...);
}

/// check that the first template type is present in the remainder
template <typename T>
constexpr bool optionInList() {
return false;
}

template <typename T, typename Param, typename... Params>
constexpr bool optionInList() {
using ParamT = std::remove_const_t<std::remove_reference_t<Param>>;
return std::is_same<T, ParamT>::value || optionInList<T, Params...>();
}

} // namespace detail
} // namespace adm
35 changes: 34 additions & 1 deletion include/adm/document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,40 @@
#pragma once

#include <memory>
#include <string>
#include <vector>
#include "adm/elements.hpp"
#include "adm/detail/auto_base.hpp"
#include "adm/detail/id_assigner.hpp"
#include "adm/detail/named_type.hpp"
#include "adm/export.h"

namespace adm {

/// tag for version
struct VersionTag {};
/// NamedType for audioFormatExtended version attribute
using Version = detail::NamedType<std::string, VersionTag>;

namespace detail {
extern template class ADM_EXPORT_TEMPLATE_METHODS
OptionalParameter<ProfileList>;
extern template class ADM_EXPORT_TEMPLATE_METHODS
OptionalParameter<Version>;

using DocumentBase = HasParameters<OptionalParameter<ProfileList>,
OptionalParameter<Version>>;
} // namespace detail

/**
* @ingroup main
* @brief Class representation of a whole ADM document
* @headerfile document.hpp <adm/document.hpp>
*
*/
class Document : public std::enable_shared_from_this<Document> {
class Document : public std::enable_shared_from_this<Document>,
private detail::DocumentBase,
public detail::AddWrapperMethods<Document> {
public:
/**
* @brief Static helper function to create an Document
Expand Down Expand Up @@ -202,6 +222,12 @@ namespace adm {
const AudioTrackUidId &trackUidId) const;
///@}

using detail::DocumentBase::set;
using detail::AddWrapperMethods<Document>::get;
using detail::AddWrapperMethods<Document>::has;
using detail::AddWrapperMethods<Document>::isDefault;
using detail::AddWrapperMethods<Document>::unset;

private:
ADM_EXPORT Document();
ADM_EXPORT Document(const Document &) = default;
Expand Down Expand Up @@ -251,6 +277,13 @@ namespace adm {
template <typename Element>
bool checkParent(const std::shared_ptr<Element> &element, const char *type);

using detail::DocumentBase::get;
using detail::DocumentBase::has;
using detail::DocumentBase::isDefault;
using detail::DocumentBase::unset;

friend class detail::AddWrapperMethods<Document>;

std::vector<std::shared_ptr<AudioProgramme>> audioProgrammes_;
std::vector<std::shared_ptr<AudioContent>> audioContents_;
std::vector<std::shared_ptr<AudioObject>> audioObjects_;
Expand Down
1 change: 1 addition & 0 deletions include/adm/elements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "adm/elements/audio_track_format.hpp"
#include "adm/elements/audio_stream_format.hpp"
#include "adm/elements/audio_track_uid.hpp"
#include "adm/elements/profile_list.hpp"

#include "adm/elements/audio_block_format_direct_speakers.hpp"
#include "adm/elements/audio_block_format_matrix.hpp"
Expand Down
116 changes: 116 additions & 0 deletions include/adm/elements/profile_list.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#pragma once
#include <vector>
#include "adm/detail/auto_base.hpp"
#include "adm/detail/named_option_helper.hpp"
#include "adm/detail/optional_comparison.hpp"

namespace adm {
struct ProfileValueTag {};
using ProfileValue = detail::NamedType<std::string, ProfileValueTag>;

struct ProfileNameTag {};
using ProfileName = detail::NamedType<std::string, ProfileNameTag>;

struct ProfileVersionTag {};
using ProfileVersion = detail::NamedType<std::string, ProfileVersionTag>;

struct ProfileLevelTag {};
using ProfileLevel = detail::NamedType<std::string, ProfileLevelTag>;

struct ProfileTag {};

namespace detail {
extern template class ADM_EXPORT_TEMPLATE_METHODS
RequiredParameter<ProfileValue>;
extern template class ADM_EXPORT_TEMPLATE_METHODS
RequiredParameter<ProfileName>;
extern template class ADM_EXPORT_TEMPLATE_METHODS
RequiredParameter<ProfileVersion>;
extern template class ADM_EXPORT_TEMPLATE_METHODS
RequiredParameter<ProfileLevel>;

using ProfileBase = HasParameters<
RequiredParameter<ProfileValue>, RequiredParameter<ProfileName>,
RequiredParameter<ProfileVersion>, RequiredParameter<ProfileLevel>>;
} // namespace detail

class Profile : private detail::ProfileBase,
public detail::AddWrapperMethods<Profile> {
public:
using tag = ProfileTag;

template <typename... Parameters>
explicit Profile(Parameters... namedArgs) {
detail::setNamedOptionHelper(this, std::move(namedArgs)...);
static_assert(detail::optionInList<ProfileValue, Parameters...>(),
"ProfileValue must be specified");
static_assert(detail::optionInList<ProfileName, Parameters...>(),
"ProfileName must be specified");
static_assert(detail::optionInList<ProfileVersion, Parameters...>(),
"ProfileVersion must be specified");
static_assert(detail::optionInList<ProfileLevel, Parameters...>(),
"ProfileLevel must be specified");
}

using detail::ProfileBase::set;
using detail::AddWrapperMethods<Profile>::get;
using detail::AddWrapperMethods<Profile>::has;
using detail::AddWrapperMethods<Profile>::isDefault;
using detail::AddWrapperMethods<Profile>::unset;

private:
using detail::ProfileBase::get;
using detail::ProfileBase::has;

friend class detail::AddWrapperMethods<Profile>;
};

inline bool operator==(const Profile &a, const Profile &b) {
return detail::optionalsEqual<ProfileValue, ProfileName, ProfileVersion,
ProfileLevel>(a, b);
}

inline bool operator!=(const Profile &a, const Profile &b) {
return !(a == b);
}

struct ProfilesTag {};

using Profiles = std::vector<Profile>;
ADD_TRAIT(Profiles, ProfilesTag);

namespace detail {
extern template class ADM_EXPORT_TEMPLATE_METHODS VectorParameter<Profiles>;

using ProfileListBase = HasParameters<VectorParameter<Profiles>>;
} // namespace detail

struct ProfileceListTag {};

class ProfileList : private detail::ProfileListBase,
public detail::AddWrapperMethods<ProfileList> {
public:
using tag = ProfileceListTag;

template <typename... Parameters>
explicit ProfileList(Parameters... namedArgs) {
detail::setNamedOptionHelper(this, std::move(namedArgs)...);
}

using detail::ProfileListBase::set;
using detail::AddWrapperMethods<ProfileList>::get;
using detail::AddWrapperMethods<ProfileList>::has;
using detail::AddWrapperMethods<ProfileList>::isDefault;
using detail::AddWrapperMethods<ProfileList>::unset;
using detail::ProfileListBase::add;
using detail::ProfileListBase::remove;

private:
using detail::ProfileListBase::get;
using detail::ProfileListBase::has;
using detail::ProfileListBase::isDefault;
using detail::ProfileListBase::unset;

friend class detail::AddWrapperMethods<ProfileList>;
};
} // namespace adm
2 changes: 1 addition & 1 deletion include/adm/elements/screen_edge_lock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace adm {

/// @brief Tag for NamedTyoe ::ScreenEdge
/// @brief Tag for NamedType ::ScreenEdge
struct ScreenEdgeTag {};
/**
* @brief NamedType for the screen edge
Expand Down
2 changes: 1 addition & 1 deletion include/adm/elements/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace adm {
}

/// normalised fraction, such that numerator and denominator have no common
/// fractors
/// factors
ADM_EXPORT FractionalTime normalised() const;

private:
Expand Down
2 changes: 2 additions & 0 deletions include/adm/private/rapidxml_formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace adm {
const std::shared_ptr<const AudioTrackFormat> trackFormat);
void formatAudioTrackUid(
XmlNode &node, const std::shared_ptr<const AudioTrackUid> trackUid);
void formatProfileList(XmlNode &node, const ProfileList &profileList);
void formatProfile(XmlNode &node, const Profile &profile);

void formatBlockFormatDirectSpeakers(
XmlNode &node, const AudioBlockFormatDirectSpeakers &audioBlock);
Expand Down
2 changes: 2 additions & 0 deletions include/adm/private/xml_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace adm {
HeadphoneVirtualise parseHeadphoneVirtualise(NodePtr node);
AudioBlockFormatHoa parseAudioBlockFormatHoa(NodePtr node);
AudioBlockFormatBinaural parseAudioBlockFormatBinaural(NodePtr node);
Profile parseProfile(NodePtr node);

NodePtr findAudioFormatExtendedNodeEbuCore(NodePtr root);
NodePtr findAudioFormatExtendedNodeFullRecursive(NodePtr root);
Expand Down Expand Up @@ -94,6 +95,7 @@ namespace adm {
std::shared_ptr<AudioPackFormat> parseAudioPackFormat(NodePtr node);
std::shared_ptr<AudioTrackUid> parseAudioTrackUid(NodePtr node);
std::shared_ptr<AudioChannelFormat> parseAudioChannelFormat(NodePtr node);
ProfileList parseProfileList(NodePtr node);

rapidxml::file<> xmlFile_;
ParserOptions options_;
Expand Down
5 changes: 5 additions & 0 deletions include/adm/private/xml_parser_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ namespace adm {
}
}

template <typename NT>
NT parseValue(NodePtr node) {
return parseValue<NT>(node, detail::parseDefault<NT>);
}

template <typename NT, typename Target, typename Callable>
void setValue(NodePtr node, Target& target, Callable parser) {
detail::invokeSet(target, parseValue<NT>(node, parser));
Expand Down
2 changes: 1 addition & 1 deletion include/adm/utilities/object_creation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace adm {
ADM_EXPORT SimpleObjectHolder createSimpleObject(const std::string& name);

/**
* @brief Create and add `AudioObject` hierarchie for single
* @brief Create and add `AudioObject` hierarchy for single
* `TypeDefinition::OBJECTS`-type element
*
* same as `createSimpleObject`, but the elements are automatically added to
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ add_library(adm
elements/position.cpp
elements/position_offset.cpp
elements/position_interaction_range.cpp
elements/profile_list.cpp
elements/screen_edge_lock.cpp
elements/speaker_position.cpp
elements/type_descriptor.cpp
Expand Down
5 changes: 5 additions & 0 deletions src/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include <algorithm>

namespace adm {
namespace detail {
template class OptionalParameter<ProfileList>;
template class OptionalParameter<Version>;
} // namespace detail

Document::Document() { idAssigner_.document(this); }

std::shared_ptr<Document> Document::create() {
Expand Down
11 changes: 11 additions & 0 deletions src/elements/profile_list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "adm/elements/profile_list.hpp"

namespace adm {
namespace detail {
template class RequiredParameter<ProfileValue>;
template class RequiredParameter<ProfileName>;
template class RequiredParameter<ProfileVersion>;
template class RequiredParameter<ProfileLevel>;
template class VectorParameter<Profiles>;
} // namespace detail
} // namespace adm
11 changes: 11 additions & 0 deletions src/private/rapidxml_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,5 +672,16 @@ namespace adm {
trackUid, "audioPackFormatIDRef");
}

void formatProfileList(XmlNode &node, const ProfileList &profileList) {
node.addVectorElements<Profiles>(&profileList, "profile", &formatProfile);
}

void formatProfile(XmlNode &node, const Profile &profile) {
node.setValue(profile.get<ProfileValue>());
node.addAttribute<ProfileName>(&profile, "profileName");
node.addAttribute<ProfileVersion>(&profile, "profileVersion");
node.addAttribute<ProfileLevel>(&profile, "profileLevel");
}

} // namespace xml
} // namespace adm
24 changes: 24 additions & 0 deletions src/private/xml_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ namespace adm {
add(parseAudioStreamFormat(node));
} else if (nodeName == "audioTrackFormat") {
add(parseAudioTrackFormat(node));
} else if (nodeName == "profileList") {
if (document_->has<ProfileList>())
throw error::XmlParsingError(
"found more than one profileList element");
document_->set(parseProfileList(node));
}
}
resolveReferences(programmeContentRefs_);
Expand All @@ -92,6 +97,8 @@ namespace adm {
resolveReference(streamFormatChannelFormatRef_);
resolveReference(streamFormatPackFormatRef_);
resolveReferences(streamFormatTrackFormatRefs_);

setOptionalAttribute<Version>(root, "version", document_);
} else {
throw error::XmlParsingError("audioFormatExtended node not found");
}
Expand Down Expand Up @@ -460,6 +467,23 @@ namespace adm {
return audioTrackUid;
}

ProfileList XmlParser::parseProfileList(NodePtr node) {
ProfileList profileList;

addOptionalElements<Profile>(node, "profile", profileList, &parseProfile);

return profileList;
}

Profile parseProfile(NodePtr node) {
auto value = parseValue<ProfileValue>(node);
auto name = parseAttribute<ProfileName>(node, "profileName");
auto version = parseAttribute<ProfileVersion>(node, "profileVersion");
auto level = parseAttribute<ProfileLevel>(node, "profileLevel");

return Profile{value, name, version, level};
}

AudioBlockFormatDirectSpeakers parseAudioBlockFormatDirectSpeakers(
NodePtr node) {
AudioBlockFormatDirectSpeakers audioBlockFormat;
Expand Down
2 changes: 2 additions & 0 deletions src/private/xml_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ namespace adm {
root = xmlDocument.addEbuStructure();
}
// clang-format off
root.addOptionalAttribute<Version>(document, "version");
root.addOptionalElement<ProfileList>(document, "profileList", &formatProfileList);
root.addBaseElements<AudioProgramme, AudioProgrammeId>(document, "audioProgramme", &formatAudioProgramme);
root.addBaseElements<AudioContent, AudioContentId>(document, "audioContent", &formatAudioContent);
root.addBaseElements<AudioObject, AudioObjectId>(document, "audioObject", &formatAudioObject);
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ add_adm_test("object_divergence_tests")
add_adm_test("position_interaction_range_tests")
add_adm_test("position_tests")
add_adm_test("position_offset_tests")
add_adm_test("profile_list_tests")
add_adm_test("route_tracer_tests")
add_adm_test("screen_edge_lock_tests")
add_adm_test("speaker_position_tests")
add_adm_test("type_descriptor_tests")
add_adm_test("version_tests")
add_adm_test("xml_audio_block_format_objects_tests")
add_adm_test("xml_loudness_metadata_tests")
add_adm_test("xml_parser_audio_block_format_direct_speakers_tests")
Expand Down
Loading