diff --git a/include/adm/utilities/object_creation.hpp b/include/adm/utilities/object_creation.hpp index 7f40fd4e..3d452cf2 100644 --- a/include/adm/utilities/object_creation.hpp +++ b/include/adm/utilities/object_creation.hpp @@ -87,4 +87,29 @@ namespace adm { const std::string& name, const std::string& speakerLayout); + /** + * @brief Create and add `AudioObject` with common definitions direct speakers + * channel bed to document + * + * Creates an `AudioObject` and corresponding `AudioTrackUids` and connects it + * to the common definition ADM elements for the given speaker layout. The + * created ADM elements are added to the given document. + * + * @note The document must already have the common definition elements added. + * + * @param document The document where the `AudioObject` and the + * `AudioTrackUids` should be added to and whose common definition ADM + * elements should be used. + * @param name Name that will be used for the created `AudioObject`. + * @param packFormatId AudioPackFormatId of the given layout. + * @param trackFormatIds AudioTrackFormatIds of all the speakers in the layout. + * @param speakerLabels Labels of all the speakers in the layout. + */ + ADM_EXPORT SimpleCommonDefinitionsObjectHolder + addSimpleCommonDefinitionsObjectTo(std::shared_ptr document, + const std::string& name, + const std::string& packFormatId, + const std::vector& trackFormatIds, + const std::vector& speakerLabels); + } // namespace adm diff --git a/src/utilities/object_creation.cpp b/src/utilities/object_creation.cpp index 071bae94..33f15928 100644 --- a/src/utilities/object_creation.cpp +++ b/src/utilities/object_creation.cpp @@ -71,4 +71,45 @@ namespace adm { document->add(holder.audioObject); return holder; } + + SimpleCommonDefinitionsObjectHolder addSimpleCommonDefinitionsObjectTo( + std::shared_ptr document, const std::string& name, + const std::string& packFormatId, + const std::vector& trackFormatIds, + const std::vector& speakerLabels) { + SimpleCommonDefinitionsObjectHolder holder; + holder.audioObject = AudioObject::create(AudioObjectName(name)); + auto packFormat = + document->lookup(adm::parseAudioPackFormatId(packFormatId)); + if (!packFormat) { + std::stringstream ss; + ss << "AudioPackFormatId \"" << packFormatId + << "\" not found. Are the common definitions added to the document?"; + throw error::AdmException(ss.str()); + } + holder.audioObject->addReference(packFormat); + if (trackFormatIds.size() != speakerLabels.size()) { + std::stringstream ss; + ss << "Sizes of trackFormatIds and speakerLabels arguments do not match."; + throw error::AdmException(ss.str()); + } + for (size_t i = 0; i < trackFormatIds.size(); i++) { + auto track = + document->lookup(adm::parseAudioTrackFormatId(trackFormatIds.at(i))); + if (!track) { + std::stringstream ss; + ss << "AudioTrackFormatId \"" << trackFormatIds.at(i) + << "\" not found. Id might be invalid."; + throw error::AdmException(ss.str()); + } + auto uid = AudioTrackUid::create(); + uid->setReference(packFormat); + uid->setReference(track); + holder.audioObject->addReference(uid); + holder.audioTrackUids[speakerLabels.at(i)] = uid; + } + document->add(holder.audioObject); + return holder; + } + } // namespace adm