MNX Document Model
Loading...
Searching...
No Matches
Global.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 "BaseTypes.h"
25#include "CommonClasses.h"
26
27namespace mnx {
28
33namespace global {
34
39class Barline : public Object
40{
41public:
43 Barline(const std::shared_ptr<json>& root, json_pointer pointer)
45 {
46 }
47
52 Barline(Base& parent, const std::string_view& key, BarlineType barlineType)
53 : Object(parent, key)
54 {
55 set_type(barlineType);
56 }
57
59};
60
65class Ending : public Object
66{
67public:
69 Ending(const std::shared_ptr<json>& root, json_pointer pointer)
71 {
72 }
73
78 Ending(Base& parent, const std::string_view& key, int duration)
79 : Object(parent, key)
80 {
81 set_duration(duration);
82 }
83
84 MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class");
85 MNX_OPTIONAL_PROPERTY(std::string, color);
86 MNX_REQUIRED_PROPERTY(int, duration);
89};
90
95class Fine : public Object
96{
97public:
99 Fine(const std::shared_ptr<json>& root, json_pointer pointer)
101 {
102 }
103
108 Fine(Base& parent, const std::string_view& key, const Fraction::Initializer& position)
109 : Object(parent, key)
110 {
111 create_location(position);
112 }
113
114 MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class");
115 MNX_OPTIONAL_PROPERTY(std::string, color);
117};
118
123class Jump : public Object
124{
125public:
127 Jump(const std::shared_ptr<json>& root, json_pointer pointer)
129 {
130 }
131
137 Jump(Base& parent, const std::string_view& key, JumpType jumpType, const Fraction::Initializer& position)
138 : Object(parent, key)
139 {
140 set_type(jumpType);
141 create_location(position);
142 }
143
146};
147
152class RepeatEnd : public Object
153{
154public:
155 using Object::Object;
156
158};
159
164class RepeatStart : public Object
165{
166public:
167 using Object::Object;
168
169};
170
175class Segno : public Object
176{
177public:
179 Segno(const std::shared_ptr<json>& root, json_pointer pointer)
181 {
182 }
183
188 Segno(Base& parent, const std::string_view& key, const Fraction::Initializer& position)
189 : Object(parent, key)
190 {
191 create_location(position);
192 }
193
194 MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class");
195 MNX_OPTIONAL_PROPERTY(std::string, color);
196 MNX_OPTIONAL_PROPERTY(std::string, glyph);
198};
199
205{
206public:
208 Tempo(const std::shared_ptr<json>& root, json_pointer pointer)
210 {
211 }
212
218 Tempo(Base& parent, const std::string_view& key, int bpm, const NoteValue::Initializer& noteValue)
220 {
221 set_bpm(bpm);
222 create_value(noteValue);
223 }
224
228};
229
260
266{
267public:
268 using ArrayElementObject::ArrayElementObject;
269
270 MNX_OPTIONAL_PROPERTY(std::string, label);
271 MNX_OPTIONAL_PROPERTY(std::string, lang);
272};
273
278class LyricsGlobal : public Object
279{
280public:
281 using Object::Object;
282
285};
286
292{
293public:
295 StyleGlobal(const std::shared_ptr<json>& root, json_pointer pointer)
297 {
298 }
299
304 StyleGlobal(Base& parent, const std::string_view& key, const std::string& selector)
306 {
307 set_selector(selector);
308 }
309
310 MNX_OPTIONAL_PROPERTY(std::string, color);
311 MNX_REQUIRED_PROPERTY(std::string, selector);
312};
313
314} // namespace global
315
320class Global : public Object
321{
322public:
323 using Object::Object;
324
328 Global(Base& parent, const std::string_view& key)
329 : Object(parent, key)
330 {
331 create_measures();
332 }
333
337};
338
339} // namespace mnx
Represents an MNX object that is included as an array element.
Definition BaseTypes.h:615
Represents an MNX array, encapsulating property access.
Definition BaseTypes.h:483
Base class wrapper for all MNX JSON nodes.
Definition BaseTypes.h:210
json_pointer pointer() const
Returns the json_pointer for this node.
Definition BaseTypes.h:271
T parent() const
Returns the parent object for this node.
Definition BaseTypes.h:258
const std::shared_ptr< json > & root() const
Returns the root.
Definition BaseTypes.h:288
Represents an MNX dictionary, where each key is a user-defined string.
Definition BaseTypes.h:769
std::pair< NumType, NumType > Initializer
initializer for Fraction class (numerator, denominator)
Definition CommonClasses.h:43
Represents the global section of an MNX document, containing global measures.
Definition Global.h:321
MNX_OPTIONAL_CHILD(global::LyricsGlobal, lyrics)
lyrics metadata
MNX_OPTIONAL_CHILD(Array< global::StyleGlobal >, styles)
array of styles
Global(Base &parent, const std::string_view &key)
Creates a new Global class as a child of a JSON element.
Definition Global.h:328
MNX_REQUIRED_CHILD(Array< global::Measure >, measures)
array of global measures.
Represents a key signature.
Definition CommonClasses.h:162
Definition CommonClasses.h:193
Represents a symbolic note value (not necessarily a duration)
Definition CommonClasses.h:190
Represents an MNX object, encapsulating property access.
Definition BaseTypes.h:420
Object(const std::shared_ptr< json > &root, json_pointer pointer)
Wraps an Object class around an existing JSON object node.
Definition BaseTypes.h:425
Represents a system on a page in a score.
Definition CommonClasses.h:105
Represents the tempo for a global measure.
Definition CommonClasses.h:261
Represents the barline for a global measure.
Definition Global.h:40
MNX_REQUIRED_PROPERTY(BarlineType, type)
the type of barline
Barline(Base &parent, const std::string_view &key, BarlineType barlineType)
Creates a new Barline class as a child of a JSON element.
Definition Global.h:52
Barline(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Barline objects.
Definition Global.h:43
Represents an alternate ending (or "volta bracket") for a global measure.
Definition Global.h:66
MNX_REQUIRED_PROPERTY(int, duration)
the type of barline
MNX_OPTIONAL_CHILD(Array< int >, numbers)
ending numbers
MNX_OPTIONAL_PROPERTY(std::string, color)
color to use when rendering the ending
MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class")
style class
Ending(Base &parent, const std::string_view &key, int duration)
Creates a new Ending class as a child of a JSON element.
Definition Global.h:78
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, open, false)
if this is an open (i.e., final) ending
Ending(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Ending objects.
Definition Global.h:69
Represents an Fine object (as in "D.S. al Fine")
Definition Global.h:96
MNX_OPTIONAL_PROPERTY(std::string, color)
color to use when rendering the fine direction
Fine(Base &parent, const std::string_view &key, const Fraction::Initializer &position)
Creates a new Fine class as a child of a JSON element.
Definition Global.h:108
Fine(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Fine objects.
Definition Global.h:99
MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class")
style class
MNX_REQUIRED_CHILD(RhythmicPosition, location)
the location of the fine direction
Represents an Jump object (as in "D.S.")
Definition Global.h:124
Jump(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Jump objects.
Definition Global.h:127
MNX_REQUIRED_CHILD(RhythmicPosition, location)
the location of the jump
Jump(Base &parent, const std::string_view &key, JumpType jumpType, const Fraction::Initializer &position)
Creates a new Jump class as a child of a JSON element.
Definition Global.h:137
MNX_REQUIRED_PROPERTY(JumpType, type)
the JumpType
Represents a single item of lyric metadata. The user-defined key is the lyric line ID.
Definition Global.h:266
MNX_OPTIONAL_PROPERTY(std::string, label)
Human readable lable for this lyric line. This could be used in a software UI, for example.
MNX_OPTIONAL_PROPERTY(std::string, lang)
RFC5646 language code identifying the language of this line of lyrics.
Metadata for lyrics in this MNX document.
Definition Global.h:279
MNX_OPTIONAL_CHILD(Array< std::string >, lineOrder)
Lyric line IDs used in the document (e.g. verse numbers)
MNX_OPTIONAL_CHILD(Dictionary< LyricLineMetadata >, lineMetadata)
Defines lyric line IDs and their metadata.
Represents a single global measure instance within an MNX document.
Definition Global.h:235
MNX_OPTIONAL_CHILD(Segno, segno)
if present, indicates that a segno marker is here
MNX_OPTIONAL_CHILD(Array< Tempo >, tempos)
the tempo changes within the measure, if any
MNX_OPTIONAL_PROPERTY(int, index)
the measure index which is used to refer to this measure by other classes in the MNX document
MNX_OPTIONAL_CHILD(Barline, barline)
optional barline for this measure
MNX_OPTIONAL_CHILD(RepeatStart, repeatStart)
if present, indicates that a repeated section starts here
MNX_OPTIONAL_PROPERTY(int, number)
visible measure number. Use calcMeasureIndex to get the default value.
MNX_OPTIONAL_CHILD(Jump, jump)
optional jump direction for this measure
MNX_OPTIONAL_CHILD(Ending, ending)
optional ending ("volta bracket") for this measure
MNX_OPTIONAL_CHILD(KeySignature, key)
optional key signature/key change for this measure
BarlineType calcBarlineType() const
Calculates the barline type for this measure.
Definition Implementations.cpp:155
int calcMeasureIndex() const
Calculates the measure index for this measure.
Definition Implementations.cpp:165
MNX_OPTIONAL_CHILD(Fine, fine)
optional fine direction for this measure
MNX_OPTIONAL_CHILD(RepeatEnd, repeatEnd)
if present, indicates that there is backwards repeat
MNX_OPTIONAL_CHILD(TimeSignature, time)
if present, indicates a meter change
Represents the end of a repeat in an MNX document.
Definition Global.h:153
MNX_OPTIONAL_PROPERTY(int, times)
number of times to repeat
Represents the start of a repeat in an MNX document.
Definition Global.h:165
Represents a segno marker.
Definition Global.h:176
Segno(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Segno objects.
Definition Global.h:179
Segno(Base &parent, const std::string_view &key, const Fraction::Initializer &position)
Creates a new Segno class as a child of a JSON element.
Definition Global.h:188
MNX_OPTIONAL_PROPERTY(std::string, glyph)
the SMuFL glyph name to be used when rendering this segno.
MNX_OPTIONAL_PROPERTY(std::string, color)
color to use when rendering the ending
MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class")
style class
MNX_REQUIRED_CHILD(RhythmicPosition, location)
location
Visual styling selectors for this MNX document.
Definition Global.h:292
StyleGlobal(Base &parent, const std::string_view &key, const std::string &selector)
Creates a new Jump class as a child of a JSON element.
Definition Global.h:304
MNX_OPTIONAL_PROPERTY(std::string, color)
the JumpType
MNX_REQUIRED_PROPERTY(std::string, selector)
the location of the jump
StyleGlobal(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing StyleGlobal objects.
Definition Global.h:295
Represents the tempo for a global measure.
Definition Global.h:205
Tempo(Base &parent, const std::string_view &key, int bpm, const NoteValue::Initializer &noteValue)
Creates a new Tempo class as a child of a JSON element.
Definition Global.h:218
MNX_REQUIRED_CHILD(NoteValue, value)
the note value for the tempo.
MNX_REQUIRED_PROPERTY(int, bpm)
the beats per minute of this tempo marking
Tempo(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Tempo instances.
Definition Global.h:208
MNX_OPTIONAL_CHILD(RhythmicPosition, location)
location within the measure of the tempo marking
object model for MNX format
JumpType
The types of jumps.
Definition Enumerations.h:105
json::json_pointer json_pointer
JSON pointer class for MNX.
Definition BaseTypes.h:197
BarlineType
The types of barlines supported.
Definition Enumerations.h:52