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<BaselineChords> : private FieldPopulator<Baseline>
41{
42 using FieldPopulator<Baseline>::populate;
43};
44
45template <>
46struct FieldPopulator<BaselineExpressionsAbove> : private FieldPopulator<Baseline>
47{
48 using FieldPopulator<Baseline>::populate;
49};
50
51template <>
52struct FieldPopulator<BaselineExpressionsBelow> : private FieldPopulator<Baseline>
53{
54 using FieldPopulator<Baseline>::populate;
55};
56
57template <>
58struct FieldPopulator<BaselineFretboards> : private FieldPopulator<Baseline>
59{
60 using FieldPopulator<Baseline>::populate;
61};
62
63template <>
64struct FieldPopulator<BaselineLyricsChorus> : private FieldPopulator<Baseline>
65{
66 using FieldPopulator<Baseline>::populate;
67};
68
69template <>
70struct FieldPopulator<BaselineLyricsSection> : private FieldPopulator<Baseline>
71{
72 using FieldPopulator<Baseline>::populate;
73};
74
75template <>
76struct FieldPopulator<BaselineLyricsVerse> : private FieldPopulator<Baseline>
77{
78 using FieldPopulator<Baseline>::populate;
79};
80
81template <>
82struct FieldPopulator<BaselineSystemChords> : private FieldPopulator<Baseline>
83{
84 using FieldPopulator<Baseline>::populate;
85};
86
87template <>
88struct FieldPopulator<BaselineSystemExpressionsAbove> : private FieldPopulator<Baseline>
89{
90 using FieldPopulator<Baseline>::populate;
91};
92
93template <>
94struct FieldPopulator<BaselineSystemExpressionsBelow> : private FieldPopulator<Baseline>
95{
96 using FieldPopulator<Baseline>::populate;
97};
98
99template <>
100struct FieldPopulator<BaselineSystemFretboards> : private FieldPopulator<Baseline>
101{
102 using FieldPopulator<Baseline>::populate;
103};
104
105template <>
106struct FieldPopulator<BaselineSystemLyricsChorus> : private FieldPopulator<Baseline>
107{
108 using FieldPopulator<Baseline>::populate;
109};
110
111template <>
112struct FieldPopulator<BaselineSystemLyricsSection> : private FieldPopulator<Baseline>
113{
114 using FieldPopulator<Baseline>::populate;
115};
116
117template <>
118struct FieldPopulator<BaselineSystemLyricsVerse> : private FieldPopulator<Baseline>
119{
120 using FieldPopulator<Baseline>::populate;
121};
122
123template <>
124struct FieldPopulator<BeamAlterationsDownStem> : private FieldPopulator<BeamAlterations>
125{
126 static void populate(const std::shared_ptr<BeamAlterationsDownStem>& instance,
127 const XmlElementPtr& element,
128 ElementLinker& elementLinker)
129 {
130 FieldPopulator<BeamAlterations>::template populate<BeamAlterationsDownStem>(instance, element, elementLinker);
131 }
132};
133
134template <>
135struct FieldPopulator<BeamAlterationsUpStem> : private FieldPopulator<BeamAlterations>
136{
137 static void populate(const std::shared_ptr<BeamAlterationsUpStem>& instance,
138 const XmlElementPtr& element,
139 ElementLinker& elementLinker)
140 {
141 FieldPopulator<BeamAlterations>::template populate<BeamAlterationsUpStem>(instance, element, elementLinker);
142 }
143};
144
145template <>
146struct FieldPopulator<BeamExtensionDownStem> : private FieldPopulator<BeamExtension>
147{
148 using FieldPopulator<BeamExtension>::populate;
149};
150
151template <>
152struct FieldPopulator<BeamExtensionUpStem> : private FieldPopulator<BeamExtension>
153{
154 using FieldPopulator<BeamExtension>::populate;
155};
156
157template <>
158struct FieldPopulator<CustomDownStem> : private FieldPopulator<CustomStem>
159{
160 using FieldPopulator<CustomStem>::populate;
161};
162
163template <>
164struct FieldPopulator<CustomUpStem> : private FieldPopulator<CustomStem>
165{
166 using FieldPopulator<CustomStem>::populate;
167};
168
169template <>
170struct FieldPopulator<LyricAssignChorus> : private FieldPopulator<LyricAssign>
171{
172 using FieldPopulator<LyricAssign>::populate;
173};
174
175template <>
176struct FieldPopulator<LyricAssignSection> : private FieldPopulator<LyricAssign>
177{
178 using FieldPopulator<LyricAssign>::populate;
179};
180
181template <>
182struct FieldPopulator<LyricAssignVerse> : private FieldPopulator<LyricAssign>
183{
184 using FieldPopulator<LyricAssign>::populate;
185};
186
187template <>
188struct FieldPopulator<SecondaryBeamAlterationsDownStem> : private FieldPopulator<BeamAlterations>
189{
190 static void populate(const std::shared_ptr<SecondaryBeamAlterationsDownStem>& instance,
191 const XmlElementPtr& element,
192 ElementLinker& elementLinker)
193 {
194 FieldPopulator<BeamAlterations>::template populate<SecondaryBeamAlterationsDownStem>(instance, element, elementLinker);
195 }
196};
197
198template <>
199struct FieldPopulator<SecondaryBeamAlterationsUpStem> : private FieldPopulator<BeamAlterations>
200{
201 static void populate(const std::shared_ptr<SecondaryBeamAlterationsUpStem>& instance,
202 const XmlElementPtr& element,
203 ElementLinker& elementLinker)
204 {
205 FieldPopulator<BeamAlterations>::template populate<SecondaryBeamAlterationsUpStem>(instance, element, elementLinker);
206 }
207};
208
209template <>
210struct FieldPopulator<ShapeNote> : private FieldPopulator<ShapeNoteBase>
211{
212 using FieldPopulator<ShapeNoteBase>::populate;
213};
214
215template <>
216struct FieldPopulator<ShapeNoteStyle> : private FieldPopulator<ShapeNoteBase>
217{
218 using FieldPopulator<ShapeNoteBase>::populate;
219};
220
221template <>
222struct FieldPopulator<StemAlterationsUnderBeam> : private FieldPopulator<StemAlterations>
223{
224 using FieldPopulator<StemAlterations>::populate;
225};
226
227template <>
228struct FieldPopulator<TieAlterEnd> : private FieldPopulator<TieAlterBase>
229{
230 using FieldPopulator<TieAlterBase>::populate;
231};
232
233template <>
234struct FieldPopulator<TieAlterStart> : private FieldPopulator<TieAlterBase>
235{
236 using FieldPopulator<TieAlterBase>::populate;
237};
238
239template <>
240inline Bracket::BracketStyle toEnum<Bracket::BracketStyle>(const int& value)
241{
242 if (value >= static_cast<int>(Bracket::BracketStyle::None) &&
243 value <= static_cast<int>(Bracket::BracketStyle::DeskBracket)) {
244 return static_cast<Bracket::BracketStyle>(value);
245 }
246 MUSX_UNKNOWN_XML("Invalid <bracket><id> value in XML for Bracket: " + std::to_string(value));
247 return {};
248}
249
250MUSX_RESOLVER_ENTRY(BeamAlterationsDownStem, BeamAlterations::calcAllActiveFlags<BeamAlterationsDownStem>);
251MUSX_RESOLVER_ENTRY(BeamAlterationsUpStem, BeamAlterations::calcAllActiveFlags<BeamAlterationsUpStem>);
252MUSX_RESOLVER_ENTRY(SecondaryBeamAlterationsDownStem, BeamAlterations::calcAllActiveFlags<SecondaryBeamAlterationsDownStem>);
253MUSX_RESOLVER_ENTRY(SecondaryBeamAlterationsUpStem, BeamAlterations::calcAllActiveFlags<SecondaryBeamAlterationsUpStem>);
254
255MUSX_RESOLVER_ENTRY(StaffGroup, {
256 [](const dom::DocumentPtr& document) {
257 auto parts = document->getOthers()->getArray<others::PartDefinition>(SCORE_PARTID);
258 for (const auto& part : parts) {
259 auto groups = document->getDetails()->getArray<StaffGroup>(part->getCmper(), BASE_SYSTEM_ID);
260 const auto baseList = document->getOthers()->getArray<others::StaffUsed>(part->getCmper(), BASE_SYSTEM_ID);
261 for (const auto& instance : groups) {
262 auto startIndex = baseList.getIndexForStaff(instance->startInst);
263 auto endIndex = baseList.getIndexForStaff(instance->endInst);
264 if (!startIndex || !endIndex) {
265 // this situation arises fairly commonly in Finale files, so the message is demoted to a verbose logging message
266 // from an integrity error.
267 util::Logger::log(util::Logger::LogLevel::Verbose, "Group " + std::to_string(instance->getCmper2()) + " in part " + part->getName()
268 + " [" + std::to_string(part->getCmper()) + "] has non-existent start or end staff cmpers");
269 continue;
270 }
271 for (size_t x = *startIndex; x <= *endIndex && x < baseList.size(); x++) {
272 auto mutableInstance = const_cast<StaffGroup*>(instance.get());
273 mutableInstance->staves.insert(baseList[x]->staffId);
274 }
275 }
276 }
277 }
278});
279
280} // namespace factory
281} // namespace musx
282
283#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