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 {
66 return !hiddenCounterpart;
67 }
68};
69
73{};
74
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 None,
122 Hook,
123 PedalDown,
124 PedalUp,
126 };
127
130 std::optional<KeyboardPedalClassification> startText;
132 std::optional<KeyboardPedalClassification> continuationText;
134 std::optional<KeyboardPedalClassification> endText;
137
139 [[nodiscard]] bool isUnaCorda() const noexcept;
140
142 [[nodiscard]] bool isSostPedal() const noexcept;
143
145 [[nodiscard]] bool isSustainPedal() const noexcept;
146};
147
151{
152 bool includesTrSymbol{};
153 std::optional<GeneralLine> line;
154};
155
162
177{
178 musx::dom::NoteInfoPtr startNote;
179 musx::dom::NoteInfoPtr endNote;
181};
182
183} // namespace smartshape
184
193
197{
200 musx::dom::others::SmartShape::ShapeType shapeType{};
203
206 template <typename T>
207 const T* as() const noexcept
208 {
209 return std::get_if<T>(&value);
210 }
211};
212
217[[nodiscard]]
218SmartShapeClassification classifySmartShape(const musx::dom::MusxInstance<musx::dom::others::SmartShape>& shape);
219
226[[nodiscard]]
227std::optional<smartshape::KeyboardPedal> classifyKeyboardPedalCustomLine(
228 const musx::dom::MusxInstance<musx::dom::others::SmartShapeCustomLine>& customLine);
229
230} // namespace classify
231} // 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::Glissando, smartshape::GeneralLine > SmartShapeValue
The semantic payload of a classified smart shape.
Definition smartshapes.h:192
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:33
A source shape used as a stand-in for a laissez-vibrer tie or tie end.
Definition classifier_common.h:48
Result returned by smart-shape classification.
Definition smartshapes.h:197
const T * as() const noexcept
Returns the payload when the shape classified as the requested type, otherwise null.
Definition smartshapes.h:207
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:73
A decrescendo hairpin.
Definition smartshapes.h:78
Describes the appearance of a line-type smart shape in musxdom terms.
Definition general_lines.h:66
A pitch-motion line drawn from one note to another.
Definition smartshapes.h:177
GeneralLine line
Appearance of the line.
Definition smartshapes.h:180
musx::dom::NoteInfoPtr endNote
The note the line ends on. May be a grace note.
Definition smartshapes.h:179
musx::dom::NoteInfoPtr startNote
The note the line starts from.
Definition smartshapes.h:178
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:136
GeneralLine line
Appearance of the pedal line.
Definition smartshapes.h:128
CapType startCap
Pedal meaning of the cap at the start of the line.
Definition smartshapes.h:135
std::optional< KeyboardPedalClassification > startText
The marking in the line's left-start text, when it names one.
Definition smartshapes.h:130
std::optional< KeyboardPedalClassification > continuationText
The marking in the line's left-continuation text, when it names one.
Definition smartshapes.h:132
std::optional< KeyboardPedalClassification > endText
The marking in the line's right-end text, when it names one.
Definition smartshapes.h:134
CapType
The pedal semantic of a line cap.
Definition smartshapes.h:120
@ 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:151
std::optional< GeneralLine > line
Appearance, when the source is a custom line. (Empty for built-in trills.)
Definition smartshapes.h:153
A vibrato (wavy) line.
Definition smartshapes.h:159
GeneralLine line
Appearance of the vibrato line. (Always a custom line.)
Definition smartshapes.h:160