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 <unordered_map>
26#include <vector>
27
28#include "Header.h"
29#include "ObjectPool.h"
30#include "MusxInstance.h"
31
36namespace musx {
37
38namespace factory {
39class DocumentFactory;
40} // namespace factory
41
46namespace dom {
47
48using namespace header;
49
54{
55 std::unordered_map<StaffCmper, size_t> staves;
58
60 std::vector<StaffCmper> getSequentialStaves() const;
61};
62using InstrumentMap = std::unordered_map<StaffCmper, InstrumentInfo>;
63
68{
69public:
71 HeaderPtr& getHeader() { return m_header; }
73 const HeaderPtr& getHeader() const { return m_header; }
74
76 OptionsPoolPtr& getOptions() { return m_options; }
78 const OptionsPoolPtr& getOptions() const { return m_options; }
79
81 OthersPoolPtr& getOthers() { return m_others; }
83 const OthersPoolPtr& getOthers() const { return m_others; }
84
86 DetailsPoolPtr& getDetails() { return m_details; }
88 const DetailsPoolPtr& getDetails() const { return m_details; }
89
91 EntryPoolPtr& getEntries() { return m_entries; }
93 const EntryPoolPtr& getEntries() const { return m_entries; }
94
96 TextsPoolPtr& getTexts() { return m_texts; }
98 const TextsPoolPtr& getTexts() const { return m_texts; }
99
102 [[nodiscard]]
103 constexpr Cmper calcScrollViewCmper([[maybe_unused]]Cmper partId) const noexcept
104 {
105 // as of now, there is no calculation, but keep that assumption encapsulated.
106 return BASE_SYSTEM_ID;
107 }
108
112
117
122
124 int getMaxBlankPages() const { return m_maxBlankPages; }
125
127 const InstrumentMap& getInstruments() const { return m_instruments; }
128
131 const InstrumentInfo& getInstrumentForStaff(StaffCmper staffId) const;
132
146 InstrumentMap createInstrumentMap(Cmper forPartId) const;
147
150 bool calcHasVaryingSystemStaves(Cmper forPartId) const;
151
154
159 bool iterateEntries(Cmper partId, std::function<bool(const EntryInfoPtr&)> iterator) const;
160
161private:
163 explicit Document() = default;
164
165 DocumentWeakPtr m_self;
166
167 HeaderPtr m_header;
168 OptionsPoolPtr m_options;
169 OthersPoolPtr m_others;
170 DetailsPoolPtr m_details;
171 EntryPoolPtr m_entries;
172 TextsPoolPtr m_texts;
173
174 int m_maxBlankPages{};
175
176 InstrumentMap m_instruments;
178
179 // Grant the factory class access to the private constructor
181};
182
183} // namespace dom
184} // namespace musx
Represents a document object that encapsulates the entire EnigmaXML structure.
Definition Document.h:68
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:228
const TextsPoolPtr & getTexts() const
Retrieves the const texts pool.
Definition Document.h:98
OthersPoolPtr & getOthers()
Retrieves the others pool.
Definition Document.h:81
const HeaderPtr & getHeader() const
Retrieves the const header.
Definition Document.h:73
MusxInstance< others::Page > calculatePageFromMeasure(Cmper partId, MeasCmper measureId) const
Searches pages to find the page that contains the measure.
Definition Document.cpp:41
const InstrumentInfo & getInstrumentForStaff(StaffCmper staffId) const
Get the instrument info for the given staffId.
Definition Document.cpp:188
int getMaxBlankPages() const
Returns the maximum number of blank pages in any part. This is calculated by factory::DocumentFactory...
Definition Document.h:124
const InstrumentMap & getInstruments() const
Returns the instrument map for this document. It is computed by the factory.
Definition Document.h:127
MusxInstance< others::StaffSystem > calculateSystemFromMeasure(Cmper partId, MeasCmper measureId) const
Searches systems to find the page that contains the measure.
Definition Document.cpp:59
constexpr Cmper calcScrollViewCmper(Cmper partId) const noexcept
Returns the Scroll View Cmper for the given partId.
Definition Document.h:103
const DetailsPoolPtr & getDetails() const
Retrieves the const others pool.
Definition Document.h:88
HeaderPtr & getHeader()
Retrieves the header.
Definition Document.h:71
MusxInstanceList< others::StaffUsed > getScrollViewStaves(Cmper partId) const
Returns the scroll view staves for the given partId.
Definition Document.cpp:36
bool calcHasVaryingSystemStaves(Cmper forPartId) const
Calculate if the current score/part has staves that differ from system to system.
Definition Document.cpp:210
const OptionsPoolPtr & getOptions() const
Retrieves the const options pool.
Definition Document.h:78
TextsPoolPtr & getTexts()
Retrieves the texts pool.
Definition Document.h:96
const OthersPoolPtr & getOthers() const
Retrieves the const others pool.
Definition Document.h:83
InstrumentMap createInstrumentMap(Cmper forPartId) const
Builds an instrument map for the specified linked part ID.
Definition Document.cpp:76
MusicRange calcEntireDocument() const
Calcuate a MusicRange instance for the entire document.
Definition Document.cpp:204
const EntryPoolPtr & getEntries() const
Retrieves the entry others pool.
Definition Document.h:93
DetailsPoolPtr & getDetails()
Retrieves the details pool.
Definition Document.h:86
OptionsPoolPtr & getOptions()
Retrieves the options pool.
Definition Document.h:76
EntryPoolPtr & getEntries()
Retrieves the entry pool.
Definition Document.h:91
Wraps a frame of shared_ptr<const EntryInfo> and an index for per entry access. This class manages ow...
Definition Entries.h:417
Utility class that represents of a range of musical time.
Definition CommonClasses.h:474
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
std::shared_ptr< OthersPool > OthersPoolPtr
Shared OthersPool pointer.
Definition ObjectPool.h:447
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:534
uint16_t Cmper
Enigma "comperator" key type.
Definition Fundamentals.h:55
std::shared_ptr< TextsPool > TextsPoolPtr
Shared OthersPool pointer.
Definition ObjectPool.h:608
std::shared_ptr< OptionsPool > OptionsPoolPtr
Shared OptionsPool pointer.
Definition ObjectPool.h:393
std::weak_ptr< Document > DocumentWeakPtr
Shared weak Document pointer.
Definition BaseClasses.h:57
constexpr Cmper BASE_SYSTEM_ID
Definition Fundamentals.h:80
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:569
std::unordered_map< StaffCmper, InstrumentInfo > InstrumentMap
A list of instruments, which may be single- or multi-staff.
Definition Document.h:62
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:54
std::vector< StaffCmper > getSequentialStaves() const
Returns the staffIds in sequence as they appear in Scroll View in the score.
Definition Document.cpp:241
Cmper multistaffGroupId
The others::MultiStaffInstrumentGroup that defines the instrument. (May be zero.)
Definition Document.h:57
Cmper staffGroupId
The details::StaffGroup that visually represents the instrument. (May be zero.)
Definition Document.h:56
std::unordered_map< StaffCmper, size_t > staves
List of each staffId with its sequence index from top to bottom.
Definition Document.h:55