denigma 4.0.0
Loading...
Searching...
No Matches
smartshapes.h
1/*
2 * Copyright (C) 2026, 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 <optional>
25#include <variant>
26
27#include "denigma/classify/classifier_common.h"
28#include "denigma/classify/general_lines.h"
29#include "denigma/classify/keyboard_pedals.h"
30#include "musx/musx.h"
31#include "musx/util/Arpeggio.h"
32
33namespace denigma {
34namespace classify {
35
36namespace smartshape {
37
44struct Ottava
45{
48
52 musx::dom::MusxInstance<musx::dom::others::SmartShape> hiddenCounterpart;
53
57
59 std::optional<GeneralLine> line;
60
63 [[nodiscard]]
64 bool calcIsSemanticCarrier() const noexcept
65 { return !hiddenCounterpart; }
66};
67
71{
72};
73
77{
78};
79
82struct Slur
83{
85 musx::dom::EntryInfoPtr startEntry;
88 musx::dom::EntryInfoPtr endEntry;
90 musx::dom::CurveContourDirection contour{ musx::dom::CurveContourDirection::Unspecified };
91};
92
96{
97 musx::dom::NoteInfoPtr tiedFrom;
98 musx::dom::NoteInfoPtr tiedTo;
100 musx::dom::CurveContourDirection contour{ musx::dom::CurveContourDirection::Unspecified };
101};
102
106{
108 musx::util::ArpeggioSpanCandidate candidate;
109};
110
117{
120 enum class CapType
121 {
122 None,
123 Hook,
124 PedalDown,
125 PedalUp,
127 };
128
131 std::optional<KeyboardPedalClassification> startText;
133 std::optional<KeyboardPedalClassification> continuationText;
135 std::optional<KeyboardPedalClassification> endText;
138
140 [[nodiscard]] bool isUnaCorda() const noexcept;
141
143 [[nodiscard]] bool isSostPedal() const noexcept;
144
146 [[nodiscard]] bool isSustainPedal() const noexcept;
147};
148
152{
153 bool includesTrSymbol{};
154 std::optional<GeneralLine> line;
155};
156
163
164} // namespace smartshape
165
171using SmartShapeValue = std::variant<
172 std::monostate,
178 PseudoTie,
184
188{
191 musx::dom::others::SmartShape::ShapeType shapeType{};
194
197 template <typename T>
198 const T* as() const noexcept
199 { return std::get_if<T>(&value); }
200};
201
206[[nodiscard]]
208 const musx::dom::MusxInstance<musx::dom::others::SmartShape>& shape);
209
216[[nodiscard]]
217std::optional<smartshape::KeyboardPedal> classifyKeyboardPedalCustomLine(
218 const musx::dom::MusxInstance<musx::dom::others::SmartShapeCustomLine>& customLine);
219
220} // namespace classify
221} // namespace denigma
std::variant< std::monostate, smartshape::Ottava, smartshape::Crescendo, smartshape::Decrescendo, smartshape::Slur, smartshape::ArpeggiatedTie, PseudoTie, smartshape::NonArpeggio, smartshape::KeyboardPedal, smartshape::TrillLine, smartshape::VibratoLine, smartshape::GeneralLine > SmartShapeValue
The semantic payload of a classified smart shape.
Definition smartshapes.h:183
std::optional< smartshape::KeyboardPedal > classifyKeyboardPedalCustomLine(const musx::dom::MusxInstance< musx::dom::others::SmartShapeCustomLine > &customLine)
Classifies a custom line style as keyboard pedaling.
SmartShapeClassification classifySmartShape(const musx::dom::MusxInstance< musx::dom::others::SmartShape > &shape)
Classifies a smart shape's meaning.
Core public API for the Denigma conversion libraries.
Definition articulations.h:32
A source shape used as a stand-in for a laissez-vibrer tie or tie end.
Definition classifier_common.h:49
Result returned by smart-shape classification.
Definition smartshapes.h:188
const T * as() const noexcept
Returns the payload when the shape classified as the requested type, otherwise null.
Definition smartshapes.h:198
A slur used to tie one note of a rolled chord to a note in a following chord.
Definition smartshapes.h:96
musx::dom::NoteInfoPtr tiedFrom
The note the tie starts from.
Definition smartshapes.h:97
musx::dom::NoteInfoPtr tiedTo
The note the tie ends on.
Definition smartshapes.h:98
musx::dom::CurveContourDirection contour
The tie's resolved curvature direction.
Definition smartshapes.h:100
A crescendo hairpin.
Definition smartshapes.h:71
A decrescendo hairpin.
Definition smartshapes.h:77
Describes the appearance of a line-type smart shape in musxdom terms.
Definition general_lines.h:66
A custom line that notates keyboard pedaling.
Definition smartshapes.h:117
bool isSustainPedal() const noexcept
Returns whether any text position identifies the sustain pedal.
bool isSostPedal() const noexcept
Returns whether any text position identifies the sostenuto pedal.
bool isUnaCorda() const noexcept
Returns whether any text position identifies the una-corda (soft) pedal.
CapType endCap
Pedal meaning of the cap at the end of the line.
Definition smartshapes.h:137
GeneralLine line
Appearance of the pedal line.
Definition smartshapes.h:129
CapType startCap
Pedal meaning of the cap at the start of the line.
Definition smartshapes.h:136
std::optional< KeyboardPedalClassification > startText
The marking in the line's left-start text, when it names one.
Definition smartshapes.h:131
std::optional< KeyboardPedalClassification > continuationText
The marking in the line's left-continuation text, when it names one.
Definition smartshapes.h:133
std::optional< KeyboardPedalClassification > endText
The marking in the line's right-end text, when it names one.
Definition smartshapes.h:135
CapType
The pedal semantic of a line cap.
Definition smartshapes.h:121
@ None
No cap, or a cap with no pedal meaning.
@ Hook
A plain hook, which brackets the pedaled music without naming a pedal action.
@ PedalChange
The cap releases and immediately re-engages the pedal.
A bracket spanning notes that are explicitly not to be rolled.
Definition smartshapes.h:106
musx::util::ArpeggioSpanCandidate candidate
The notes the bracket spans, as resolved by musxdom.
Definition smartshapes.h:108
An octave-displacement span, from either a built-in ottava shape or a custom line.
Definition smartshapes.h:45
int octaveShift
Octaves the written pitches are displaced: negative sounds below written pitch.
Definition smartshapes.h:47
bool hasVisualProxy
True when this shape is a hidden built-in ottava that is rendered by a visible custom line.
Definition smartshapes.h:56
musx::dom::MusxInstance< musx::dom::others::SmartShape > hiddenCounterpart
When this shape is a custom line whose octave semantics are carried by a hidden built-in ottava cover...
Definition smartshapes.h:52
std::optional< GeneralLine > line
Appearance, when this shape is a custom line. (Empty for built-in ottavas.)
Definition smartshapes.h:59
bool calcIsSemanticCarrier() const noexcept
True when this shape carries the octave-displacement semantics.
Definition smartshapes.h:64
A slur between two entries.
Definition smartshapes.h:83
musx::dom::EntryInfoPtr startEntry
The entry at the slur's start, or null when the endpoint coincides with no entry.
Definition smartshapes.h:85
musx::dom::EntryInfoPtr endEntry
The entry at the slur's end, or null when the endpoint coincides with no entry.
Definition smartshapes.h:88
musx::dom::CurveContourDirection contour
The slur's resolved curvature direction.
Definition smartshapes.h:90
A trill, with or without an extension line.
Definition smartshapes.h:152
std::optional< GeneralLine > line
Appearance, when the source is a custom line. (Empty for built-in trills.)
Definition smartshapes.h:154
A vibrato (wavy) line.
Definition smartshapes.h:160
GeneralLine line
Appearance of the vibrato line. (Always a custom line.)
Definition smartshapes.h:161