MUSX Document Model
Loading...
Searching...
No Matches
Texts.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 <string>
25#include <unordered_map>
26#include <vector>
27#include <memory>
28#include <stdexcept>
29
30#include "BaseClasses.h"
31#include "CommonClasses.h"
32#include "musx/util/EnigmaString.h"
33 // do not add other dom class dependencies. Use Implementations.h for implementations that need total class access.
34
35namespace musx {
36namespace dom {
37
42namespace texts {
43
50class FileInfoText : public TextsBase
51{
52public:
61 explicit FileInfoText(const DocumentWeakPtr& document, Cmper partId, ShareMode shareMode, Cmper textNumber)
62 : TextsBase(document, partId, shareMode, textNumber)
63 {
64 if (textNumber <= 0 || textNumber > Cmper(TextType::Subtitle)) {
65 throw std::invalid_argument("invalid text type value provided to FileInfoText constructor");
66 }
67 }
68
75 explicit FileInfoText(const DocumentWeakPtr& document, Cmper textNumber)
76 : TextsBase(document, 0, ShareMode::All, textNumber)
77 {
78 if (textNumber <= 0 || textNumber > Cmper(TextType::Subtitle)) {
79 throw std::invalid_argument("invalid text type value provided to FileInfoText constructor");
80 }
81 }
82
89 enum class TextType : Cmper
90 {
91 Title = 1,
92 Composer = 2,
93 Copyright = 3,
94 Description = 4,
95 Lyricist = 5,
96 Arranger = 6,
97 Subtitle = 7
98 };
99
104 {
105 const Cmper textNumber = getTextNumber();
106 MUSX_ASSERT_IF(textNumber <= 0 || textNumber > Cmper(TextType::Subtitle)) {
107 throw std::logic_error("File Info text found with invalid text number " + std::to_string(textNumber));
108 }
109 return TextType(textNumber);
110 }
111
115 constexpr static std::string_view XmlNodeName = "fileInfo";
116};
117
123{
124public:
126
127 std::vector<std::shared_ptr<const LyricsSyllableInfo>> syllables;
128
134 bool iterateStylesForSyllable(size_t syllableIndex, util::EnigmaString::TextChunkCallback callback) const;
135
138 void createSyllableInfo(const MusxInstance<TextsBase>& ptrToThis);
139
140private:
141 std::vector<util::EnigmaStyles> m_syllableStyles;
142};
143
149{
150public:
151 using LyricsTextBase::LyricsTextBase;
152
156 constexpr static std::string_view XmlNodeName = "verse";
157};
158
164{
165public:
166 using LyricsTextBase::LyricsTextBase;
167
171 constexpr static std::string_view XmlNodeName = "chorus";
172};
173
179{
180public:
181 using LyricsTextBase::LyricsTextBase;
182
186 constexpr static std::string_view XmlNodeName = "section";
187};
188
193class BlockText : public TextsBase
194{
195public:
197
201 constexpr static std::string_view XmlNodeName = "blockText";
202};
203
209{
210public:
212
216 constexpr static std::string_view XmlNodeName = "smartShapeText";
217};
218
224{
225public:
227
231 constexpr static std::string_view XmlNodeName = "expression";
232};
233
241{
242public:
244
248 constexpr static std::string_view XmlNodeName = "bookmarkText";
249};
250
251} // namespace texts
252} // namespace dom
253} // namespace musx
ShareMode
Describes how this instance is shared between part and score.
Definition BaseClasses.h:91
Base class for all text blocks.
Definition BaseClasses.h:557
Cmper getTextNumber() const
Returns the raw text number.
Definition BaseClasses.h:577
TextsBase(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper textNumber)
Constructs a TextsBase object.
Definition BaseClasses.h:569
Contains block text (Finale Text Tool, both page- and measure-attached)
Definition Texts.h:194
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:201
Contains bookmark description text.
Definition Texts.h:241
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:248
Contains text blocks associated with text expressions.
Definition Texts.h:224
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:231
Contains File Info text (from Finale's Score Manager)
Definition Texts.h:51
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:115
TextType
Represents various text types for the file header.
Definition Texts.h:90
@ Copyright
Copyright information for the piece.
@ Description
Description of the piece.
FileInfoText(const DocumentWeakPtr &document, Cmper textNumber)
Constructs a FileInfoText object.
Definition Texts.h:75
TextType getTextType() const
Returns the TextType of the current instance.
Definition Texts.h:103
FileInfoText(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper textNumber)
Constructs a FileInfoText object.
Definition Texts.h:61
Contains chorus text for lyrics.
Definition Texts.h:164
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:171
Contains section text for lyrics.
Definition Texts.h:179
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:186
Base class for lyrics text.
Definition Texts.h:123
std::vector< std::shared_ptr< const LyricsSyllableInfo > > syllables
the syllable info for the lyric text, constructed by the factory
Definition Texts.h:127
bool iterateStylesForSyllable(size_t syllableIndex, util::EnigmaString::TextChunkCallback callback) const
Parse a given syllable into chunks with EnigmaStyles for that chunk. In the most common case,...
Definition Texts.cpp:116
void createSyllableInfo(const MusxInstance< TextsBase > &ptrToThis)
Creates the syllables array. Used by the factory but available at any time.
Definition Texts.cpp:48
Contains verse text for lyrics.
Definition Texts.h:149
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:156
Contains text blocks associated with custom line smart shapes.
Definition Texts.h:209
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:216
std::function< bool(const std::string &text, const EnigmaStyles &styles)> TextChunkCallback
Iteration function type that the parser calls back when the font has changed or when recursively pars...
Definition EnigmaString.h:331
std::shared_ptr< const T > MusxInstance
Defines the type of a musx instance stored in a pool.
Definition MusxInstance.h:35
uint16_t Cmper
Enigma "comperator" key type.
Definition Fundamentals.h:55
std::weak_ptr< Document > DocumentWeakPtr
Shared weak Document pointer.
Definition BaseClasses.h:57
object model for musx file (enigmaxml)
Definition BaseClasses.h:36