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 struct Required
44 {
46 };
47
49 Barline(const std::shared_ptr<json>& root, json_pointer pointer)
51 {
52 }
53
58 Barline(Base& parent, std::string_view key, BarlineType barlineType)
59 : Object(parent, key)
60 {
61 set_type(barlineType);
62 }
63
65 operator Required() const { return { type() }; }
66
68 static Required make(BarlineType barlineType) { return { barlineType }; }
69
71};
72
77class Ending : public Object
78{
79public:
81 struct Required
82 {
83 int duration{};
84 };
85
87 Ending(const std::shared_ptr<json>& root, json_pointer pointer)
89 {
90 }
91
96 Ending(Base& parent, std::string_view key, int duration)
97 : Object(parent, key)
98 {
99 set_duration(duration);
100 }
101
103 operator Required() const { return { duration() }; }
104
106 static Required make(int duration) { return { duration }; }
107
108 MNX_OPTIONAL_PROPERTY(std::string, color);
109 MNX_REQUIRED_PROPERTY(int, duration);
112};
113
118class Fine : public Object
119{
120public:
122 struct Required
123 {
125 };
126
128 Fine(const std::shared_ptr<json>& root, json_pointer pointer)
130 {
131 }
132
137 Fine(Base& parent, std::string_view key, const FractionValue& position)
138 : Object(parent, key)
139 {
140 create_location(position);
141 }
142
144 operator Required() const { return { location().fraction() }; }
145
147 static Required make(const FractionValue& position) { return { position }; }
148
149 MNX_OPTIONAL_PROPERTY(std::string, color);
151 (const FractionValue&, position));
152};
153
158class Jump : public Object
159{
160public:
167
169 Jump(const std::shared_ptr<json>& root, json_pointer pointer)
171 {
172 }
173
179 Jump(Base& parent, std::string_view key, JumpType jumpType, const FractionValue& position)
180 : Object(parent, key)
181 {
182 set_type(jumpType);
183 create_location(position);
184 }
185
187 operator Required() const { return { type(), location().fraction() }; }
188
190 static Required make(JumpType jumpType, const FractionValue& position) { return { jumpType, position }; }
191
194 (const FractionValue&, position));
195};
196
201class RepeatEnd : public Object
202{
203public:
204 using Object::Object;
205
207};
208
213class RepeatStart : public Object
214{
215public:
216 using Object::Object;
217
218};
219
224class Segno : public Object
225{
226public:
228 struct Required
229 {
231 };
232
234 Segno(const std::shared_ptr<json>& root, json_pointer pointer)
236 {
237 }
238
243 Segno(Base& parent, std::string_view key, const FractionValue& position)
244 : Object(parent, key)
245 {
246 create_location(position);
247 }
248
250 operator Required() const { return { location().fraction() }; }
251
253 static Required make(const FractionValue& position) { return { position }; }
254
255 MNX_OPTIONAL_PROPERTY(std::string, color);
256 MNX_OPTIONAL_PROPERTY(std::string, glyph);
258 (const FractionValue&, position));
259};
260
266{
267public:
268 using ArrayElementObject::ArrayElementObject;
269
270 MNX_OPTIONAL_PROPERTY(unsigned, midiNumber);
271 MNX_OPTIONAL_PROPERTY(std::string, name);
272};
273
279{
280public:
282 struct Required
283 {
284 int bpm{};
286 };
287
289 Tempo(const std::shared_ptr<json>& root, json_pointer pointer)
291 {
292 }
293
299 Tempo(Base& parent, std::string_view key, int bpm, const NoteValue::Required& noteValue)
301 {
302 set_bpm(bpm);
303 create_value(noteValue.base, noteValue.dots);
304 }
305
307 operator Required() const { return { bpm(), value() }; }
308
310 static Required make(int bpm, const NoteValue::Required& noteValue) { return { bpm, noteValue }; }
311
314 (const FractionValue&, position));
316 (NoteValueBase, base), (unsigned, dots));
317};
318
324{
325public:
326 using ArrayElementObject::ArrayElementObject;
327
329 (BarlineType, barlineType));
331 (int, duration));
333 (const FractionValue&, position));
335 (JumpType, jumpType), (const FractionValue&, position));
337 (int, fifths));
343 (const FractionValue&, position));
346 (int, count), (TimeSignatureUnit, unit));
347
350 [[nodiscard]] BarlineType calcBarlineType() const;
351
354 [[nodiscard]] int calcVisibleNumber() const;
355
358 [[nodiscard]] std::optional<TimeSignature> calcCurrentTime() const;
359
362 [[nodiscard]] std::optional<KeySignature> calcCurrentKey() const;
363
366 [[nodiscard]] KeySignature::Required calcCurrentKeyFields() const;
367
368 inline static constexpr std::string_view JsonSchemaTypeName = "measure-global";
369};
370
376{
377public:
378 using ArrayElementObject::ArrayElementObject;
379
380 MNX_OPTIONAL_PROPERTY(std::string, label);
381 MNX_OPTIONAL_PROPERTY(std::string, lang);
382};
383
388class LyricsGlobal : public Object
389{
390public:
391 using Object::Object;
392
395};
396
397} // namespace global
398
403class Global : public Object
404{
405public:
406 using Object::Object;
407
411 Global(Base& parent, std::string_view key)
412 : Object(parent, key)
413 {
414 create_measures();
415 }
416
420};
421
422} // namespace mnx
Represents an MNX object that is included as an array element.
Definition BaseTypes.h:664
Represents an MNX array, encapsulating property access.
Definition BaseTypes.h:499
Base class wrapper for all MNX JSON nodes.
Definition BaseTypes.h:198
json_pointer pointer() const
Returns the json_pointer for this node.
Definition BaseTypes.h:260
T parent() const
Returns the parent object for this node.
Definition BaseTypes.h:246
const std::shared_ptr< json > & root() const
Returns the root.
Definition BaseTypes.h:280
Represents an MNX dictionary, where each key is a user-defined string.
Definition BaseTypes.h:856
Represents the global section of an MNX document, containing global measures.
Definition Global.h:404
MNX_OPTIONAL_CHILD(global::LyricsGlobal, lyrics)
lyrics metadata
Global(Base &parent, std::string_view key)
Creates a new Global class as a child of a JSON element.
Definition Global.h:411
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:560
Represents a symbolic note value (not necessarily a duration)
Definition CommonClasses.h:599
Represents an MNX object, encapsulating property access.
Definition BaseTypes.h:412
Object(const std::shared_ptr< json > &root, json_pointer pointer)
Wraps an Object class around an existing JSON object node.
Definition BaseTypes.h:417
Represents a system on a page in a score.
Definition CommonClasses.h:432
Represents the tempo for a global measure.
Definition CommonClasses.h:696
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:58
MNX_REQUIRED_PROPERTY(BarlineType, type)
the type of barline
static Required make(BarlineType barlineType)
Create a Required instance for Barline.
Definition Global.h:68
Barline(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Barline objects.
Definition Global.h:49
Represents an alternate ending (or "volta bracket") for a global measure.
Definition Global.h:78
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:96
static Required make(int duration)
Create a Required instance for Ending.
Definition Global.h:106
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:87
Represents an Fine object (as in "D.S. al Fine")
Definition Global.h:119
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:137
static Required make(const FractionValue &position)
Create a Required instance for Fine.
Definition Global.h:147
MNX_REQUIRED_CHILD(RhythmicPosition, location,(const FractionValue &, position))
the location of the fine direction
Fine(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Fine objects.
Definition Global.h:128
Represents an Jump object (as in "D.S.")
Definition Global.h:159
static Required make(JumpType jumpType, const FractionValue &position)
Create a Required instance for Jump.
Definition Global.h:190
Jump(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Jump objects.
Definition Global.h:169
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:179
MNX_REQUIRED_PROPERTY(JumpType, type)
the JumpType
MNX_REQUIRED_CHILD(RhythmicPosition, location,(const FractionValue &, position))
the location of the jump
Represents a single item of lyric metadata. The user-defined key is the lyric line ID.
Definition Global.h:376
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:389
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:324
MNX_OPTIONAL_CHILD(Array< Tempo >, tempos)
the tempo changes within the measure, if any
MNX_OPTIONAL_CHILD(KeySignature, key,(int, fifths))
optional key signature/key change for this measure
std::optional< TimeSignature > calcCurrentTime() const
Calculates the current time signature by searching backwards.
Definition Implementations.cpp:555
MNX_OPTIONAL_CHILD(Segno, segno,(const FractionValue &, position))
if present, indicates that a segno marker is here
KeySignature::Required calcCurrentKeyFields() const
Get the fields of the current key signature.
Definition Implementations.cpp:583
MNX_OPTIONAL_CHILD(RepeatStart, repeatStart)
if present, indicates that a repeated section starts here
int calcVisibleNumber() const
Calculates the visible measure number for this measure.
Definition Implementations.cpp:550
MNX_OPTIONAL_CHILD(Fine, fine,(const FractionValue &, position))
optional fine direction for this measure
MNX_OPTIONAL_PROPERTY(int, number)
MNX_OPTIONAL_CHILD(Barline, barline,(BarlineType, barlineType))
optional barline for this measure
MNX_OPTIONAL_CHILD(TimeSignature, time,(int, count),(TimeSignatureUnit, unit))
if present, indicates a meter change
std::optional< KeySignature > calcCurrentKey() const
Calculates the current key signature by searching backwards.
Definition Implementations.cpp:569
BarlineType calcBarlineType() const
Calculates the barline type for this measure.
Definition Implementations.cpp:540
MNX_OPTIONAL_CHILD(Jump, jump,(JumpType, jumpType),(const FractionValue &, position))
optional jump 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:368
MNX_OPTIONAL_CHILD(Ending, ending,(int, duration))
optional ending ("volta bracket") for this measure
Represents the end of a repeat in an MNX document.
Definition Global.h:202
MNX_OPTIONAL_PROPERTY(int, times)
number of times to repeat
Represents the start of a repeat in an MNX document.
Definition Global.h:214
Represents a segno marker.
Definition Global.h:225
Segno(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Segno objects.
Definition Global.h:234
static Required make(const FractionValue &position)
Create a Required instance for Segno.
Definition Global.h:253
MNX_REQUIRED_CHILD(RhythmicPosition, location,(const FractionValue &, position))
location
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:243
MNX_OPTIONAL_PROPERTY(std::string, color)
color to use when rendering the ending
Represents a sound definition.
Definition Global.h:266
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)
Represents the tempo for a global measure.
Definition Global.h:279
MNX_REQUIRED_CHILD(NoteValue, value,(NoteValueBase, base),(unsigned, dots))
the note value for the tempo.
static Required make(int bpm, const NoteValue::Required &noteValue)
Create a Required instance for Tempo.
Definition Global.h:310
MNX_OPTIONAL_CHILD(RhythmicPosition, location,(const FractionValue &, position))
location within the measure of the tempo marking
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:289
Tempo(Base &parent, std::string_view key, int bpm, const NoteValue::Required &noteValue)
Creates a new Tempo class as a child of a JSON element.
Definition Global.h:299
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:68
TimeSignatureUnit
Valid units for the lower numbers of time signatures.
Definition Enumerations.h:317
BarlineType
The types of barlines supported.
Definition Enumerations.h:52
NoteValueBase
The note values allowed in MNX.
Definition Enumerations.h:198
Represents a detached arithmetic fraction with normalization.
Definition CommonClasses.h:59
initializer class for KeySignature
Definition CommonClasses.h:564
initializer class for NoteValue
Definition CommonClasses.h:603
NoteValueBase base
the note value base to initialize
Definition CommonClasses.h:604
unsigned dots
the number of dots to initialize
Definition CommonClasses.h:605
initializer class for Barline
Definition Global.h:44
BarlineType barlineType
the barline type for this Barline
Definition Global.h:45
initializer class for Ending
Definition Global.h:82
int duration
the duration of the ending
Definition Global.h:83
initializer class for Fine
Definition Global.h:123
FractionValue position
the position of the Fine within the measure
Definition Global.h:124
initializer class for Jump
Definition Global.h:163
FractionValue position
the position within the measure
Definition Global.h:165
JumpType jumpType
the jump type
Definition Global.h:164
initializer class for Segno
Definition Global.h:229
FractionValue position
the position of the Segno within the measure
Definition Global.h:230
initializer class for Tempo
Definition Global.h:283
int bpm
the beats per minute
Definition Global.h:284
NoteValue::Required noteValue
the note value for the tempo
Definition Global.h:285