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
153 constexpr static std::string_view XmlNodeName = "verse";
155};
156
162{
163public:
164 using LyricsTextBase::LyricsTextBase;
165
166 constexpr static std::string_view XmlNodeName = "chorus";
168};
169
175{
176public:
177 using LyricsTextBase::LyricsTextBase;
178
179 constexpr static std::string_view XmlNodeName = "section";
181};
182
187class BlockText : public TextsBase
188{
189public:
191
195 constexpr static std::string_view XmlNodeName = "blockText";
196};
197
203{
204public:
206
210 constexpr static std::string_view XmlNodeName = "smartShapeText";
211};
212
218{
219public:
221
225 constexpr static std::string_view XmlNodeName = "expression";
226};
227
235{
236public:
238
242 constexpr static std::string_view XmlNodeName = "bookmarkText";
243};
244
245} // namespace texts
246} // namespace dom
247} // 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:586
Cmper getTextNumber() const
Returns the raw text number.
Definition BaseClasses.h:606
TextsBase(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper textNumber)
Constructs a TextsBase object.
Definition BaseClasses.h:598
Contains block text (Finale Text Tool, both page- and measure-attached)
Definition Texts.h:188
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:195
Contains bookmark description text.
Definition Texts.h:235
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:242
Contains text blocks associated with text expressions.
Definition Texts.h:218
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:225
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:162
static constexpr LyricTextType lyricTextType
Lyric text type for looking up word extensions.
Definition Texts.h:167
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:166
Contains section text for lyrics.
Definition Texts.h:175
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:179
static constexpr LyricTextType lyricTextType
Lyric text type for looking up word extensions.
Definition Texts.h:180
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:153
static constexpr LyricTextType lyricTextType
Lyric text type for looking up word extensions.
Definition Texts.h:154
Contains text blocks associated with custom line smart shapes.
Definition Texts.h:203
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:210
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
LyricTextType
The lyric text type if this is a lyrics smart shape.
Definition EnumClasses.h:77
@ Verse
The assignment is to a Verse lyrics text block.
@ Chorus
The assignment is to a Chorus lyrics text block.
@ Section
The assignment is to a Section lyrics text block.
std::shared_ptr< const T > MusxInstance
Defines the type of a musx instance stored in a pool.
Definition MusxInstance.h:39
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