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, 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, std::string_view key, int duration)
79 : Object(parent, key)
80 {
81 set_duration(duration);
82 }
83
84 MNX_OPTIONAL_PROPERTY(std::string, color);
85 MNX_REQUIRED_PROPERTY(int, duration);
88};
89
94class Fine : public Object
95{
96public:
98 Fine(const std::shared_ptr<json>& root, json_pointer pointer)
100 {
101 }
102
107 Fine(Base& parent, std::string_view key, const FractionValue& position)
108 : Object(parent, key)
109 {
110 create_location(position);
111 }
112
113 MNX_OPTIONAL_PROPERTY(std::string, color);
115};
116
121class Jump : public Object
122{
123public:
125 Jump(const std::shared_ptr<json>& root, json_pointer pointer)
127 {
128 }
129
135 Jump(Base& parent, std::string_view key, JumpType jumpType, const FractionValue& position)
136 : Object(parent, key)
137 {
138 set_type(jumpType);
139 create_location(position);
140 }
141
144};
145
150class RepeatEnd : public Object
151{
152public:
153 using Object::Object;
154
156};
157
162class RepeatStart : public Object
163{
164public:
165 using Object::Object;
166
167};
168
173class Segno : public Object
174{
175public:
177 Segno(const std::shared_ptr<json>& root, json_pointer pointer)
179 {
180 }
181
186 Segno(Base& parent, std::string_view key, const FractionValue& position)
187 : Object(parent, key)
188 {
189 create_location(position);
190 }
191
192 MNX_OPTIONAL_PROPERTY(std::string, color);
193 MNX_OPTIONAL_PROPERTY(std::string, glyph);
195};
196
202{
203public:
204 using ArrayElementObject::ArrayElementObject;
205
206 MNX_OPTIONAL_PROPERTY(unsigned, midiNumber);
207 MNX_OPTIONAL_PROPERTY(std::string, name);
208};
209
215{
216public:
218 Tempo(const std::shared_ptr<json>& root, json_pointer pointer)
220 {
221 }
222
228 Tempo(Base& parent, std::string_view key, int bpm, const NoteValue::Initializer& noteValue)
230 {
231 set_bpm(bpm);
232 create_value(noteValue);
233 }
234
238};
239
245{
246public:
247 using ArrayElementObject::ArrayElementObject;
248
261
264 [[nodiscard]] BarlineType calcBarlineType() const;
265
268 [[nodiscard]] int calcMeasureIndex() const;
269
272 [[nodiscard]] std::optional<TimeSignature> calcCurrentTime() const;
273
274 inline static constexpr std::string_view JsonSchemaTypeName = "measure-global";
275};
276
282{
283public:
284 using ArrayElementObject::ArrayElementObject;
285
286 MNX_OPTIONAL_PROPERTY(std::string, label);
287 MNX_OPTIONAL_PROPERTY(std::string, lang);
288};
289
294class LyricsGlobal : public Object
295{
296public:
297 using Object::Object;
298
301};
302
308{
309public:
311 StyleGlobal(const std::shared_ptr<json>& root, json_pointer pointer)
313 {
314 }
315
320 StyleGlobal(Base& parent, std::string_view key, const std::string& selector)
322 {
323 set_selector(selector);
324 }
325
326 MNX_OPTIONAL_PROPERTY(std::string, color);
327 MNX_REQUIRED_PROPERTY(std::string, selector);
328};
329
330} // namespace global
331
336class Global : public Object
337{
338public:
339 using Object::Object;
340
344 Global(Base& parent, std::string_view key)
345 : Object(parent, key)
346 {
347 create_measures();
348 }
349
354};
355
356} // namespace mnx
Represents an MNX object that is included as an array element.
Definition BaseTypes.h:631
Represents an MNX array, encapsulating property access.
Definition BaseTypes.h:493
Base class wrapper for all MNX JSON nodes.
Definition BaseTypes.h:212
json_pointer pointer() const
Returns the json_pointer for this node.
Definition BaseTypes.h:274
T parent() const
Returns the parent object for this node.
Definition BaseTypes.h:260
const std::shared_ptr< json > & root() const
Returns the root.
Definition BaseTypes.h:294
Represents an MNX dictionary, where each key is a user-defined string.
Definition BaseTypes.h:785
Represents the global section of an MNX document, containing global measures.
Definition Global.h:337
MNX_OPTIONAL_CHILD(global::LyricsGlobal, lyrics)
lyrics metadata
MNX_OPTIONAL_CHILD(Array< global::StyleGlobal >, styles)
array of styles
Global(Base &parent, std::string_view key)
Creates a new Global class as a child of a JSON element.
Definition Global.h:344
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:503
initializer class for NoteValue
Definition CommonClasses.h:534
Represents a symbolic note value (not necessarily a duration)
Definition CommonClasses.h:530
Represents an MNX object, encapsulating property access.
Definition BaseTypes.h:426
Object(const std::shared_ptr< json > &root, json_pointer pointer)
Wraps an Object class around an existing JSON object node.
Definition BaseTypes.h:431
Represents a system on a page in a score.
Definition CommonClasses.h:417
Represents the tempo for a global measure.
Definition CommonClasses.h:611
Represents the barline for a global measure.
Definition Global.h:40
Barline(Base &parent, std::string_view key, BarlineType barlineType)
Creates a new Barline class as a child of a JSON element.
Definition Global.h:52
MNX_REQUIRED_PROPERTY(BarlineType, type)
the type of barline
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
Ending(Base &parent, 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:95
MNX_OPTIONAL_PROPERTY(std::string, color)
color to use when rendering the fine direction
Fine(Base &parent, std::string_view key, const FractionValue &position)
Creates a new Fine class as a child of a JSON element.
Definition Global.h:107
Fine(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Fine objects.
Definition Global.h:98
MNX_REQUIRED_CHILD(RhythmicPosition, location)
the location of the fine direction
Represents an Jump object (as in "D.S.")
Definition Global.h:122
Jump(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Jump objects.
Definition Global.h:125
Jump(Base &parent, std::string_view key, JumpType jumpType, const FractionValue &position)
Creates a new Jump class as a child of a JSON element.
Definition Global.h:135
MNX_REQUIRED_CHILD(RhythmicPosition, location)
the location of the jump
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:282
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:295
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:245
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
std::optional< TimeSignature > calcCurrentTime() const
Calculates the current time signature by searching backwards.
Definition Implementations.cpp:286
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:263
int calcMeasureIndex() const
Calculates the measure index for this measure.
Definition Implementations.cpp:273
MNX_OPTIONAL_CHILD(Fine, fine)
optional fine direction for this measure
MNX_OPTIONAL_CHILD(RepeatEnd, repeatEnd)
if present, indicates that there is backwards repeat
static constexpr std::string_view JsonSchemaTypeName
required for mapping
Definition Global.h:274
MNX_OPTIONAL_CHILD(TimeSignature, time)
if present, indicates a meter change
Represents the end of a repeat in an MNX document.
Definition Global.h:151
MNX_OPTIONAL_PROPERTY(int, times)
number of times to repeat
Represents the start of a repeat in an MNX document.
Definition Global.h:163
Represents a segno marker.
Definition Global.h:174
Segno(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Segno objects.
Definition Global.h:177
MNX_OPTIONAL_PROPERTY(std::string, glyph)
the SMuFL glyph name to be used when rendering this segno.
Segno(Base &parent, std::string_view key, const FractionValue &position)
Creates a new Segno class as a child of a JSON element.
Definition Global.h:186
MNX_OPTIONAL_PROPERTY(std::string, color)
color to use when rendering the ending
MNX_REQUIRED_CHILD(RhythmicPosition, location)
location
Represents a sound definition.
Definition Global.h:202
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:308
StyleGlobal(Base &parent, std::string_view key, const std::string &selector)
Creates a new Jump class as a child of a JSON element.
Definition Global.h:320
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:311
Represents the tempo for a global measure.
Definition Global.h:215
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:218
MNX_OPTIONAL_CHILD(RhythmicPosition, location)
location within the measure of the tempo marking
Tempo(Base &parent, 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:228
object model for MNX format
JumpType
The types of jumps.
Definition Enumerations.h:116
json::json_pointer json_pointer
JSON pointer class for MNX.
Definition BaseTypes.h:198
BarlineType
The types of barlines supported.
Definition Enumerations.h:52
Represents a detached arithmetic fraction with normalization.
Definition CommonClasses.h:59