MNX Document Model
Loading...
Searching...
No Matches
Score.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 score {
34
40{
41public:
43 struct Required
44 {
45 std::string startMeasure{};
47 };
48
50 MultimeasureRest(const std::shared_ptr<json>& root, json_pointer pointer)
52 {
53 }
54
60 MultimeasureRest(Base& parent, std::string_view key, const std::string& startMeasure, int numMeasures)
62 {
63 set_start(startMeasure);
64 set_duration(numMeasures);
65 }
66
68 operator Required() const { return { start(), duration() }; }
69
71 static Required make(const std::string& startMeasure, int numMeasures) { return { startMeasure, numMeasures }; }
72
73 MNX_REQUIRED_PROPERTY(int, duration);
74 MNX_OPTIONAL_PROPERTY(std::string, label);
75 MNX_REQUIRED_PROPERTY(std::string, start);
76};
77
83{
84public:
86 struct Required
87 {
88 std::string layoutId;
89 std::string measureId;
91 };
92
94 LayoutChange(const std::shared_ptr<json>& root, json_pointer pointer)
96 {
97 }
98
104 LayoutChange(Base& parent, std::string_view key, const std::string& layoutId, const MeasureRhythmicPosition::Required& location)
106 {
107 set_layout(layoutId);
108 create_location(location.measureId, location.position);
109 }
110
112 operator Required() const { return { layout(), location().measure(), location().position().fraction() }; }
113
115 static Required make(const std::string& layoutId, const MeasureRhythmicPosition::Required& location)
116 { return { layoutId, location.measureId, location.position }; }
117
118 MNX_REQUIRED_PROPERTY(std::string, layout);
120 (const std::string&, measureId), (const FractionValue&, position));
121};
122
128{
129public:
131 struct Required
132 {
133 std::string startMeasure{};
134 };
135
137 System(const std::shared_ptr<json>& root, json_pointer pointer)
139 {
140 }
141
146 System(Base& parent, std::string_view key, const std::string& startMeasure)
148 {
149 set_measure(startMeasure);
150 }
151
153 operator Required() const { return { measure() }; }
154
156 static Required make(const std::string& startMeasure) { return { startMeasure }; }
157
158 MNX_OPTIONAL_PROPERTY(std::string, layout);
160 MNX_REQUIRED_PROPERTY(std::string, measure);
161};
162
168{
169public:
170 using ArrayElementObject::ArrayElementObject;
171
175 Page(Base& parent, std::string_view key)
177 {
178 // required children
179 create_systems();
180 }
181
182 MNX_OPTIONAL_PROPERTY(std::string, layout);
184};
185
186} // namespace score
187
193{
194public:
196 struct Required
197 {
198 std::string scoreName;
199 };
200
202 Score(const std::shared_ptr<json>& root, json_pointer pointer)
204 {
205 }
206
211 Score(Base& parent, std::string_view key, const std::string& scoreName)
213 {
214 set_name(scoreName);
215 }
216
218 operator Required() const { return { name() }; }
219
221 static Required make(const std::string& scoreName) { return { scoreName }; }
222
223 MNX_OPTIONAL_PROPERTY(std::string, layout);
225 MNX_REQUIRED_PROPERTY(std::string, name);
227 MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, useWritten, false);
228};
229
230} // namespace mnx
Represents an MNX object that is included as an array element.
Definition BaseTypes.h:719
Represents an MNX array, encapsulating property access.
Definition BaseTypes.h:531
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:297
Represents a system on a page in a score.
Definition CommonClasses.h:550
Represents an element in the scores section of an MNX document.
Definition Score.h:193
MNX_REQUIRED_PROPERTY(std::string, name)
Required name, such as "Flute 1" or "Full Score".
Score(Base &parent, std::string_view key, const std::string &scoreName)
Creates a new Score class as a child of a JSON element.
Definition Score.h:211
static Required make(const std::string &scoreName)
Create a Required instance for Score.
Definition Score.h:221
MNX_OPTIONAL_CHILD(Array< score::Page >, pages)
An optional list of pages.
MNX_OPTIONAL_PROPERTY(std::string, layout)
Layout id, referring to an element in the root-level layouts array.
MNX_OPTIONAL_CHILD(Array< score::MultimeasureRest >, multimeasureRests)
List of multimeasure rests in the score.
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, useWritten, false)
If this value is true, the score should be displayed transposed.
Score(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing system layouts.
Definition Score.h:202
Represents a system layout change in a score.
Definition Score.h:83
MNX_REQUIRED_PROPERTY(std::string, layout)
Layout id, referring to an element in the root-level layouts array.
LayoutChange(Base &parent, std::string_view key, const std::string &layoutId, const MeasureRhythmicPosition::Required &location)
Creates a new LayoutChange class as a child of a JSON element.
Definition Score.h:104
MNX_REQUIRED_CHILD(MeasureRhythmicPosition, location,(const std::string &, measureId),(const FractionValue &, position))
location where the new layout takes effect.
static Required make(const std::string &layoutId, const MeasureRhythmicPosition::Required &location)
Create a Required instance for LayoutChange.
Definition Score.h:115
LayoutChange(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing system layouts.
Definition Score.h:94
Represents a multimeasure rest in a score.
Definition Score.h:40
MultimeasureRest(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing mm rests.
Definition Score.h:50
static Required make(const std::string &startMeasure, int numMeasures)
Create a Required instance for MultimeasureRest.
Definition Score.h:71
MNX_REQUIRED_PROPERTY(int, duration)
the number of measures in the multimeasure rest
MNX_OPTIONAL_PROPERTY(std::string, label)
the label to place on the multimeasure rest, if provided.
MultimeasureRest(Base &parent, std::string_view key, const std::string &startMeasure, int numMeasures)
Creates a new MultimeasureRest class as a child of a JSON element.
Definition Score.h:60
MNX_REQUIRED_PROPERTY(std::string, start)
the global measure id of the start measure of the multimeasure rest
Represents a page in a score.
Definition Score.h:168
MNX_OPTIONAL_PROPERTY(std::string, layout)
Layout id, referring to an element in the root-level layouts array.
Page(Base &parent, std::string_view key)
Creates a new Page class as a child of a JSON element.
Definition Score.h:175
MNX_REQUIRED_CHILD(Array< System >, systems)
and array systems on the page.
Represents a system on a page in a score.
Definition Score.h:128
System(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing system layouts.
Definition Score.h:137
MNX_OPTIONAL_PROPERTY(std::string, layout)
Layout id, referring to an element in the root-level layouts array.
MNX_REQUIRED_PROPERTY(std::string, measure)
The global measure if of the first measure in the system.
System(Base &parent, std::string_view key, const std::string &startMeasure)
Creates a new System class as a child of a JSON element.
Definition Score.h:146
MNX_OPTIONAL_CHILD(Array< LayoutChange >, layoutChanges)
layout changes in the system (e.g., for changes in stem direction)
static Required make(const std::string &startMeasure)
Create a Required instance for System.
Definition Score.h:156
object model for MNX format
json::json_pointer json_pointer
JSON pointer class for MNX.
Definition BaseTypes.h:68
Represents a detached arithmetic fraction with normalization.
Definition CommonClasses.h:74
initializer class for MeasureRhythmicPosition
Definition CommonClasses.h:554
std::string measureId
the global measure id of the position
Definition CommonClasses.h:555
FractionValue position
the position within the measure
Definition CommonClasses.h:556
initializer class for Score
Definition Score.h:197
std::string scoreName
the name of the score to be created
Definition Score.h:198
initializer class for LayoutChange
Definition Score.h:87
std::string layoutId
the id of the layout to use for the layout change
Definition Score.h:88
FractionValue position
the position of the LayoutChange within the measure
Definition Score.h:90
std::string measureId
the global measure id of the measure of the position
Definition Score.h:89
initializer class for MultimeasureRest
Definition Score.h:44
std::string startMeasure
the measure index of the first measure in the multimeasure rest
Definition Score.h:45
int numMeasures
the number of measures in the multimeasure rest
Definition Score.h:46
initializer class for System
Definition Score.h:132
std::string startMeasure
the measure index of the first measure in the system
Definition Score.h:133