MNX Document Model
Loading...
Searching...
No Matches
Sequence.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#include "Enumerations.h"
27#include "EventMarkings.h"
28
29namespace mnx {
30
31class Sequence; // forward declaration
32
37namespace sequence {
38
44{
45public:
47 AccidentalEnclosure(const std::shared_ptr<json>& root, json_pointer pointer)
49 {
50 }
51
56 AccidentalEnclosure(Base& parent, const std::string_view& key, AccidentalEnclosureSymbol inSymbol)
57 : Object(parent, key)
58 {
59 set_symbol(inSymbol);
60 }
61
63};
64
70{
71public:
73 AccidentalDisplay(const std::shared_ptr<json>& root, json_pointer pointer)
75 {
76 }
77
82 AccidentalDisplay(Base& parent, const std::string_view& key, bool showAcci)
83 : Object(parent, key)
84 {
85 set_show(showAcci);
86 }
87
91};
92
98{
99public:
100 using ArrayElementObject::ArrayElementObject;
101
102 MNX_OPTIONAL_PROPERTY(int, staffPosition);
103};
104
110{
111public:
112 using Object::Object;
113
114 MNX_OPTIONAL_PROPERTY(int, diatonicDelta);
115};
116
121class Pitch : public Object
122{
123public:
125 Pitch(const std::shared_ptr<json>& root, json_pointer pointer)
127 {
128 }
129
136 Pitch(Base& parent, const std::string_view& key, NoteStep inpStep, int inpOctave, std::optional<int> inpAlter = std::nullopt)
137 : Object(parent, key)
138 {
139 set_step(inpStep);
140 set_octave(inpOctave);
141 if (inpAlter) {
142 set_alter(inpAlter.value());
143 }
144 }
145
149
153 bool isSamePitch(const Pitch& src) const;
154};
155
161{
162public:
164 Slur(const std::shared_ptr<json>& root, json_pointer pointer)
166 {
167 }
168
173 Slur(Base& parent, const std::string_view& key, const std::string& target)
175 {
176 set_target(target);
177 }
178
179 MNX_OPTIONAL_PROPERTY(std::string, endNote);
183 MNX_OPTIONAL_PROPERTY(std::string, startNote);
184 MNX_REQUIRED_PROPERTY(std::string, target);
185};
186
192{
193public:
195 Tie(const std::shared_ptr<json>& root, json_pointer pointer)
197 {
198 }
199
204 Tie(Base& parent, const std::string_view& key, const std::optional<std::string>& target = std::nullopt)
206 {
207 if (target) {
208 set_target(target.value());
209 } else {
210 set_lv(true);
211 }
212 }
213
216 MNX_OPTIONAL_PROPERTY(std::string, target);
217};
218
224{
225public:
226 using ArrayElementObject::ArrayElementObject;
227
230 MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class");
232};
233
238class KitNote : public NoteBase
239{
240public:
242 KitNote(const std::shared_ptr<json>& root, json_pointer pointer)
244 {
245 }
246
251 KitNote(Base& parent, const std::string_view& key, std::string kitComponentId)
252 : NoteBase(parent, key)
253 {
254 set_kitComponent(kitComponentId);
255 }
256
257 MNX_REQUIRED_PROPERTY(std::string, kitComponent);
258};
259
264class Note : public NoteBase
265{
266public:
268 Note(const std::shared_ptr<json>& root, json_pointer pointer)
270 {
271 }
272
279 Note(Base& parent, const std::string_view& key, NoteStep step, int octave, std::optional<int> alter = std::nullopt)
280 : NoteBase(parent, key)
281 {
282 create_pitch(step, octave, alter);
283 }
284
288};
289
295{
296public:
298 EventLyricLine(const std::shared_ptr<json>& root, json_pointer pointer)
300 {
301 }
302
307 EventLyricLine(Base& parent, const std::string_view& key, const std::string& syllableText)
309 {
310 set_text(syllableText);
311 }
312
313 MNX_REQUIRED_PROPERTY(std::string, text);
315};
316
321class EventLyrics : public Object
322{
323public:
324 using Object::Object;
325
327};
328
333class Event : public ContentObject
334{
335public:
337 Event(const std::shared_ptr<json>& root, json_pointer pointer)
339 {
340 }
341
346 Event(Base& parent, const std::string_view& key, std::optional<NoteValue::Initializer> noteValue = std::nullopt)
347 : ContentObject(parent, key)
348 {
349 // per the specification, either noteValue or the full-measure boolean *must* be supplied.
350 if (noteValue) {
351 create_duration(noteValue.value());
352 } else {
353 set_measure(true);
354 }
355 }
356
368
372 std::optional<Note> findNote(const std::string& noteId) const;
373
375 bool isGrace() const;
376
379 Sequence getSequence() const;
380
381 static constexpr std::string_view ContentTypeValue = ContentObject::ContentTypeValueDefault;
382};
383
388class Space : public ContentObject
389{
390public:
392 Space(const std::shared_ptr<json>& root, json_pointer pointer)
394 {
395 }
396
401 Space(Base& parent, const std::string_view& key, const Fraction::Initializer& duration)
402 : ContentObject(parent, key)
403 {
404 create_duration(duration);
405 }
406
408
409 static constexpr std::string_view ContentTypeValue = "space";
410};
411
416class Grace : public ContentObject
417{
418public:
420 Grace(const std::shared_ptr<json>& root, json_pointer pointer)
422 {
423 }
424
428 Grace(Base& parent, const std::string_view& key)
429 : ContentObject(parent, key)
430 {
431 create_content();
432 }
433
434 MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class");
435 MNX_OPTIONAL_PROPERTY(std::string, color);
439
440 static constexpr std::string_view ContentTypeValue = "grace";
441};
442
447class Tuplet : public ContentObject
448{
449public:
451 Tuplet(const std::shared_ptr<json>& root, json_pointer pointer)
453 {
454 }
455
463 Tuplet(Base& parent, const std::string_view& key,
464 unsigned innerCount, const NoteValue::Initializer& innerNoteValue,
465 unsigned outerCount, const NoteValue::Initializer& outerNoteValue)
466 : ContentObject(parent, key)
467 {
468 create_inner(innerCount, innerNoteValue);
469 create_outer(outerCount, outerNoteValue);
470 create_content();
471 }
472
478 MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(TupletDisplaySetting, showNumber, TupletDisplaySetting::Inner);
479 MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(TupletDisplaySetting, showValue, TupletDisplaySetting::NoNumber);
481
482 static constexpr std::string_view ContentTypeValue = "tuplet";
483};
484
485} // namespace sequence
486
492{
493public:
495 Sequence(const std::shared_ptr<json>& root, json_pointer pointer)
497 {
498 }
499
503 Sequence(Base& parent, const std::string_view& key)
505 {
506 create_content();
507 }
508
512 MNX_OPTIONAL_PROPERTY(std::string, voice);
513};
514
515} // 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
Class for content arrays.
Definition BaseTypes.h:704
Base class for objects that are elements of content arrays.
Definition BaseTypes.h:644
static constexpr std::string_view ContentTypeValueDefault
default type value that identifies the type within the content array
Definition BaseTypes.h:646
Represents an MNX dictionary, where each key is a user-defined string.
Definition BaseTypes.h:773
Represents a fraction of a whole note, for measuring musical time.
Definition CommonClasses.h:34
std::pair< NumType, NumType > Initializer
initializer for Fraction class (numerator, denominator)
Definition CommonClasses.h:43
Represents a quantity of symbolic note values=.
Definition CommonClasses.h:263
initializer class for NoteValue
Definition CommonClasses.h:223
Represents a symbolic note value (not necessarily a duration)
Definition CommonClasses.h:219
Represents an MNX object, encapsulating property access.
Definition BaseTypes.h:421
Object(const std::shared_ptr< json > &root, json_pointer pointer)
Wraps an Object class around an existing JSON object node.
Definition BaseTypes.h:426
A sequence of events and other items in this measure for a voice in a part.
Definition Sequence.h:492
Sequence(Base &parent, const std::string_view &key)
Creates a new Sequence class as a child of a JSON element.
Definition Sequence.h:503
MNX_OPTIONAL_PROPERTY(std::string, voice)
the unique (per measure) voice label for this sequence.
MNX_REQUIRED_CHILD(ContentArray, content)
MNX_OPTIONAL_PROPERTY(int, staff)
the staff number for this sequence
Sequence(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Sequence objects.
Definition Sequence.h:495
Represents an explicit directive to show or hide an accidental.
Definition Sequence.h:70
AccidentalDisplay(Base &parent, const std::string_view &key, bool showAcci)
Creates a new Pitch class as a child of a JSON element.
Definition Sequence.h:82
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, force, false)
Whether this accidental was set intentionally (e.g., a courtesy accidental).
MNX_OPTIONAL_CHILD(AccidentalEnclosure, enclosure)
The enclosure type (brackets or parentheses). Omit if none.
MNX_REQUIRED_PROPERTY(bool, show)
Whether to show or hide the accidental.
AccidentalDisplay(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing AccidentalEnclosure objects.
Definition Sequence.h:73
Represents the enclosure on an accidental.
Definition Sequence.h:44
AccidentalEnclosure(Base &parent, const std::string_view &key, AccidentalEnclosureSymbol inSymbol)
Creates a new Pitch class as a child of a JSON element.
Definition Sequence.h:56
AccidentalEnclosure(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing AccidentalEnclosure objects.
Definition Sequence.h:47
MNX_REQUIRED_PROPERTY(AccidentalEnclosureSymbol, symbol)
The symbol to use for the enclosure.
Contains information about a lyric syllable from one lyric line on a note.
Definition Sequence.h:295
MNX_REQUIRED_PROPERTY(std::string, text)
the syllable text
EventLyricLine(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing EventLyricLine objects.
Definition Sequence.h:298
EventLyricLine(Base &parent, const std::string_view &key, const std::string &syllableText)
Creates a new EventLyricLine class as a child of a JSON element.
Definition Sequence.h:307
MNX_OPTIONAL_PROPERTY(LyricLineType, type)
the type of syllable (in relation to the complete word)
Contains information about the lyric syllables on the event.
Definition Sequence.h:322
MNX_OPTIONAL_CHILD(Dictionary< EventLyricLine >, lines)
the syllables per lyric line
Container for any markings on an event.
Definition EventMarkings.h:177
Represents a musical event within a sequence.
Definition Sequence.h:334
Event(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Event objects.
Definition Sequence.h:337
MNX_OPTIONAL_PROPERTY(StemDirection, stemDirection)
Forced stem direction.
std::optional< Note > findNote(const std::string &noteId) const
Finds a note in the event by its ID.
Definition Implementations.cpp:191
MNX_OPTIONAL_CHILD(Rest, rest)
indicates this event is a rest.
MNX_OPTIONAL_CHILD(Array< Slur >, slurs)
The slurs that start on this event.
bool isGrace() const
Returns true if this event is part of a grace note sequence.
Definition Implementations.cpp:203
Sequence getSequence() const
Returns the Sequence instance for this event.
Definition Implementations.cpp:213
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition Sequence.h:381
MNX_OPTIONAL_CHILD(NoteValue, duration)
Symbolic duration of the event.
MNX_OPTIONAL_CHILD(EventMarkings, markings)
Articulation markings on this event.
Event(Base &parent, const std::string_view &key, std::optional< NoteValue::Initializer > noteValue=std::nullopt)
Creates a new Event class as a child of a JSON element.
Definition Sequence.h:346
MNX_OPTIONAL_CHILD(EventLyrics, lyrics)
The lyric syllables on this event.
MNX_OPTIONAL_CHILD(Array< KitNote >, kitNotes)
KitNote array for percussion kit notation.
MNX_OPTIONAL_PROPERTY(int, staff)
Staff number override (e.g., for cross-staff events.)
MNX_OPTIONAL_CHILD(Array< Note >, notes)
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, measure, false)
Whether this event is a whole-measure event.
Represents a grace note sequence within a sequence.
Definition Sequence.h:417
MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class")
style class
MNX_REQUIRED_CHILD(ContentArray, content)
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition Sequence.h:440
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, slash, true)
whether to show a slash on the grace note
Grace(Base &parent, const std::string_view &key)
Creates a new Grace class as a child of a JSON element.
Definition Sequence.h:428
Grace(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Grace objects.
Definition Sequence.h:420
MNX_OPTIONAL_PROPERTY(std::string, color)
color to use when rendering the grace note sequence
Represents a single note in a (drum) kit within a musical event within a sequence.
Definition Sequence.h:239
KitNote(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Note objects.
Definition Sequence.h:242
MNX_REQUIRED_PROPERTY(std::string, kitComponent)
The ID within the kit for this part.
KitNote(Base &parent, const std::string_view &key, std::string kitComponentId)
Creates a new Note class as a child of a JSON element.
Definition Sequence.h:251
Represents common elements between Note and KitNote.
Definition Sequence.h:224
MNX_OPTIONAL_CHILD(Array< Tie >, ties)
The (forward) ties, if any.
MNX_OPTIONAL_NAMED_PROPERTY(std::string, styleClass, "class")
style class
MNX_OPTIONAL_PROPERTY(int, staff)
Staff number override (e.g., for cross-staff notes.)
Represents a single note (i.e., within a chord) within a musical event within a sequence.
Definition Sequence.h:265
MNX_OPTIONAL_CHILD(AccidentalDisplay, accidentalDisplay)
the forced show/hide state of the accidental
MNX_OPTIONAL_CHILD(TransposeWritten, written)
How to write this note when it is displayed transposed.
Note(Base &parent, const std::string_view &key, NoteStep step, int octave, std::optional< int > alter=std::nullopt)
Creates a new Note class as a child of a JSON element.
Definition Sequence.h:279
MNX_REQUIRED_CHILD(Pitch, pitch)
the pitch of the note
Note(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Note objects.
Definition Sequence.h:268
Represents the pitch of a note.
Definition Sequence.h:122
Pitch(Base &parent, const std::string_view &key, NoteStep inpStep, int inpOctave, std::optional< int > inpAlter=std::nullopt)
Creates a new Pitch class as a child of a JSON element.
Definition Sequence.h:136
Pitch(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Pitch objects.
Definition Sequence.h:125
MNX_OPTIONAL_PROPERTY(int, alter)
chromatic alteration
MNX_REQUIRED_PROPERTY(int, octave)
the octave number
bool isSamePitch(const Pitch &src) const
Checks if the input pitch is the same as this pitch, including enharmonic equivalents.
Definition Implementations.cpp:226
MNX_REQUIRED_PROPERTY(NoteStep, step)
the note step, (i.e., "A".."G")
Represents a rest within a musical event within a sequence.
Definition Sequence.h:98
MNX_OPTIONAL_PROPERTY(int, staffPosition)
The staff position of non-floating rests.
Contains information about a tie on a note.
Definition Sequence.h:161
MNX_OPTIONAL_PROPERTY(SlurTieSide, side)
used to force slur direction (if present)
MNX_OPTIONAL_PROPERTY(SlurTieSide, sideEnd)
used to force slur's endpoint direction (if different than side)
Slur(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Slur objects.
Definition Sequence.h:164
MNX_OPTIONAL_PROPERTY(std::string, startNote)
the specific note ID this slur starts on
MNX_OPTIONAL_PROPERTY(std::string, endNote)
the specific note ID this slur ends on
Slur(Base &parent, const std::string_view &key, const std::string &target)
Creates a new Slur class as a child of a JSON element.
Definition Sequence.h:173
MNX_OPTIONAL_PROPERTY(LineType, lineType)
the type of line for the slur
MNX_REQUIRED_PROPERTY(std::string, target)
the event ID this slur ends on (if present)
Occupies metric space without showing anything.
Definition Sequence.h:389
MNX_REQUIRED_CHILD(Fraction, duration)
Duration of space to occupy.
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition Sequence.h:409
Space(Base &parent, const std::string_view &key, const Fraction::Initializer &duration)
Creates a new Space class as a child of a JSON element.
Definition Sequence.h:401
Space(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Space objects.
Definition Sequence.h:392
Contains information about a tie on a note.
Definition Sequence.h:192
Tie(Base &parent, const std::string_view &key, const std::optional< std::string > &target=std::nullopt)
Creates a new Tie class as a child of a JSON element.
Definition Sequence.h:204
MNX_OPTIONAL_PROPERTY(std::string, target)
the note id of the tied-to note
MNX_OPTIONAL_PROPERTY(SlurTieSide, side)
used to force tie direction (if present)
Tie(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Tie objects.
Definition Sequence.h:195
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(bool, lv, false)
Indicates the presence of an l.v. tie (instead of target)
Represents the options for how a note is written when transposed.
Definition Sequence.h:110
MNX_OPTIONAL_PROPERTY(int, diatonicDelta)
the number of enharmonic transpositions to apply
Represents a tuplet sequence within a sequence.
Definition Sequence.h:448
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(TupletDisplaySetting, showValue, TupletDisplaySetting::NoNumber)
How and whether to show the tuplet note value(s)
MNX_REQUIRED_CHILD(NoteValueQuantity, inner)
Inner quantity: 3 quarters in the time of 2 quarters.
Tuplet(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Tuplet objects.
Definition Sequence.h:451
Tuplet(Base &parent, const std::string_view &key, unsigned innerCount, const NoteValue::Initializer &innerNoteValue, unsigned outerCount, const NoteValue::Initializer &outerNoteValue)
Creates a new Tuplet class as a child of a JSON element.
Definition Sequence.h:463
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition Sequence.h:482
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(AutoYesNo, bracket, AutoYesNo::Auto)
bracket style
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(TupletDisplaySetting, showNumber, TupletDisplaySetting::Inner)
How and whether to show the tuplet number(s)
MNX_OPTIONAL_PROPERTY(int, staff)
Staff number override (e.g., for cross-staff notes.)
MNX_REQUIRED_CHILD(NoteValueQuantity, outer)
MNX_REQUIRED_CHILD(ContentArray, content)
array of events (and tuplets, at least for now)
object model for MNX format
LineType
Specifies the visual style of a line in (specifically) slurs.
Definition Enumerations.h:136
json::json_pointer json_pointer
JSON pointer class for MNX.
Definition BaseTypes.h:198
LyricLineType
The symbols available to bracket a staff group.
Definition Enumerations.h:148
AccidentalEnclosureSymbol
The types of accidental enclosure symbols.
Definition Enumerations.h:31
AutoYesNo
3-state choice enum
Definition Enumerations.h:41
NoteStep
The diatonic note step values.
Definition Enumerations.h:172
SlurTieSide
Specifies the direction of a slur or tie.
Definition Enumerations.h:256
TupletDisplaySetting
Controls display of a tuplet's number or note value.
Definition Enumerations.h:292
StemDirection
The values available in a labelref.
Definition Enumerations.h:266