MNX Document Model
Loading...
Searching...
No Matches
Layout.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 "Enumerations.h"
25#include "BaseTypes.h"
26#include "ContentArray.h"
27
28namespace mnx {
29
34namespace layout {
35class Group;
36class Staff;
37
38class LayoutContentObject : public ContentObject<LayoutContentObject>
39{
40public:
41 using ContentObject::ContentObject;
42 std::string_view defaultType() const override { return ""; }
43};
44
45class LayoutContent : public ContentArray<LayoutContentObject>
46{
47public:
48 using ContentArray<LayoutContentObject>::ContentArray;
49
50 Group appendGroup();
51 Staff appendStaff();
52};
53
59{
60public:
62 struct Required
63 {
64 std::string partId;
65 };
66
68 StaffSource(const std::shared_ptr<json>& root, json_pointer pointer)
70 {
71 }
72
77 StaffSource(Base& parent, std::string_view key, const std::string& partId)
79 {
80 set_part(partId);
81 }
82
84 operator Required() const { return { part() }; }
85
87 static Required make(const std::string& partId) { return { partId }; }
88
89 MNX_OPTIONAL_PROPERTY(std::string, label);
91 MNX_REQUIRED_PROPERTY(std::string, part);
94 MNX_OPTIONAL_PROPERTY(std::string, voice);
95};
96
102{
103public:
104 using LayoutContentObject::LayoutContentObject;
105
109 Staff(Base& parent, std::string_view key)
111 {
112 // required children
113 create_sources();
114 }
115
116 MNX_OPTIONAL_PROPERTY(std::string, label);
120
121 inline static constexpr std::string_view ContentTypeValue = "staff";
122};
123
129{
130public:
131 using LayoutContentObject::LayoutContentObject;
132
136 Group(Base& parent, std::string_view key)
138 {
139 // required children
140 create_content();
141 }
142
145 MNX_OPTIONAL_PROPERTY(std::string, label);
147
149 [[nodiscard]] bool calcIsPartGroup() const;
150
153
154 inline static constexpr std::string_view ContentTypeValue = "group";
155};
156
157inline Group LayoutContent::appendGroup()
158{ return appendWithType<Group>(); }
159
160inline Staff LayoutContent::appendStaff()
161{ return appendWithType<Staff>(); }
162
163} // namespace layout
164
170{
171public:
172 using ArrayElementObject::ArrayElementObject;
173
177 Layout(Base& parent, std::string_view key)
179 {
180 // required children
181 create_content();
182 }
183
185
186 inline static constexpr std::string_view JsonSchemaTypeName = "system-layout";
187};
188
189} // 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
Class for content arrays.
Definition ContentArray.h:49
Base class for objects that are elements of content arrays.
Definition BaseTypes.h:742
Represents the element of the layout array in an MNX document.
Definition Layout.h:170
MNX_REQUIRED_CHILD(layout::LayoutContent, content)
Required child containing the layout content (groups and staves).
Layout(Base &parent, std::string_view key)
Creates a new Layout class as a child of a JSON element.
Definition Layout.h:177
static constexpr std::string_view JsonSchemaTypeName
required for mapping
Definition Layout.h:186
Represents a groups of staves within an MNX layout.
Definition Layout.h:129
MNX_REQUIRED_CHILD(LayoutContent, content)
Required child containing the layout content (groups and staves).
StaffGroupBarlineOverride calcBarlineOverride() const
Calculates the effective barline override.
Definition Implementations.cpp:642
bool calcIsPartGroup() const
Calculates whether all staves in this group subtree use the same part id.
Definition Implementations.cpp:598
MNX_OPTIONAL_PROPERTY(LayoutSymbol, symbol)
The symbol down the left side.
Group(Base &parent, std::string_view key)
Creates a new Group class as a child of a JSON element.
Definition Layout.h:136
MNX_OPTIONAL_PROPERTY(std::string, label)
Label to be rendered to the left of the group.
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(StaffGroupBarlineStyle, barlineStyle, StaffGroupBarlineStyle::Instrument)
barline override settings
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition Layout.h:154
Definition Layout.h:39
Definition Layout.h:46
Represents a staff source for a staff in a layout in a score.
Definition Layout.h:59
static Required make(const std::string &partId)
Create a Required instance for StaffSource.
Definition Layout.h:87
MNX_OPTIONAL_PROPERTY(std::string, label)
Text to appear to the left of the staff.
MNX_OPTIONAL_PROPERTY(StemDirection, stem)
The stem direction for this staff source.
MNX_OPTIONAL_PROPERTY(std::string, voice)
The voice id to draw from.
StaffSource(Base &parent, std::string_view key, const std::string &partId)
Creates a new StaffSource class as a child of a JSON element.
Definition Layout.h:77
StaffSource(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing staff sources.
Definition Layout.h:68
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(int, staff, 1)
The staff number within the part.
MNX_OPTIONAL_PROPERTY(LabelRef, labelref)
The labelref to use (rather than label)
MNX_REQUIRED_PROPERTY(std::string, part)
Id of the part to draw from.
Represents a single staff instance within an MNX layout.
Definition Layout.h:102
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition Layout.h:121
MNX_REQUIRED_CHILD(Array< StaffSource >, sources)
The sources for this staff.
Staff(Base &parent, std::string_view key)
Creates a new Staff class as a child of a JSON element.
Definition Layout.h:109
MNX_OPTIONAL_PROPERTY(LabelRef, labelref)
The labelref to use (rather than label)
MNX_OPTIONAL_PROPERTY(LayoutSymbol, symbol)
The symbol down the left side.
MNX_OPTIONAL_PROPERTY(std::string, label)
Label to be rendered to the left of the staff.
object model for MNX format
StaffGroupBarlineOverride
Resolved barline override setting for a layout staff group.
Definition Enumerations.h:404
json::json_pointer json_pointer
JSON pointer class for MNX.
Definition BaseTypes.h:68
LayoutSymbol
The symbols available to bracket a staff group.
Definition Enumerations.h:222
LabelRef
The values available in a labelref.
Definition Enumerations.h:212
StemDirection
The values available in a labelref.
Definition Enumerations.h:415
StaffGroupBarlineStyle
The types of barline overrides for staff groups in layouts.
Definition Enumerations.h:390
@ Instrument
currently interpreted as no override or unified, depending on whether the group is single- or multi-i...
initializer class for StaffSource
Definition Layout.h:63
std::string partId
the part to use as a source
Definition Layout.h:64