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
89 Bracket,
90
98
101 ClosePath,
102
105 CurveTo,
106
109 DrawChar,
110
114 Ellipse,
115
118 EndGroup,
119
123
126 FillAlt,
127
130 FillSolid,
131
135
138 GoToStart,
139
142 LineWidth,
143
147 Rectangle,
148
151 RLineTo,
152
155 RMoveTo,
156
161
164 SetBlack,
165
168 SetDash,
169
172 SetFont,
173
176 SetGray,
177
180 SetWhite,
181
185 Slur,
186
190
199
202 Stroke,
203
208 };
209
214 enum class ShapeType
215 {
216 Other = 0,
217 Articulation = 1,
218 Barline = 2,
219 Executable = 3,
220 Expression = 4,
221 CustomStem = 5,
222 Frame = 6,
223 Arrowhead = 7,
224 Fretboard = 8,
225 Clef = 9
226 };
227
231
233 bool isBlank() const
234 { return instructionList == 0; }
235
238 void iterateInstructions(std::function<bool(InstructionType, std::vector<int>)> callback) const;
239
240
243 std::optional<KnownShapeDefType> recognize() const;
244
245 constexpr static std::string_view XmlNodeName = "shapeDef";
247};
248
252{
254 struct LineWidth {
256 };
257
259 struct RLineTo {
262 };
263
264 // add more data structs as needed...
265
270 static std::optional<LineWidth> parseLineWidth(ShapeDef::InstructionType type, const std::vector<int>& data);
271
276 static std::optional<RLineTo> parseRLineTo(ShapeDef::InstructionType type, const std::vector<int>& data);
277
283 static std::optional<FontInfo> parseSetFont(const DocumentWeakPtr& document, ShapeDef::InstructionType type, const std::vector<int>& data);
284
285 // Add more parsers as needed...
286};
287
295{
296public:
298 explicit ShapeInstructionList(const DocumentWeakPtr& document, Cmper partId, ShareMode shareMode, Cmper cmper)
299 : OthersBase(document, partId, shareMode, cmper)
300 {
301 }
302
313
314 std::vector<std::shared_ptr<InstructionInfo>> instructions;
315
316 constexpr static std::string_view XmlNodeName = "shapeList";
318};
319
320} // namespace others
321} // namespace dom
322} // 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:585
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:229
ShapeType
Represents different types of shapes in Finale's Shape Designer.
Definition ShapeDesigner.h:215
@ 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:245
ShapeType shapeType
Shape type (specifies which type of entity this shape pertains to)
Definition ShapeDesigner.h:230
Cmper instructionList
Instruction list Cmper. (xml node is <instList>)
Definition ShapeDesigner.h:228
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:233
An instruction in the shape.
Definition ShapeDesigner.h:305
int numData
the number of data items consumed by this instruction (See ShapeData.)
Definition ShapeDesigner.h:308
static const xml::XmlElementArray< InstructionInfo > & xmlMappingArray()
Required for musx::factory::FieldPopulator.
ShapeDef::InstructionType type
the type of instruction
Definition ShapeDesigner.h:309
Represents the data for instruction associated with a ShapeDef.
Definition ShapeDesigner.h:295
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition ShapeDesigner.h:316
std::vector< std::shared_ptr< InstructionInfo > > instructions
The instructions.
Definition ShapeDesigner.h:314
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:298
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:254
Efix efix
The line width in Efix units.
Definition ShapeDesigner.h:255
Holds the parsed data for an RLineTo instruction.
Definition ShapeDesigner.h:259
Evpu dy
The relative Y coordinate delta in Evpu.
Definition ShapeDesigner.h:261
Evpu dx
The relative X coordinate delta in Evpu.
Definition ShapeDesigner.h:260
Helper functions and structs for decoding instruction data vectors in ShapeDef.
Definition ShapeDesigner.h:252
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