MUSX Document Model
Loading...
Searching...
No Matches
FieldPopulatorsDetails.h
1/*
2 * Copyright (C) 2025, Robert Patterson
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22#pragma once
23
24#include "musx/dom/BaseClasses.h"
25#include "musx/dom/Others.h"
26#include "musx/dom/Details.h"
27#include "musx/dom/Document.h"
28#include "musx/xml/XmlInterface.h"
29#include "FactoryBase.h"
30
31#ifndef DOXYGEN_SHOULD_IGNORE_THIS
32
33namespace musx {
34namespace factory {
35
36using namespace ::musx::xml;
37using namespace ::musx::dom::details;
38
39template <>
40struct FieldPopulator<BaselineLyricsChorus> : private FieldPopulator<Baseline>
41{
42 using FieldPopulator<Baseline>::populate;
43};
44
45template <>
46struct FieldPopulator<BaselineLyricsSection> : private FieldPopulator<Baseline>
47{
48 using FieldPopulator<Baseline>::populate;
49};
50
51template <>
52struct FieldPopulator<BaselineLyricsVerse> : private FieldPopulator<Baseline>
53{
54 using FieldPopulator<Baseline>::populate;
55};
56
57template <>
58struct FieldPopulator<LyricAssignChorus> : private FieldPopulator<LyricAssign>
59{
60 using FieldPopulator<LyricAssign>::populate;
61};
62
63template <>
64struct FieldPopulator<LyricAssignSection> : private FieldPopulator<LyricAssign>
65{
66 using FieldPopulator<LyricAssign>::populate;
67};
68
69template <>
70struct FieldPopulator<LyricAssignVerse> : private FieldPopulator<LyricAssign>
71{
72 using FieldPopulator<LyricAssign>::populate;
73};
74
75template <>
76struct FieldPopulator<TieAlterEnd> : private FieldPopulator<TieAlterBase>
77{
78 using FieldPopulator<TieAlterBase>::populate;
79};
80
81template <>
82struct FieldPopulator<TieAlterStart> : private FieldPopulator<TieAlterBase>
83{
84 using FieldPopulator<TieAlterBase>::populate;
85};
86
87template <>
88inline StaffGroup::BracketStyle toEnum<StaffGroup::BracketStyle>(const int& value)
89{
90 if (value >= static_cast<int>(StaffGroup::BracketStyle::None) &&
91 value <= static_cast<int>(StaffGroup::BracketStyle::DeskBracket)) {
92 return static_cast<StaffGroup::BracketStyle>(value);
93 }
94 MUSX_UNKNOWN_XML("Invalid <bracket><id> value in XML for StaffGroup: " + std::to_string(value));
95 return {};
96}
97
98MUSX_RESOLVER_ENTRY(StaffGroup, {
99 [](const dom::DocumentPtr& document) {
100 auto parts = document->getOthers()->getArray<others::PartDefinition>(SCORE_PARTID);
101 for (const auto& part : parts) {
102 auto groups = document->getDetails()->getArray<StaffGroup>(part->getCmper(), BASE_SYSTEM_ID);
103 auto baseList = document->getOthers()->getArray<others::InstrumentUsed>(part->getCmper(), BASE_SYSTEM_ID);
104 for (const auto& instance : groups) {
105 auto startIndex = others::InstrumentUsed::getIndexForStaff(baseList, instance->startInst);
106 auto endIndex = others::InstrumentUsed::getIndexForStaff(baseList, instance->endInst);
107 if (!startIndex || !endIndex) {
108 // this situation arises fairly commonly in Finale files, so the message is demoted to a verbose logging message
109 // from an integrity error.
110 util::Logger::log(util::Logger::LogLevel::Verbose, "Group " + std::to_string(instance->getCmper2()) + " in part " + part->getName()
111 + " [" + std::to_string(part->getCmper()) + "] has non-existent start or end staff cmpers");
112 continue;
113 }
114 for (size_t x = *startIndex; x <= *endIndex && x < baseList.size(); x++) {
115 instance->staves.insert(baseList[x]->staffId);
116 }
117 }
118 }
119 }
120});
121
122} // namespace factory
123} // namespace musx
124
125#endif // DOXYGEN_SHOULD_IGNORE THIS
static std::optional< size_t > getIndexForStaff(const std::vector< std::shared_ptr< InstrumentUsed > > &iuArray, InstCmper staffId)
Returns the 0-based index of the InstCmper or std::nullopt if not found.
Definition Implementations.cpp:1067
@ Verbose
Informational messages that should only displayed when verbose logging is requested.
static void log(LogLevel level, const std::string &message)
Logs a message with a specific severity level.
Definition Logger.h:87
Classes in the DetailsPool.
Definition CommonClasses.h:296
constexpr Cmper SCORE_PARTID
The part id of the score.
Definition Fundamentals.h:75
std::shared_ptr< Document > DocumentPtr
Shared Document pointer.
Definition BaseClasses.h:55
constexpr Cmper BASE_SYSTEM_ID
The base system cmper that gives a list of all available staves and their score order (others::Instru...
Definition Fundamentals.h:76
Provides interfaces and optional implementations for traversing XML.
Definition PugiXmlImpl.h:33
object model for musx file (enigmaxml)
Definition BaseClasses.h:32