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<StemAlterationsUnderBeam> : private FieldPopulator<StemAlterations>
145{
146 using FieldPopulator<StemAlterations>::populate;
147};
148
149template <>
150struct FieldPopulator<TieAlterEnd> : private FieldPopulator<TieAlterBase>
151{
152 using FieldPopulator<TieAlterBase>::populate;
153};
154
155template <>
156struct FieldPopulator<TieAlterStart> : private FieldPopulator<TieAlterBase>
157{
158 using FieldPopulator<TieAlterBase>::populate;
159};
160
161template <>
162inline StaffGroup::BracketStyle toEnum<StaffGroup::BracketStyle>(const int& value)
163{
164 if (value >= static_cast<int>(StaffGroup::BracketStyle::None) &&
165 value <= static_cast<int>(StaffGroup::BracketStyle::DeskBracket)) {
166 return static_cast<StaffGroup::BracketStyle>(value);
167 }
168 MUSX_UNKNOWN_XML("Invalid <bracket><id> value in XML for StaffGroup: " + std::to_string(value));
169 return {};
170}
171
172MUSX_RESOLVER_ENTRY(BeamAlterationsDownStem, BeamAlterations::calcAllActiveFlags<BeamAlterationsDownStem>);
173MUSX_RESOLVER_ENTRY(BeamAlterationsUpStem, BeamAlterations::calcAllActiveFlags<BeamAlterationsUpStem>);
174MUSX_RESOLVER_ENTRY(SecondaryBeamAlterationsDownStem, BeamAlterations::calcAllActiveFlags<SecondaryBeamAlterationsDownStem>);
175MUSX_RESOLVER_ENTRY(SecondaryBeamAlterationsUpStem, BeamAlterations::calcAllActiveFlags<SecondaryBeamAlterationsUpStem>);
176
177MUSX_RESOLVER_ENTRY(StaffGroup, {
178 [](const dom::DocumentPtr& document) {
179 auto parts = document->getOthers()->getArray<others::PartDefinition>(SCORE_PARTID);
180 for (const auto& part : parts) {
181 auto groups = document->getDetails()->getArray<StaffGroup>(part->getCmper(), BASE_SYSTEM_ID);
182 auto baseList = document->getOthers()->getArray<others::InstrumentUsed>(part->getCmper(), BASE_SYSTEM_ID);
183 for (const auto& instance : groups) {
184 auto startIndex = others::InstrumentUsed::getIndexForStaff(baseList, instance->startInst);
185 auto endIndex = others::InstrumentUsed::getIndexForStaff(baseList, instance->endInst);
186 if (!startIndex || !endIndex) {
187 // this situation arises fairly commonly in Finale files, so the message is demoted to a verbose logging message
188 // from an integrity error.
189 util::Logger::log(util::Logger::LogLevel::Verbose, "Group " + std::to_string(instance->getCmper2()) + " in part " + part->getName()
190 + " [" + std::to_string(part->getCmper()) + "] has non-existent start or end staff cmpers");
191 continue;
192 }
193 for (size_t x = *startIndex; x <= *endIndex && x < baseList.size(); x++) {
194 instance->staves.insert(baseList[x]->staffId);
195 }
196 }
197 }
198 }
199});
200
201} // namespace factory
202} // namespace musx
203
204#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:1449
@ 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:328
constexpr Cmper SCORE_PARTID
The part id of the score.
Definition Fundamentals.h:80
std::shared_ptr< Document > DocumentPtr
Shared Document pointer.
Definition BaseClasses.h:51
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:81
Provides interfaces and optional implementations for traversing XML.
Definition PugiXmlImpl.h:33
object model for musx file (enigmaxml)
Definition BaseClasses.h:32