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<BeamAlterationsDownStem> : private FieldPopulator<BeamAlterations>
59{
60 static void populate(const std::shared_ptr<BeamAlterationsDownStem>& instance,
61 const XmlElementPtr& element,
62 ElementLinker& elementLinker)
63 {
64 FieldPopulator<BeamAlterations>::template populate<BeamAlterationsDownStem>(instance, element, elementLinker);
65 }
66};
67
68template <>
69struct FieldPopulator<BeamAlterationsUpStem> : private FieldPopulator<BeamAlterations>
70{
71 static void populate(const std::shared_ptr<BeamAlterationsUpStem>& instance,
72 const XmlElementPtr& element,
73 ElementLinker& elementLinker)
74 {
75 FieldPopulator<BeamAlterations>::template populate<BeamAlterationsUpStem>(instance, element, elementLinker);
76 }
77};
78
79template <>
80struct FieldPopulator<BeamExtensionDownStem> : private FieldPopulator<BeamExtension>
81{
82 using FieldPopulator<BeamExtension>::populate;
83};
84
85template <>
86struct FieldPopulator<BeamExtensionUpStem> : private FieldPopulator<BeamExtension>
87{
88 using FieldPopulator<BeamExtension>::populate;
89};
90
91template <>
92struct FieldPopulator<CustomDownStem> : private FieldPopulator<CustomStem>
93{
94 using FieldPopulator<CustomStem>::populate;
95};
96
97template <>
98struct FieldPopulator<CustomUpStem> : private FieldPopulator<CustomStem>
99{
100 using FieldPopulator<CustomStem>::populate;
101};
102
103template <>
104struct FieldPopulator<LyricAssignChorus> : private FieldPopulator<LyricAssign>
105{
106 using FieldPopulator<LyricAssign>::populate;
107};
108
109template <>
110struct FieldPopulator<LyricAssignSection> : private FieldPopulator<LyricAssign>
111{
112 using FieldPopulator<LyricAssign>::populate;
113};
114
115template <>
116struct FieldPopulator<LyricAssignVerse> : private FieldPopulator<LyricAssign>
117{
118 using FieldPopulator<LyricAssign>::populate;
119};
120
121template <>
122struct FieldPopulator<SecondaryBeamAlterationsDownStem> : private FieldPopulator<BeamAlterations>
123{
124 static void populate(const std::shared_ptr<SecondaryBeamAlterationsDownStem>& instance,
125 const XmlElementPtr& element,
126 ElementLinker& elementLinker)
127 {
128 FieldPopulator<BeamAlterations>::template populate<SecondaryBeamAlterationsDownStem>(instance, element, elementLinker);
129 }
130};
131
132template <>
133struct FieldPopulator<SecondaryBeamAlterationsUpStem> : private FieldPopulator<BeamAlterations>
134{
135 static void populate(const std::shared_ptr<SecondaryBeamAlterationsUpStem>& instance,
136 const XmlElementPtr& element,
137 ElementLinker& elementLinker)
138 {
139 FieldPopulator<BeamAlterations>::template populate<SecondaryBeamAlterationsUpStem>(instance, element, elementLinker);
140 }
141};
142
143template <>
144struct FieldPopulator<ShapeNote> : private FieldPopulator<ShapeNoteBase>
145{
146 using FieldPopulator<ShapeNoteBase>::populate;
147};
148
149template <>
150struct FieldPopulator<ShapeNoteStyle> : private FieldPopulator<ShapeNoteBase>
151{
152 using FieldPopulator<ShapeNoteBase>::populate;
153};
154
155template <>
156struct FieldPopulator<StemAlterationsUnderBeam> : private FieldPopulator<StemAlterations>
157{
158 using FieldPopulator<StemAlterations>::populate;
159};
160
161template <>
162struct FieldPopulator<TieAlterEnd> : private FieldPopulator<TieAlterBase>
163{
164 using FieldPopulator<TieAlterBase>::populate;
165};
166
167template <>
168struct FieldPopulator<TieAlterStart> : private FieldPopulator<TieAlterBase>
169{
170 using FieldPopulator<TieAlterBase>::populate;
171};
172
173template <>
174inline Bracket::BracketStyle toEnum<Bracket::BracketStyle>(const int& value)
175{
176 if (value >= static_cast<int>(Bracket::BracketStyle::None) &&
177 value <= static_cast<int>(Bracket::BracketStyle::DeskBracket)) {
178 return static_cast<Bracket::BracketStyle>(value);
179 }
180 MUSX_UNKNOWN_XML("Invalid <bracket><id> value in XML for Bracket: " + std::to_string(value));
181 return {};
182}
183
184MUSX_RESOLVER_ENTRY(BeamAlterationsDownStem, BeamAlterations::calcAllActiveFlags<BeamAlterationsDownStem>);
185MUSX_RESOLVER_ENTRY(BeamAlterationsUpStem, BeamAlterations::calcAllActiveFlags<BeamAlterationsUpStem>);
186MUSX_RESOLVER_ENTRY(SecondaryBeamAlterationsDownStem, BeamAlterations::calcAllActiveFlags<SecondaryBeamAlterationsDownStem>);
187MUSX_RESOLVER_ENTRY(SecondaryBeamAlterationsUpStem, BeamAlterations::calcAllActiveFlags<SecondaryBeamAlterationsUpStem>);
188
189MUSX_RESOLVER_ENTRY(StaffGroup, {
190 [](const dom::DocumentPtr& document) {
191 auto parts = document->getOthers()->getArray<others::PartDefinition>(SCORE_PARTID);
192 for (const auto& part : parts) {
193 auto groups = document->getDetails()->getArray<StaffGroup>(part->getCmper(), BASE_SYSTEM_ID);
194 const auto baseList = document->getOthers()->getArray<others::StaffUsed>(part->getCmper(), BASE_SYSTEM_ID);
195 for (const auto& instance : groups) {
196 auto startIndex = baseList.getIndexForStaff(instance->startInst);
197 auto endIndex = baseList.getIndexForStaff(instance->endInst);
198 if (!startIndex || !endIndex) {
199 // this situation arises fairly commonly in Finale files, so the message is demoted to a verbose logging message
200 // from an integrity error.
201 util::Logger::log(util::Logger::LogLevel::Verbose, "Group " + std::to_string(instance->getCmper2()) + " in part " + part->getName()
202 + " [" + std::to_string(part->getCmper()) + "] has non-existent start or end staff cmpers");
203 continue;
204 }
205 for (size_t x = *startIndex; x <= *endIndex && x < baseList.size(); x++) {
206 auto mutableInstance = const_cast<StaffGroup*>(instance.get());
207 mutableInstance->staves.insert(baseList[x]->staffId);
208 }
209 }
210 }
211 }
212});
213
214} // namespace factory
215} // namespace musx
216
217#endif // DOXYGEN_SHOULD_IGNORE THIS
@ 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:39
constexpr Cmper SCORE_PARTID
The part id of the score.
Definition Fundamentals.h:79
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::StaffU...
Definition Fundamentals.h:80
Provides interfaces and optional implementations for traversing XML.
Definition PugiXmlImpl.h:33
object model for musx file (enigmaxml)
Definition BaseClasses.h:36