MNX Document Model
Loading...
Searching...
No Matches
Part.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 "Sequence.h"
26
27namespace mnx {
28
33namespace part {
34
40{
41public:
43 Beam(const std::shared_ptr<json>& root, json_pointer pointer)
45 {
46 }
47
51 Beam(Base& parent, const std::string_view& key)
53 {
54 create_events();
55 }
56
60};
61
66class Clef : public Object
67{
68public:
70 Clef(const std::shared_ptr<json>& root, json_pointer pointer)
72 {
73 }
74
81 Clef(Base& parent, const std::string_view& key, ClefSign clefSign, int staffPosition, std::optional<OttavaAmountOrZero> octaveAdjustment = std::nullopt)
82 : Object(parent, key)
83 {
84 set_sign(clefSign);
85 set_staffPosition(staffPosition);
86 if (octaveAdjustment.has_value()) {
87 set_octave(octaveAdjustment.value());
88 }
89 }
90
91 MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class");
92 MNX_OPTIONAL_PROPERTY(std::string, color);
93 MNX_OPTIONAL_PROPERTY(std::string, glyph);
95 MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, showOctave, true);
97 MNX_REQUIRED_PROPERTY(int, staffPosition);
98};
99
104class Dynamic : public ContentObject
105{
106public:
108 Dynamic(const std::shared_ptr<json>& root, json_pointer pointer)
110 {
111 }
112
118 Dynamic(Base& parent, const std::string_view& key, const std::string& value, const Fraction::Initializer& position)
119 : ContentObject(parent, key)
120 {
121 set_value(value);
122 create_position(position);
123 }
124
125 MNX_OPTIONAL_PROPERTY(std::string, glyph);
128 MNX_REQUIRED_PROPERTY(std::string, value);
129 MNX_OPTIONAL_PROPERTY(std::string, voice);
130};
131
137{
138public:
140 Ottava(const std::shared_ptr<json>& root, json_pointer pointer)
142 {
143 }
144
152 Ottava(Base& parent, const std::string_view& key, OttavaAmount value, const Fraction::Initializer& position, int endMeasureId, const Fraction::Initializer& endPosition)
154 {
155 create_position(position);
156 create_end(endMeasureId, endPosition);
157 set_value(value);
158 }
159
165 MNX_OPTIONAL_PROPERTY(std::string, voice);
166};
167
173{
174public:
176 KitComponent(const std::shared_ptr<json>& root, json_pointer pointer)
178 {
179 }
180
185 KitComponent(Base& parent, const std::string_view& key, int staffPosition)
187 {
188 set_staffPosition(staffPosition);
189 }
190
191 MNX_OPTIONAL_PROPERTY(std::string, name);
192 MNX_OPTIONAL_PROPERTY(std::string, sound);
193 MNX_REQUIRED_PROPERTY(int, staffPosition);
194};
195
201{
202public:
204 PartTransposition(const std::shared_ptr<json>& root, json_pointer pointer)
206 {
207 }
208
214 PartTransposition(Base& parent, const std::string_view& key, int diatonic, int chromatic)
215 : Object(parent, key)
216 {
217 create_interval(diatonic, chromatic);
218 }
219
221 MNX_OPTIONAL_PROPERTY(int, keyFifthsFlipAt);
222 MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, prefersWrittenPitches, false);
224};
225
231{
232public:
234 PositionedClef(const std::shared_ptr<json>& root, json_pointer pointer)
236 {
237 }
238
245 PositionedClef(Base& parent, const std::string_view& key, ClefSign clefSign, int staffPosition, std::optional<OttavaAmountOrZero> octaveAdjustment = std::nullopt)
247 {
248 create_clef(clefSign, staffPosition, octaveAdjustment);
249 }
250
254};
255
261{
262public:
263 using ArrayElementObject::ArrayElementObject;
264
268 Measure(Base& parent, const std::string_view& key)
270 {
271 // required children
272 create_sequences();
273 }
274
280};
281
282} // namespace part
283
289{
290public:
291 using ArrayElementObject::ArrayElementObject;
292
295 MNX_OPTIONAL_PROPERTY(std::string, name);
296 MNX_OPTIONAL_PROPERTY(std::string, shortName);
297 MNX_OPTIONAL_PROPERTY(std::string, smuflFont);
300};
301
302} // 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
Base class for objects that are elements of content arrays.
Definition BaseTypes.h:644
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 a musical chromatic interval.
Definition CommonClasses.h:162
Represents a system on a page in a score.
Definition CommonClasses.h:133
Represents an MNX object, encapsulating property access.
Definition BaseTypes.h:421
Represents a single part in an MNX document.
Definition Part.h:289
MNX_OPTIONAL_PROPERTY(std::string, name)
Specifies the user-facing full name of this part.
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(int, staves, 1)
The number of staves in this part.
MNX_OPTIONAL_PROPERTY(std::string, smuflFont)
Name of SMuFL-font for notation elements in the part (can be overridden by children)
MNX_OPTIONAL_CHILD(part::PartTransposition, transposition)
the instrument transposition for the part
MNX_OPTIONAL_CHILD(Dictionary< part::KitComponent >, kit)
The definition of a kit of (usually percussion) instruments that are used by the part.
MNX_OPTIONAL_PROPERTY(std::string, shortName)
Specifies the user-facing abbreviated name of this part.
MNX_OPTIONAL_CHILD(Array< part::Measure >, measures)
Contains all the musical data for this part.
Represents a system on a page in a score.
Definition CommonClasses.h:105
Contains information about each level of bea.
Definition Part.h:40
Beam(Base &parent, const std::string_view &key)
Creates a new Beam class as a child of a JSON element.
Definition Part.h:51
MNX_OPTIONAL_CHILD(Array< Beam >, beams)
the beams that comprise the next beam level (may be omitted)
MNX_REQUIRED_CHILD(Array< std::string >, events)
the events that comprise this beam level
Beam(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Beam objects.
Definition Part.h:43
MNX_OPTIONAL_PROPERTY(BeamHookDirection, direction)
the forced direction of a beam hook (if this beam contains one event).
Represents a visible clef in the measure.
Definition Part.h:67
MNX_OPTIONAL_PROPERTY(std::string, color)
color to use when rendering the ending
MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class")
style class
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, showOctave, true)
if octave is non-zero, this value determines whether the octave should be displayedon the clef
Clef(Base &parent, const std::string_view &key, ClefSign clefSign, int staffPosition, std::optional< OttavaAmountOrZero > octaveAdjustment=std::nullopt)
Creates a new Clef class as a child of a JSON element.
Definition Part.h:81
MNX_REQUIRED_PROPERTY(ClefSign, sign)
the clef sign
MNX_OPTIONAL_PROPERTY(std::string, glyph)
the specific SMuFL glyph to use for rendering the clef
MNX_REQUIRED_PROPERTY(int, staffPosition)
staff position offset from center of staff (in half-spaces)
Clef(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Clef instances.
Definition Part.h:70
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(OttavaAmountOrZero, octave, OttavaAmountOrZero::NoTransposition)
the number of octaves by which the clef transposes
Represents a dynamic positioned with the next event in the sequence.
Definition Part.h:105
MNX_REQUIRED_PROPERTY(std::string, value)
The value of the dynamic. Currently the MNX spec allows any string here.
MNX_OPTIONAL_PROPERTY(std::string, glyph)
The SMuFL glyph name (if any)
MNX_REQUIRED_CHILD(RhythmicPosition, position)
The rhythmic position of the dynamic within the measure.
MNX_OPTIONAL_PROPERTY(std::string, voice)
Optionally specify the voice this dynamic applies to.
Dynamic(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Space objects.
Definition Part.h:108
Dynamic(Base &parent, const std::string_view &key, const std::string &value, const Fraction::Initializer &position)
Creates a new Space class as a child of a JSON element.
Definition Part.h:118
MNX_OPTIONAL_PROPERTY(int, staff)
The staff (within the part) this dynamic applies to.
Describes a single instrument of a drum kit associated with the part.
Definition Part.h:173
MNX_OPTIONAL_PROPERTY(std::string, name)
Human-readable name of the kit component.
KitComponent(Base &parent, const std::string_view &key, int staffPosition)
Creates a new Clef class as a child of a JSON element.
Definition Part.h:185
MNX_OPTIONAL_PROPERTY(std::string, sound)
The sound ID in global.sounds.
MNX_REQUIRED_PROPERTY(int, staffPosition)
The staff position of the kit component, where 0 is the middle line.
KitComponent(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Clef instances.
Definition Part.h:176
Represents a single measuer in a part in an MNX document. It contains the majority of the musical inf...
Definition Part.h:261
MNX_OPTIONAL_CHILD(Array< PositionedClef >, clefs)
the clef changes in this bar
MNX_OPTIONAL_CHILD(Array< Dynamic >, dynamics)
the dynamics in this measure
MNX_OPTIONAL_CHILD(Array< Ottava >, ottavas)
the ottavas in this measure
Measure(Base &parent, const std::string_view &key)
Creates a new Measure class as a child of a JSON element.
Definition Part.h:268
MNX_REQUIRED_CHILD(Array< Sequence >, sequences)
sequences that contain all the musical details in each measure
MNX_OPTIONAL_CHILD(Array< Beam >, beams)
the beams in this measure
Represents an ottava starting with the next event in the sequence.
Definition Part.h:137
MNX_OPTIONAL_PROPERTY(std::string, voice)
Optionally specify the voice this ottava applies to.
MNX_REQUIRED_CHILD(MeasureRhythmicPosition, end)
Ottava(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Space objects.
Definition Part.h:140
MNX_REQUIRED_PROPERTY(OttavaAmount, value)
The type of ottava (amount of displacement, in octaves)
MNX_REQUIRED_CHILD(RhythmicPosition, position)
The start position of the ottava.
Ottava(Base &parent, const std::string_view &key, OttavaAmount value, const Fraction::Initializer &position, int endMeasureId, const Fraction::Initializer &endPosition)
Creates a new Space class as a child of a JSON element.
Definition Part.h:152
MNX_OPTIONAL_PROPERTY(int, staff)
The staff (within the part) this ottava applies to.
Describes a part's instrument transposition.
Definition Part.h:201
MNX_OPTIONAL_PROPERTY(int, keyFifthsFlipAt)
the number of sharps (positive) or flats (negative) at which to simplify the key signature
MNX_REQUIRED_CHILD(Interval, interval)
the transposition interval
PartTransposition(Base &parent, const std::string_view &key, int diatonic, int chromatic)
Creates a new Clef class as a child of a JSON element.
Definition Part.h:214
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, prefersWrittenPitches, false)
concert-pitch score. (Examples could be piccolo, double base, glockenspiel, etc.)
PartTransposition(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Clef instances.
Definition Part.h:204
Represents a positioned clef for the measure.
Definition Part.h:231
MNX_OPTIONAL_CHILD(RhythmicPosition, position)
location within the measure of the tempo marking
MNX_REQUIRED_CHILD(Clef, clef)
the beats per minute of this tempo marking
PositionedClef(Base &parent, const std::string_view &key, ClefSign clefSign, int staffPosition, std::optional< OttavaAmountOrZero > octaveAdjustment=std::nullopt)
Creates a new PositionedClef class as a child of a JSON element.
Definition Part.h:245
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(int, staff, 1)
the staff number (for multistaff parts)
PositionedClef(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing PositionedClef instances.
Definition Part.h:234
object model for MNX format
ClefSign
The values available in a clef sign object.
Definition Enumerations.h:94
OttavaAmount
Valid values for ottava amount.
Definition Enumerations.h:212
json::json_pointer json_pointer
JSON pointer class for MNX.
Definition BaseTypes.h:198
OttavaAmountOrZero
Valid values for octave displacment amount, including zero for no transposition.
Definition Enumerations.h:231
@ NoTransposition
No transposition.
BeamHookDirection
The types of jumps.
Definition Enumerations.h:71