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
105 LayoutChange(Base& parent, std::string_view key, const std::string& layoutId, const std::string& measureId, const FractionValue& position)
107 {
108 set_layout(layoutId);
109 create_location(measureId, position);
110 }
111
113 operator Required() const { return { layout(), location().measure(), location().position().fraction() }; }
114
116 static Required make(const std::string& layoutId, const std::string& measureId, const FractionValue& position)
117 { return { layoutId, measureId, position }; }
118
119 MNX_REQUIRED_PROPERTY(std::string, layout);
121 (const std::string&, measureId), (const FractionValue&, position));
122};
123
129{
130public:
132 struct Required
133 {
134 std::string startMeasure{};
135 };
136
138 System(const std::shared_ptr<json>& root, json_pointer pointer)
140 {
141 }
142
147 System(Base& parent, std::string_view key, const std::string& startMeasure)
149 {
150 set_measure(startMeasure);
151 }
152
154 operator Required() const { return { measure() }; }
155
157 static Required make(const std::string& startMeasure) { return { startMeasure }; }
158
159 MNX_OPTIONAL_PROPERTY(std::string, layout);
161 MNX_REQUIRED_PROPERTY(std::string, measure);
162};
163
169{
170public:
171 using ArrayElementObject::ArrayElementObject;
172
176 Page(Base& parent, std::string_view key)
178 {
179 // required children
180 create_systems();
181 }
182
183 MNX_OPTIONAL_PROPERTY(std::string, layout);
185};
186
187} // namespace score
188
194{
195public:
197 struct Required
198 {
199 std::string scoreName;
200 };
201
203 Score(const std::shared_ptr<json>& root, json_pointer pointer)
205 {
206 }
207
212 Score(Base& parent, std::string_view key, const std::string& scoreName)
214 {
215 set_name(scoreName);
216 }
217
219 operator Required() const { return { name() }; }
220
222 static Required make(const std::string& scoreName) { return { scoreName }; }
223
224 MNX_OPTIONAL_PROPERTY(std::string, layout);
226 MNX_REQUIRED_PROPERTY(std::string, name);
228 MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, useWritten, false);
229};
230
231} // 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 a system on a page in a score.
Definition CommonClasses.h:474
Represents an element in the scores section of an MNX document.
Definition Score.h:194
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:212
static Required make(const std::string &scoreName)
Create a Required instance for Score.
Definition Score.h:222
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:203
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 std::string &measureId, const FractionValue &position)
Creates a new LayoutChange class as a child of a JSON element.
Definition Score.h:105
static Required make(const std::string &layoutId, const std::string &measureId, const FractionValue &position)
Create a Required instance for LayoutChange.
Definition Score.h:116
MNX_REQUIRED_CHILD(MeasureRhythmicPosition, location,(const std::string &, measureId),(const FractionValue &, position))
location where the new layout takes effect.
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:169
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:176
MNX_REQUIRED_CHILD(Array< System >, systems)
and array systems on the page.
Represents a system on a page in a score.
Definition Score.h:129
System(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing system layouts.
Definition Score.h:138
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:147
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:157
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:59
initializer class for Score
Definition Score.h:198
std::string scoreName
the name of the score to be created
Definition Score.h:199
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:133
std::string startMeasure
the measure index of the first measure in the system
Definition Score.h:134