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:
207 using ArrayElementObject::ArrayElementObject;
208
209 MNX_OPTIONAL_PROPERTY(unsigned, midiNumber);
210 MNX_OPTIONAL_PROPERTY(std::string, name);
211};
212
218{
219public:
221 Tempo(const std::shared_ptr<json>& root, json_pointer pointer)
223 {
224 }
225
231 Tempo(Base& parent, const std::string_view& key, int bpm, const NoteValue::Initializer& noteValue)
233 {
234 set_bpm(bpm);
235 create_value(noteValue);
236 }
237
241};
242
273
279{
280public:
281 using ArrayElementObject::ArrayElementObject;
282
283 MNX_OPTIONAL_PROPERTY(std::string, label);
284 MNX_OPTIONAL_PROPERTY(std::string, lang);
285};
286
291class LyricsGlobal : public Object
292{
293public:
294 using Object::Object;
295
298};
299
305{
306public:
308 StyleGlobal(const std::shared_ptr<json>& root, json_pointer pointer)
310 {
311 }
312
317 StyleGlobal(Base& parent, const std::string_view& key, const std::string& selector)
319 {
320 set_selector(selector);
321 }
322
323 MNX_OPTIONAL_PROPERTY(std::string, color);
324 MNX_REQUIRED_PROPERTY(std::string, selector);
325};
326
327} // namespace global
328
333class Global : public Object
334{
335public:
336 using Object::Object;
337
341 Global(Base& parent, const std::string_view& key)
342 : Object(parent, key)
343 {
344 create_measures();
345 }
346
351};
352
353} // namespace mnx
Represents an MNX object that is included as an array element.
Definition BaseTypes.h:619
Represents an MNX array, encapsulating property access.
Definition BaseTypes.h:487
Base class wrapper for all MNX JSON nodes.
Definition BaseTypes.h:211
json_pointer pointer() const
Returns the json_pointer for this node.
Definition BaseTypes.h:272
T parent() const
Returns the parent object for this node.
Definition BaseTypes.h:259
const std::shared_ptr< json > & root() const
Returns the root.
Definition BaseTypes.h:289
Represents an MNX dictionary, where each key is a user-defined string.
Definition BaseTypes.h:773
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:334
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:341
MNX_REQUIRED_CHILD(Array< global::Measure >, measures)
array of global measures.
MNX_OPTIONAL_CHILD(Dictionary< global::Sound >, sounds)
dictionary of sounds with user-defined keys
Represents a key signature.
Definition CommonClasses.h:191
initializer class for NoteValue
Definition CommonClasses.h:223
Represents a symbolic note value (not necessarily a duration)
Definition CommonClasses.h:219
Represents an MNX object, encapsulating property access.
Definition BaseTypes.h:421
Object(const std::shared_ptr< json > &root, json_pointer pointer)
Wraps an Object class around an existing JSON object node.
Definition BaseTypes.h:426
Represents a system on a page in a score.
Definition CommonClasses.h:105
Represents the tempo for a global measure.
Definition CommonClasses.h:292
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:279
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:292
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:248
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:164
int calcMeasureIndex() const
Calculates the measure index for this measure.
Definition Implementations.cpp:174
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
Represents a sound definition.
Definition Global.h:205
MNX_OPTIONAL_PROPERTY(unsigned, midiNumber)
MIDI pitch of the sound from 0-127, where middle C is 60.
MNX_OPTIONAL_PROPERTY(std::string, name)
The name of the sound (presentable to the user)
Visual styling selectors for this MNX document.
Definition Global.h:305
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:317
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:308
Represents the tempo for a global measure.
Definition Global.h:218
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:231
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:221
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:198
BarlineType
The types of barlines supported.
Definition Enumerations.h:52