MUSX Document Model
Loading...
Searching...
No Matches
ShapeDesigner.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 "musx/util/Logger.h"
25#include "musx/util/Fraction.h"
26
27#include "BaseClasses.h"
28#include "CommonClasses.h"
29
30 // do not add other dom class dependencies. Use Implementations.cpp for implementations that need total class access.
31
32namespace musx {
33namespace dom {
34
38{
39 Blank,
41
42 // Add more known types here
43};
44
45namespace others {
46
53class ShapeData : public OthersArray<int>
54{
55 std::string_view xmlTag() const override { return XmlNodeName; }
56
57public:
59
60 constexpr static std::string_view XmlNodeName = "shapeData";
62};
63
71class ShapeDef : public OthersBase
72{
73public:
75 explicit ShapeDef(const DocumentWeakPtr& document, Cmper partId, ShareMode shareMode, Cmper cmper)
76 : OthersBase(document, partId, shareMode, cmper)
77 {
78 }
79
82 enum class InstructionType
83 {
86
91 Bracket,
92
100
103 ClosePath,
104
107 CurveTo,
108
111 DrawChar,
112
116 Ellipse,
117
120 EndGroup,
121
125
128 FillAlt,
129
132 FillSolid,
133
137
140 GoToStart,
141
144 LineWidth,
145
149 Rectangle,
150
153 RLineTo,
154
157 RMoveTo,
158
163
166 SetBlack,
167
170 SetDash,
171
174 SetFont,
175
178 SetGray,
179
182 SetWhite,
183
187 Slur,
188
192
201
204 Stroke,
205
210 };
211
216 enum class ShapeType
217 {
218 Other = 0,
219 Articulation = 1,
220 Barline = 2,
221 Executable = 3,
222 Expression = 4,
223 CustomStem = 5,
224 Frame = 6,
225 Arrowhead = 7,
226 Fretboard = 8,
227 Clef = 9
228 };
229
233
235 bool isBlank() const
236 { return instructionList == 0; }
237
240 void iterateInstructions(std::function<bool(InstructionType, std::vector<int>)> callback) const;
241
242
245 std::optional<KnownShapeDefType> recognize() const;
246
247 constexpr static std::string_view XmlNodeName = "shapeDef";
249};
250
254{
256 struct LineWidth {
258 };
259
261 struct RLineTo {
264 };
265
266 // add more data structs as needed...
267
272 static std::optional<LineWidth> parseLineWidth(ShapeDef::InstructionType type, const std::vector<int>& data);
273
278 static std::optional<RLineTo> parseRLineTo(ShapeDef::InstructionType type, const std::vector<int>& data);
279
285 static std::optional<FontInfo> parseSetFont(const DocumentWeakPtr& document, ShapeDef::InstructionType type, const std::vector<int>& data);
286
287 // Add more parsers as needed...
288};
289
297{
298public:
300 explicit ShapeInstructionList(const DocumentWeakPtr& document, Cmper partId, ShareMode shareMode, Cmper cmper)
301 : OthersBase(document, partId, shareMode, cmper)
302 {
303 }
304
315
316 std::vector<std::shared_ptr<InstructionInfo>> instructions;
317
318 constexpr static std::string_view XmlNodeName = "shapeList";
320};
321
322} // namespace others
323} // namespace dom
324} // namespace musx
ShareMode
Describes how this instance is shared between part and score.
Definition BaseClasses.h:91
Template pattern for OthersBase items consisting of an array of a single item.
Definition BaseClasses.h:353
OthersArray(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper cmper)
Constructor function.
Definition BaseClasses.h:359
Base class for all "others" types.
Definition BaseClasses.h:283
Represents the attributes of a TGF entry frame.
Definition Others.h:592
Represents the data for instruction associated with a ShapeDef.
Definition ShapeDesigner.h:54
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition ShapeDesigner.h:60
static const xml::XmlElementArray< ShapeData > & xmlMappingArray()
Required for musx::factory::FieldPopulator.
Represents a shape created in Finale's Shape Designer.
Definition ShapeDesigner.h:72
Cmper dataList
Instruction data list Cmper.
Definition ShapeDesigner.h:231
ShapeType
Represents different types of shapes in Finale's Shape Designer.
Definition ShapeDesigner.h:217
@ Executable
Corresponds to "executable" in XML.
@ Clef
Corresponds to "clef" in XML.
@ Other
May Correspond to "other" in XML (but may not appear in XML). All pre-Fin2k shapes use this value.
@ CustomStem
Corresponds to "note" in XML.
@ Expression
Corresponds to "expression" in XML.
@ Articulation
Corresponds to "articulation" in XML.
@ Barline
Corresponds to "barline" in XML.
@ Arrowhead
Corresponds to "arrowhead" in XML.
@ Fretboard
Corresponds to "fretboard" in XML.
ShapeDef(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper cmper)
Constructor function.
Definition ShapeDesigner.h:75
std::optional< KnownShapeDefType > recognize() const
Determine if this is a recognized shape type.
Definition ShapeDesigner.cpp:81
void iterateInstructions(std::function< bool(InstructionType, std::vector< int >)> callback) const
Iterates through the instructions in the shape.
Definition ShapeDesigner.cpp:92
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition ShapeDesigner.h:247
ShapeType shapeType
Shape type (specifies which type of entity this shape pertains to)
Definition ShapeDesigner.h:232
Cmper instructionList
Instruction list Cmper. (xml node is <instList>)
Definition ShapeDesigner.h:230
static const xml::XmlElementArray< ShapeDef > & xmlMappingArray()
Required for musx::factory::FieldPopulator.
InstructionType
Defines the instruction types for Shape Designer shapes.
Definition ShapeDesigner.h:83
@ Undocumented
catch-all for possible undocumented instruction tags.
bool isBlank() const
Returns true if this shape does not draw anything.
Definition ShapeDesigner.h:235
An instruction in the shape.
Definition ShapeDesigner.h:307
int numData
the number of data items consumed by this instruction (See ShapeData.)
Definition ShapeDesigner.h:310
static const xml::XmlElementArray< InstructionInfo > & xmlMappingArray()
Required for musx::factory::FieldPopulator.
ShapeDef::InstructionType type
the type of instruction
Definition ShapeDesigner.h:311
Represents the data for instruction associated with a ShapeDef.
Definition ShapeDesigner.h:297
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition ShapeDesigner.h:318
std::vector< std::shared_ptr< InstructionInfo > > instructions
The instructions.
Definition ShapeDesigner.h:316
static const xml::XmlElementArray< ShapeInstructionList > & xmlMappingArray()
Required for musx::factory::FieldPopulator.
ShapeInstructionList(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper cmper)
Constructor function.
Definition ShapeDesigner.h:300
KnownShapeDefType
Enumerates the shape types we can recognize semantically.
Definition ShapeDesigner.h:38
@ TenutoMark
A horizontal tenuto mark, typically used as an articulation symbol.
int32_t Efix
EFIX value (64 per EVPU, 64*288=18432 per inch)
Definition Fundamentals.h:60
int32_t Evpu
EVPU value (288 per inch)
Definition Fundamentals.h:57
uint16_t Cmper
Enigma "comperator" key type.
Definition Fundamentals.h:55
@ Blank
Blank clef (invisible, no symbol).
std::weak_ptr< Document > DocumentWeakPtr
Shared weak Document pointer.
Definition BaseClasses.h:57
std::vector< XmlElementDescriptor< T > > XmlElementArray
an array type for XmlElementDescriptor instances.
Definition XmlInterface.h:127
object model for musx file (enigmaxml)
Definition BaseClasses.h:36
Holds the parsed data for a LineWidth instruction.
Definition ShapeDesigner.h:256
Efix efix
The line width in Efix units.
Definition ShapeDesigner.h:257
Holds the parsed data for an RLineTo instruction.
Definition ShapeDesigner.h:261
Evpu dy
The relative Y coordinate delta in Evpu.
Definition ShapeDesigner.h:263
Evpu dx
The relative X coordinate delta in Evpu.
Definition ShapeDesigner.h:262
Helper functions and structs for decoding instruction data vectors in ShapeDef.
Definition ShapeDesigner.h:254
static std::optional< RLineTo > parseRLineTo(ShapeDef::InstructionType type, const std::vector< int > &data)
Attempts to parse an RLineTo instruction.
Definition ShapeDesigner.cpp:123
static std::optional< LineWidth > parseLineWidth(ShapeDef::InstructionType type, const std::vector< int > &data)
Attempts to parse a LineWidth instruction.
Definition ShapeDesigner.cpp:116
static std::optional< FontInfo > parseSetFont(const DocumentWeakPtr &document, ShapeDef::InstructionType type, const std::vector< int > &data)
Attempts to parse a SetFont instruction into a FontInfo object.
Definition ShapeDesigner.cpp:130