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 ArpeggioBase(const std::shared_ptr<json>& root, json_pointer pointer)
45 {
46 }
47
53 ArpeggioBase(Base& parent, std::string_view key, const FractionValue& position, const IdPair::Required& span)
55 {
56 create_position(position);
57 create_span(span.startId, span.endId);
58 }
59
61 RhythmicPosition, position,
62 (FractionValue, value));
64 IdPair, span,
65 (const std::string&, startId),
66 (const std::string&, endId));
67};
68
81
87{
88public:
90};
91
97{
98public:
100 Beam(const std::shared_ptr<json>& root, json_pointer pointer)
102 {
103 }
104
108 Beam(Base& parent, std::string_view key)
110 {
111 create_events();
112 }
113
117
118 inline static constexpr std::string_view JsonSchemaTypeName = "beam";
119};
120
125class Clef : public Object
126{
127public:
135
137 Clef(const std::shared_ptr<json>& root, json_pointer pointer)
139 {
140 }
141
148 Clef(Base& parent, std::string_view key, ClefSign clefSign, int staffPosition, OttavaAmountOrZero octaveAdjustment = OttavaAmountOrZero::NoTransposition)
149 : Object(parent, key)
150 {
151 set_sign(clefSign);
152 set_staffPosition(staffPosition);
153 set_or_clear_octave(octaveAdjustment);
154 }
155
157 operator Required() const { return { sign(), staffPosition(), octave() }; }
158
160 static Required make(ClefSign clefSign, int staffPosition, OttavaAmountOrZero octaveAdjustment = OttavaAmountOrZero::NoTransposition)
161 { return { clefSign, staffPosition, octaveAdjustment }; }
162
163 MNX_OPTIONAL_PROPERTY(std::string, color);
164 MNX_OPTIONAL_PROPERTY(std::string, glyph);
166 MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, showOctave, true);
168 MNX_REQUIRED_PROPERTY(int, staffPosition);
169};
170
176{
177public:
179 struct Required
180 {
181 std::string value;
183 };
184
186 Dynamic(const std::shared_ptr<json>& root, json_pointer pointer)
188 {
189 }
190
196 Dynamic(Base& parent, std::string_view key, const std::string& value, const FractionValue& position)
198 {
199 set_value(value);
200 create_position(position);
201 }
202
204 operator Required() const { return { value(), position().fraction() }; }
205
207 static Required make(const std::string& value, const FractionValue& position) { return { value, position }; }
208
209 MNX_OPTIONAL_PROPERTY(std::string, glyph);
211 RhythmicPosition, position,
212 (const FractionValue&, position));
214 MNX_REQUIRED_PROPERTY(std::string, value);
215 MNX_OPTIONAL_PROPERTY(std::string, voice);
216};
217
223{
224public:
233
235 Ottava(const std::shared_ptr<json>& root, json_pointer pointer)
237 {
238 }
239
247 Ottava(Base& parent, std::string_view key, OttavaAmount value, const FractionValue& position, const std::string& endMeasureId, const FractionValue& endPosition)
249 {
250 create_position(position);
251 create_end(endMeasureId, endPosition);
252 set_value(value);
253 }
254
256 operator Required() const
257 {
258 return { value(), position().fraction(), end().measure(), end().position().fraction() };
259 }
260
262 static Required make(OttavaAmount value, const FractionValue& position, const std::string& endMeasureId, const FractionValue& endPosition)
263 { return { value, position, endMeasureId, endPosition }; }
264
266 (const std::string&, measureId), (const FractionValue&, position));
269 (const FractionValue&, position));
272 MNX_OPTIONAL_PROPERTY(std::string, voice);
273};
274
280{
281public:
283 struct Required
284 {
286 };
287
289 KitComponent(const std::shared_ptr<json>& root, json_pointer pointer)
291 {
292 }
293
298 KitComponent(Base& parent, std::string_view key, int staffPosition)
300 {
301 set_staffPosition(staffPosition);
302 }
303
305 operator Required() const { return { staffPosition() }; }
306
308 static Required make(int staffPosition) { return { staffPosition }; }
309
310 MNX_OPTIONAL_PROPERTY(std::string, name);
311 MNX_OPTIONAL_PROPERTY(std::string, sound);
312 MNX_REQUIRED_PROPERTY(int, staffPosition);
313};
314
320{
321public:
327
329 PartTransposition(const std::shared_ptr<json>& root, json_pointer pointer)
331 {
332 }
333
338 PartTransposition(Base& parent, std::string_view key, const Interval::Required& interval)
339 : Object(parent, key)
340 {
341 create_interval(interval.staffDistance, interval.halfSteps);
342 }
343
345 operator Required() const { return { interval() }; }
346
348 static Required make(const Interval::Required& interval) { return { interval }; }
349
351 (int, staffDistance), (int, halfSteps));
352 MNX_OPTIONAL_PROPERTY(int, keyFifthsFlipAt);
353 MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, prefersWrittenPitches, false);
355
359};
360
366{
367public:
375
377 PositionedClef(const std::shared_ptr<json>& root, json_pointer pointer)
379 {
380 }
381
388 PositionedClef(Base& parent, std::string_view key, ClefSign clefSign, int staffPosition, OttavaAmountOrZero octaveAdjustment = OttavaAmountOrZero::NoTransposition)
390 {
391 create_clef(clefSign, staffPosition, octaveAdjustment);
392 }
393
395 operator Required() const { return { clef().sign(), clef().staffPosition(), clef().octave() }; }
396
398 static Required make(ClefSign clefSign, int staffPosition, OttavaAmountOrZero octaveAdjustment = OttavaAmountOrZero::NoTransposition)
399 { return { clefSign, staffPosition, octaveAdjustment }; }
400
402 (ClefSign, clefSign), (int, staffPosition), (OttavaAmountOrZero, octaveAdjustment));
404 (const FractionValue&, position));
406};
407
413{
414public:
415 using ArrayElementObject::ArrayElementObject;
416
420 Measure(Base& parent, std::string_view key)
422 {
423 // required children
424 create_sequences();
425 }
426
434
437 [[nodiscard]] mnx::global::Measure getGlobalMeasure() const;
438
441 [[nodiscard]] std::optional<TimeSignature> calcCurrentTime() const;
442
443 inline static constexpr std::string_view JsonSchemaTypeName = "part-measure";
444};
445
446} // namespace part
447
453{
454public:
455 using ArrayElementObject::ArrayElementObject;
456
460 Part(Base& parent, std::string_view key)
462 {
463 // required children
464 create_measures();
465 }
466
469 MNX_OPTIONAL_PROPERTY(std::string, name);
470 MNX_OPTIONAL_PROPERTY(std::string, shortName);
471 MNX_OPTIONAL_PROPERTY(std::string, smuflFont);
474 (const Interval::Required&, interval));
475
476 inline static constexpr std::string_view JsonSchemaTypeName = "measure-global";
477};
478
479} // namespace mnx
Represents an MNX object that is included as an array element.
Definition BaseTypes.h:675
Represents an MNX array, encapsulating property access.
Definition BaseTypes.h:506
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:283
Represents an MNX dictionary, where each key is a user-defined string.
Definition BaseTypes.h:870
Represents a start and end id pair.
Definition CommonClasses.h:447
Represents a musical chromatic interval.
Definition CommonClasses.h:604
Represents a system on a page in a score.
Definition CommonClasses.h:550
Represents an MNX object, encapsulating property access.
Definition BaseTypes.h:415
Represents a single part in an MNX document.
Definition Part.h:453
MNX_OPTIONAL_CHILD(part::PartTransposition, transposition,(const Interval::Required &, interval))
the instrument transposition for the part
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_REQUIRED_CHILD(Array< part::Measure >, measures)
Contains all the musical data for this part.
static constexpr std::string_view JsonSchemaTypeName
required for mapping
Definition Part.h:476
MNX_OPTIONAL_PROPERTY(std::string, smuflFont)
Name of SMuFL-font for notation elements in the part (can be overridden by children)
MNX_OPTIONAL_CHILD(Dictionary< part::KitComponent >, kit)
The definition of a kit of (usually percussion) instruments that are used by the part.
Part(Base &parent, std::string_view key)
Creates a new Part class as a child of a JSON element.
Definition Part.h:460
MNX_OPTIONAL_PROPERTY(std::string, shortName)
Specifies the user-facing abbreviated name of this part.
Represents a system on a page in a score.
Definition CommonClasses.h:489
Represents a single global measure instance within an MNX document.
Definition Global.h:324
Contains information about both arpeggios and non arpeggios.
Definition Part.h:40
MNX_REQUIRED_CHILD(IdPair, span,(const std::string &, startId),(const std::string &, endId))
the span of the arpeggio
ArpeggioBase(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Beam objects.
Definition Part.h:43
ArpeggioBase(Base &parent, std::string_view key, const FractionValue &position, const IdPair::Required &span)
Creates a new Beam class as a child of a JSON element.
Definition Part.h:53
MNX_REQUIRED_CHILD(RhythmicPosition, position,(FractionValue, value))
the rhythmic position of the arpeggio
Contains information about arpeggios.
Definition Part.h:74
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(MarkingUpDownAuto, direction, MarkingUpDownAuto::Auto)
the direction of the arpeggio
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, arrow, false)
specifies if the arpeggio has an arrow
Contains information about each level of beam.
Definition Part.h:97
static constexpr std::string_view JsonSchemaTypeName
required for mapping
Definition Part.h:118
Beam(Base &parent, std::string_view key)
Creates a new Beam class as a child of a JSON element.
Definition Part.h:108
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:100
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:126
MNX_OPTIONAL_PROPERTY(std::string, color)
color to use when rendering the ending
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, showOctave, true)
if octave is non-zero, this value determines whether the octave should be displayed on the clef
MNX_REQUIRED_PROPERTY(ClefSign, sign)
the clef sign
Clef(Base &parent, std::string_view key, ClefSign clefSign, int staffPosition, OttavaAmountOrZero octaveAdjustment=OttavaAmountOrZero::NoTransposition)
Creates a new Clef class as a child of a JSON element.
Definition Part.h:148
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:137
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(OttavaAmountOrZero, octave, OttavaAmountOrZero::NoTransposition)
the number of octaves by which the clef transposes
static Required make(ClefSign clefSign, int staffPosition, OttavaAmountOrZero octaveAdjustment=OttavaAmountOrZero::NoTransposition)
Create a Required instance for Clef.
Definition Part.h:160
Represents a dynamic positioned with the next event in the sequence.
Definition Part.h:176
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)
Dynamic(Base &parent, std::string_view key, const std::string &value, const FractionValue &position)
Creates a new Space class as a child of a JSON element.
Definition Part.h:196
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:186
MNX_REQUIRED_CHILD(RhythmicPosition, position,(const FractionValue &, position))
The rhythmic position of the dynamic within the measure.
static Required make(const std::string &value, const FractionValue &position)
Create a Required instance for Dynamic.
Definition Part.h:207
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:280
MNX_OPTIONAL_PROPERTY(std::string, name)
Human-readable name of the kit component.
static Required make(int staffPosition)
Create a Required instance for KitComponent.
Definition Part.h:308
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(Base &parent, std::string_view key, int staffPosition)
Creates a new Clef class as a child of a JSON element.
Definition Part.h:298
KitComponent(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Clef instances.
Definition Part.h:289
Represents a single measure in a part in an MNX document. It contains the majority of the musical inf...
Definition Part.h:413
MNX_OPTIONAL_CHILD(Array< PositionedClef >, clefs)
the clef changes in this bar
Measure(Base &parent, std::string_view key)
Creates a new Measure class as a child of a JSON element.
Definition Part.h:420
MNX_OPTIONAL_CHILD(Array< Dynamic >, dynamics)
the dynamics in this measure
MNX_OPTIONAL_CHILD(Array< Ottava >, ottavas)
the ottavas in this measure
static constexpr std::string_view JsonSchemaTypeName
required for mapping
Definition Part.h:443
MNX_REQUIRED_CHILD(Array< Sequence >, sequences)
sequences that contain all the musical details in each measure
std::optional< TimeSignature > calcCurrentTime() const
Caculates the time signature at this measure.
Definition Implementations.cpp:645
MNX_OPTIONAL_CHILD(Array< Beam >, beams)
the beams in this measure
MNX_OPTIONAL_CHILD(Array< Arpeggio >, arpeggios)
the arpeggios in this measure
mnx::global::Measure getGlobalMeasure() const
Returns the global measure for this part measure.
Definition Implementations.cpp:635
MNX_OPTIONAL_CHILD(Array< NonArpeggio >, nonArpeggios)
the non-arpeggios in this measure
Contains information about non-arpeggios.
Definition Part.h:87
Represents an ottava starting with the next event in the sequence.
Definition Part.h:223
static Required make(OttavaAmount value, const FractionValue &position, const std::string &endMeasureId, const FractionValue &endPosition)
Create a Required instance for Ottava.
Definition Part.h:262
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(Orientation, orient, Orientation::Auto)
Whether the ottava is above or below the staff
MNX_OPTIONAL_PROPERTY(std::string, voice)
Optionally specify the voice this ottava applies to.
Ottava(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Space objects.
Definition Part.h:235
MNX_REQUIRED_CHILD(MeasureRhythmicPosition, end,(const std::string &, measureId),(const FractionValue &, position))
The end of the ottava (includes any events starting at this location)
MNX_REQUIRED_PROPERTY(OttavaAmount, value)
The type of ottava (amount of displacement, in octaves)
MNX_REQUIRED_CHILD(RhythmicPosition, position,(const FractionValue &, position))
The start position of the ottava.
Ottava(Base &parent, std::string_view key, OttavaAmount value, const FractionValue &position, const std::string &endMeasureId, const FractionValue &endPosition)
Creates a new Space class as a child of a JSON element.
Definition Part.h:247
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(int, staff, 1)
The staff (within the part) this ottava applies to.
Describes a part's instrument transposition.
Definition Part.h:320
KeySignature::Required calcTransposedKey(const KeySignature::Required &concertKey) const
Calculates and returns the transposed keyFifths value for the input key.
Definition Implementations.cpp:669
MNX_OPTIONAL_PROPERTY(int, keyFifthsFlipAt)
the number of sharps (positive) or flats (negative) at which to simplify the key signature
static Required make(const Interval::Required &interval)
Create a Required instance for PartTransposition.
Definition Part.h:348
MNX_REQUIRED_CHILD(Interval, interval,(int, staffDistance),(int, halfSteps))
the transposition interval
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, prefersWrittenPitches, false)
concert-pitch score. (Examples could be piccolo, double base, glockenspiel, etc.)
PartTransposition(Base &parent, std::string_view key, const Interval::Required &interval)
Creates a new Clef class as a child of a JSON element.
Definition Part.h:338
PartTransposition(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Clef instances.
Definition Part.h:329
Represents a positioned clef for the measure.
Definition Part.h:366
PositionedClef(Base &parent, std::string_view key, ClefSign clefSign, int staffPosition, OttavaAmountOrZero octaveAdjustment=OttavaAmountOrZero::NoTransposition)
Creates a new PositionedClef class as a child of a JSON element.
Definition Part.h:388
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(int, staff, 1)
the staff number (for multistaff parts)
MNX_REQUIRED_CHILD(Clef, clef,(ClefSign, clefSign),(int, staffPosition),(OttavaAmountOrZero, octaveAdjustment))
the beats per minute of this tempo marking
PositionedClef(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing PositionedClef instances.
Definition Part.h:377
static Required make(ClefSign clefSign, int staffPosition, OttavaAmountOrZero octaveAdjustment=OttavaAmountOrZero::NoTransposition)
Create a Required instance for PositionedClef.
Definition Part.h:398
MNX_OPTIONAL_CHILD(RhythmicPosition, position,(const FractionValue &, position))
location within the measure of the tempo marking
object model for MNX format
MarkingUpDownAuto
Specifies up or down or auto for a marking symbol.
Definition Enumerations.h:232
@ Auto
determined by consuming property
ClefSign
The values available in a clef sign object.
Definition Enumerations.h:94
OttavaAmount
Valid values for ottava amount.
Definition Enumerations.h:296
json::json_pointer json_pointer
JSON pointer class for MNX.
Definition BaseTypes.h:68
OttavaAmountOrZero
Valid values for octave displacment amount, including zero for no transposition.
Definition Enumerations.h:315
@ NoTransposition
No transposition.
BeamHookDirection
The types of jumps.
Definition Enumerations.h:71
Orientation
Specifies the vertical visual orientation of a glyph with respect to its corresponding notation.
Definition Enumerations.h:285
@ Auto
the default value determined by implementation
Represents a detached arithmetic fraction with normalization.
Definition CommonClasses.h:74
initializer class for IdPair
Definition CommonClasses.h:451
std::string startId
the start id of the pair
Definition CommonClasses.h:452
std::string endId
the end id of the pair
Definition CommonClasses.h:453
initializer class for Interval
Definition CommonClasses.h:608
int halfSteps
the number of 12-EDO chromatic halfsteps in the interval (negative is down)
Definition CommonClasses.h:610
int staffDistance
the number of diatonic steps in the interval (negative is down)
Definition CommonClasses.h:609
initializer class for KeySignature
Definition CommonClasses.h:650
initializer class for Clef
Definition Part.h:130
ClefSign clefSign
the type of clef symbol
Definition Part.h:131
OttavaAmountOrZero octaveAdjustment
octave adjustment (NoTransposition when unset)
Definition Part.h:133
int staffPosition
staff position offset from center of staff
Definition Part.h:132
initializer class for Dynamic
Definition Part.h:180
std::string value
the value of the dynamic
Definition Part.h:181
FractionValue position
the position within the measure
Definition Part.h:182
initializer class for KitComponent
Definition Part.h:284
int staffPosition
the staff position of the kit component
Definition Part.h:285
initializer class for Ottava
Definition Part.h:227
FractionValue position
the start position of the ottava
Definition Part.h:229
std::string endMeasureId
the global id of the end measure of the ottava
Definition Part.h:230
FractionValue endPosition
the position within the end measure
Definition Part.h:231
OttavaAmount value
the value (type) of ottava
Definition Part.h:228
initializer class for PartTransposition
Definition Part.h:324
Interval::Required interval
the transposition interval for the part
Definition Part.h:325
initializer class for PositionedClef
Definition Part.h:370
ClefSign clefSign
the type of clef symbol
Definition Part.h:371
int staffPosition
staff position offset from center of staff
Definition Part.h:372
OttavaAmountOrZero octaveAdjustment
the octave adjustment
Definition Part.h:373