MUSX Document Model
Loading...
Searching...
No Matches
Document.h
1/*
2 * Copyright (C) 2024, 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 <memory>
25#include <optional>
26#include <unordered_map>
27#include <vector>
28
29#include "Header.h"
30#include "ObjectPool.h"
31#include "MusxInstance.h"
32
37namespace musx {
38
39namespace factory {
40class DocumentFactory;
41} // namespace factory
42
47namespace dom {
48
49using namespace header;
50
51struct InstrumentInfo;
52enum class KnownShapeDefType;
53using InstrumentMap = std::unordered_map<StaffCmper, InstrumentInfo>;
58{
59 std::unordered_map<StaffCmper, size_t> staves;
62
64 std::vector<StaffCmper> getSequentialStaves() const;
65
70 static const InstrumentInfo* getInstrumentForStaff(const InstrumentMap& map, StaffCmper staffId);
71};
72
77{
78 Ignore,
80
81 Apply
88};
89
94{
95public:
96
98 [[nodiscard]]
99 HeaderPtr& getHeader() { return m_header; }
101 [[nodiscard]]
102 const HeaderPtr& getHeader() const { return m_header; }
103
105 [[nodiscard]]
106 OptionsPoolPtr& getOptions() { return m_options; }
108 [[nodiscard]]
109 const OptionsPoolPtr& getOptions() const { return m_options; }
110
112 [[nodiscard]]
113 OthersPoolPtr& getOthers() { return m_others; }
115 [[nodiscard]]
116 const OthersPoolPtr& getOthers() const { return m_others; }
117
119 [[nodiscard]]
120 DetailsPoolPtr& getDetails() { return m_details; }
122 [[nodiscard]]
123 const DetailsPoolPtr& getDetails() const { return m_details; }
124
126 [[nodiscard]]
127 EntryPoolPtr& getEntries() { return m_entries; }
129 [[nodiscard]]
130 const EntryPoolPtr& getEntries() const { return m_entries; }
131
133 [[nodiscard]]
134 TextsPoolPtr& getTexts() { return m_texts; }
136 [[nodiscard]]
137 const TextsPoolPtr& getTexts() const { return m_texts; }
138
140 [[nodiscard]]
141 PartVoicingPolicy getPartVoicingPolicy() const { return m_partVoicingPolicy; }
142
145 [[nodiscard]]
146 constexpr Cmper calcScrollViewCmper([[maybe_unused]]Cmper partId) const noexcept
147 {
148 // as of now, there is no calculation, but keep that assumption encapsulated.
149 return BASE_SYSTEM_ID;
150 }
151
154 [[nodiscard]]
156
160 [[nodiscard]]
162
164 [[nodiscard]]
165 std::optional<KnownShapeDefType> getCachedShapeRecognition(Cmper shapeCmper) const;
166
168 void setCachedShapeRecognition(Cmper shapeCmper, KnownShapeDefType type) const;
169
173 [[nodiscard]]
175
179 [[nodiscard]]
181
183 [[nodiscard]]
184 int getMaxBlankPages() const { return m_maxBlankPages; }
185
187 [[nodiscard]]
188 const InstrumentMap& getInstruments() const { return m_instruments; }
189
192 [[nodiscard]]
193 const InstrumentInfo& getInstrumentForStaff(StaffCmper staffId) const;
194
208 [[nodiscard]]
209 InstrumentMap createInstrumentMap(Cmper forPartId) const;
210
213 [[nodiscard]]
214 bool calcHasVaryingSystemStaves(Cmper forPartId) const;
215
217 [[nodiscard]]
219
228 [[nodiscard]]
229 std::vector<MeasCmper> calcJumpFromMeasures(Cmper partId, MeasCmper currentMeasure) const;
230
235 bool iterateEntries(Cmper partId, std::function<bool(const EntryInfoPtr&)> iterator) const;
236
237private:
239 explicit Document() = default;
240
241 DocumentWeakPtr m_self;
242
243 HeaderPtr m_header;
244 OptionsPoolPtr m_options;
245 OthersPoolPtr m_others;
246 DetailsPoolPtr m_details;
247 EntryPoolPtr m_entries;
248 TextsPoolPtr m_texts;
249
250 int m_maxBlankPages{};
251
252 InstrumentMap m_instruments;
254
255 PartVoicingPolicy m_partVoicingPolicy{};
256
257 mutable std::unordered_map<Cmper, KnownShapeDefType> m_shapeRecognitionCache;
258
259 // Grant the factory class access to the private constructor
261};
262
263} // namespace dom
264} // namespace musx
Represents a document object that encapsulates the entire EnigmaXML structure.
Definition Document.h:94
bool iterateEntries(Cmper partId, std::function< bool(const EntryInfoPtr &)> iterator) const
Iterate all entries in the document by staff and then measure. This function wraps MusxInstanceList<o...
Definition Document.cpp:320
const TextsPoolPtr & getTexts() const
Retrieves the const texts pool.
Definition Document.h:137
OthersPoolPtr & getOthers()
Retrieves the others pool.
Definition Document.h:113
MusxInstance< others::Page > calcPageFromMeasure(Cmper partId, MeasCmper measureId) const
Searches pages to find the page that contains the measure.
Definition Document.cpp:68
std::optional< KnownShapeDefType > getCachedShapeRecognition(Cmper shapeCmper) const
Retrieves a cached shape recognition result, if available.
Definition Document.cpp:54
const HeaderPtr & getHeader() const
Retrieves the const header.
Definition Document.h:102
MusxInstance< others::StaffSystem > calcSystemFromMeasure(Cmper partId, MeasCmper measureId) const
Searches systems to find the page that contains the measure.
Definition Document.cpp:86
const InstrumentInfo & getInstrumentForStaff(StaffCmper staffId) const
Get the instrument info for the given staffId.
Definition Document.cpp:216
int getMaxBlankPages() const
Returns the maximum number of blank pages in any part. This is calculated by factory::DocumentFactory...
Definition Document.h:184
PartVoicingPolicy getPartVoicingPolicy() const
Retrieves the document's part voicing policy.
Definition Document.h:141
const InstrumentMap & getInstruments() const
Returns the instrument map for this document. It is computed by the factory.
Definition Document.h:188
MusxInstanceList< others::StaffUsed > getStudioViewStaves(Cmper partId) const
Returns the Studio View staves for the given partId. Normally this is only one staff and is invariant...
Definition Document.cpp:43
std::vector< MeasCmper > calcJumpFromMeasures(Cmper partId, MeasCmper currentMeasure) const
Calculates the measures from which playback jumped into currentMeasure.
Definition Document.cpp:250
constexpr Cmper calcScrollViewCmper(Cmper partId) const noexcept
Returns the Scroll View Cmper for the given partId.
Definition Document.h:146
const DetailsPoolPtr & getDetails() const
Retrieves the const others pool.
Definition Document.h:123
HeaderPtr & getHeader()
Retrieves the header.
Definition Document.h:99
MusxInstanceList< others::StaffUsed > getScrollViewStaves(Cmper partId) const
Returns the Scroll View staves for the given partId.
Definition Document.cpp:38
bool calcHasVaryingSystemStaves(Cmper forPartId) const
Calculate if the current score/part has staves that differ from system to system.
Definition Document.cpp:232
const OptionsPoolPtr & getOptions() const
Retrieves the const options pool.
Definition Document.h:109
TextsPoolPtr & getTexts()
Retrieves the texts pool.
Definition Document.h:134
void setCachedShapeRecognition(Cmper shapeCmper, KnownShapeDefType type) const
Stores a shape recognition result in the cache.
Definition Document.cpp:63
const OthersPoolPtr & getOthers() const
Retrieves the const others pool.
Definition Document.h:116
InstrumentMap createInstrumentMap(Cmper forPartId) const
Builds an instrument map for the specified linked part ID.
Definition Document.cpp:103
MusicRange calcEntireDocument() const
Calcuate a MusicRange instance for the entire document.
Definition Document.cpp:226
const EntryPoolPtr & getEntries() const
Retrieves the entry others pool.
Definition Document.h:130
DetailsPoolPtr & getDetails()
Retrieves the details pool.
Definition Document.h:120
OptionsPoolPtr & getOptions()
Retrieves the options pool.
Definition Document.h:106
EntryPoolPtr & getEntries()
Retrieves the entry pool.
Definition Document.h:127
Wraps a frame of shared_ptr<const EntryInfo> and an index for per entry access. This class manages ow...
Definition Entries.h:494
Utility class that represents of a range of musical time.
Definition CommonClasses.h:422
Provides optional per-type extension methods for MusxInstanceList.
Definition MusxInstance.h:103
Factory class for creating Document objects from XML.
Definition DocumentFactory.h:38
std::shared_ptr< Header > HeaderPtr
Shared Header pointer.
Definition Header.h:106
KnownShapeDefType
Enumerates the shape types we can recognize semantically.
Definition ShapeDesigner.h:39
std::shared_ptr< OthersPool > OthersPoolPtr
Shared OthersPool pointer.
Definition ObjectPool.h:500
int16_t MeasCmper
Enigma meas Cmper (may be negative when not applicable)
Definition Fundamentals.h:64
std::shared_ptr< const T > MusxInstance
Defines the type of a musx instance stored in a pool.
Definition MusxInstance.h:39
std::shared_ptr< DetailsPool > DetailsPoolPtr
Shared DetailsPool pointer.
Definition ObjectPool.h:587
uint16_t Cmper
Enigma "comperator" key type.
Definition Fundamentals.h:55
std::shared_ptr< TextsPool > TextsPoolPtr
Shared OthersPool pointer.
Definition ObjectPool.h:661
PartVoicingPolicy
Controls whether Finale-style part voicing is applied when iterating entries via musx::dom::details::...
Definition Document.h:77
std::shared_ptr< OptionsPool > OptionsPoolPtr
Shared OptionsPool pointer.
Definition ObjectPool.h:446
std::weak_ptr< Document > DocumentWeakPtr
Shared weak Document pointer.
Definition BaseClasses.h:57
constexpr Cmper BASE_SYSTEM_ID
Definition Fundamentals.h:89
int16_t StaffCmper
Enigma staff (staffId) Cmper (may be negative when not applicable)
Definition Fundamentals.h:65
std::shared_ptr< EntryPool > EntryPoolPtr
Shared EntryPool pointer.
Definition ObjectPool.h:622
std::unordered_map< StaffCmper, InstrumentInfo > InstrumentMap
Definition Document.h:53
object model for musx file (enigmaxml)
Definition BaseClasses.h:36
Represents information about each instrument in the document. This is calculated from the staves,...
Definition Document.h:58
std::vector< StaffCmper > getSequentialStaves() const
Returns the staffIds in sequence as they appear in Scroll View in the score.
Definition Document.cpp:333
Cmper multistaffGroupId
The others::MultiStaffInstrumentGroup that defines the instrument. (May be zero.)
Definition Document.h:61
static const InstrumentInfo * getInstrumentForStaff(const InstrumentMap &map, StaffCmper staffId)
Get the instrument info for the given staffId in the given map.
Definition Document.cpp:347
Cmper staffGroupId
The details::StaffGroup that visually represents the instrument. (May be zero.)
Definition Document.h:60
std::unordered_map< StaffCmper, size_t > staves
List of each staffId with its sequence index from top to bottom.
Definition Document.h:59