denigma 4.0.0
Loading...
Searching...
No Matches
expressions.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 <cassert>
25#include <cstddef>
26#include <optional>
27#include <stdexcept>
28#include <string>
29#include <string_view>
30#include <variant>
31#include <vector>
32
33#include "denigma/classify/articulations.h"
34#include "denigma/classify/dynamics.h"
35#include "denigma/classify/classifier_common.h"
36#include "denigma/classify/keyboard_pedals.h"
37#include "musx/musx.h"
38
39namespace denigma {
40namespace classify {
41
43using ExpressionCategoryType = musx::dom::others::MarkingCategory::CategoryType;
44
68
79
80namespace expression {
81
85{
88 enum class Type
89 {
90 None,
91 Arco,
92 Pizzicato,
93 ColLegno,
97 SulTasto,
98 Flautando,
99 Ordinario,
100 Mute,
102 CupMute,
103 HarmonMute,
105 BucketMute,
107 StopMute,
108 Stopped,
109 Open,
110 Other
111 };
112
116 std::string text;
117};
118
122{
124 std::string text;
129};
130
134{
137};
138
142{
146 musx::dom::NoteType noteType{ musx::dom::NoteType::Quarter };
148 std::string noteGlyphName;
150 std::size_t augmentationDots{};
153};
154
162
166{
170 std::optional<std::string> glyphName;
175};
176
180{
184 std::optional<std::string> glyphName;
185};
186
215
219{
221 musx::util::ArpeggioSpanCandidate candidate;
222};
223
227{
229 std::string text;
230};
231
240{
242 int number{};
243};
244
253{
255 int count{};
256};
257
261{
263 std::string text;
264};
265
269{
271 dynamics::Change change{ dynamics::Change::Absolute };
273 std::string text;
274};
275
278struct Error
279{
281 std::string message;
282};
283
287{
288};
289
291using RunValue = std::variant<
294
298{
300 musx::util::EnigmaTextChunk chunk;
304 RunValue value{};
305
309 template <typename T>
310 const T* as() const noexcept
311 { return std::get_if<T>(&value); }
312};
313
314} // namespace expression
315
317using ExpressionValue = std::variant<
323
327{
333 std::optional<musx::util::EnigmaParsingContext> enigmaCtx;
337 std::vector<expression::RunClassification> runs;
338
342 template <typename T>
343 const T* as() const noexcept
344 { return std::get_if<T>(&value); }
345
346private:
347 template <typename T, ExpressionType EnumVal>
348 const T& checkedPayload(const char* enumDesc) const
349 {
350 assert(type == EnumVal);
351 if (type != EnumVal) {
352 throw std::logic_error(std::string("ExpressionClassification type is not ") + enumDesc + ".");
353 }
354 return std::get<T>(value);
355 }
356
357public:
358
361 const dynamics::Mark& dynamic() const
362 { return checkedPayload<dynamics::Mark, ExpressionType::Dynamic>("Dynamic"); }
363
367 { return checkedPayload<expression::Fermata, ExpressionType::Fermata>("Fermata"); }
368
372 { return checkedPayload<expression::BreathMark, ExpressionType::BreathMark>("BreathMark"); }
373
377 { return checkedPayload<articulation::StringMute, ExpressionType::StringMute>("StringMute"); }
378
382 { return checkedPayload<expression::HarpDiagram, ExpressionType::HarpDiagram>("HarpDiagram"); }
383
386 keyboardpedal::Type keyboardPedal() const
387 { return checkedPayload<keyboardpedal::Type, ExpressionType::KeyboardPedal>("KeyboardPedal"); }
388
391 const PseudoTie& pseudoTie() const
392 { return checkedPayload<PseudoTie, ExpressionType::PseudoTie>("PseudoTie"); }
393
397 { return checkedPayload<expression::NonArpeggio, ExpressionType::NonArpeggio>("NonArpeggio"); }
398
402 { return checkedPayload<expression::TempoText, ExpressionType::TempoMark>("TempoText"); }
403
407 { return checkedPayload<expression::MetronomeMark, ExpressionType::MetronomeMark>("MetronomeMark"); }
408
412 { return checkedPayload<expression::TempoAlteration, ExpressionType::TempoAlteration>("TempoAlteration"); }
413
417 { return checkedPayload<expression::TechniqueText, ExpressionType::TechniqueText>("TechniqueText"); }
418
422 { return checkedPayload<expression::RehearsalMark, ExpressionType::RehearsalMark>("RehearsalMark"); }
423
427 { return checkedPayload<expression::MultimeasureRestNumber, ExpressionType::MultimeasureRestNumber>("MultimeasureRestNumber"); }
428
432 { return checkedPayload<expression::MeasureRepeatCount, ExpressionType::MeasureRepeatCount>("MeasureRepeatCount"); }
433
437 { return checkedPayload<expression::GenericText, ExpressionType::GenericText>("GenericText"); }
438
442 { return checkedPayload<expression::Error, ExpressionType::Error>("Error"); }
443};
444
448{
450 musx::dom::MusxInstance<musx::dom::others::MeasureExprAssign> assignment;
453};
454
459 const musx::dom::MusxInstance<musx::dom::others::MeasureExprAssign>& assignment);
460
464std::vector<ExpressionAssignmentClassification> classifyExpressionAssignments(
465 const musx::dom::MusxInstanceList<musx::dom::others::MeasureExprAssign>& assignments);
466
472 const musx::dom::MusxInstance<musx::dom::others::TextExpressionDef>& def,
473 const musx::dom::MusxInstance<musx::dom::others::MeasureExprAssign>& assignment = {});
474
480 const musx::dom::MusxInstance<musx::dom::others::ShapeExpressionDef>& def,
481 const musx::dom::MusxInstance<musx::dom::others::MeasureExprAssign>& assignment = {});
482
483} // namespace classify
484} // namespace denigma
musx::dom::others::MarkingCategory::CategoryType ExpressionCategoryType
Finale marking-category type used while classifying expressions.
Definition expressions.h:43
std::vector< ExpressionAssignmentClassification > classifyExpressionAssignments(const musx::dom::MusxInstanceList< musx::dom::others::MeasureExprAssign > &assignments)
Classifies a list of Finale measure-expression assignments.
std::variant< std::monostate, dynamics::Mark, expression::Fermata, expression::BreathMark, articulation::StringMute, expression::HarpDiagram, keyboardpedal::Type, PseudoTie, expression::NonArpeggio, expression::TempoText, expression::MetronomeMark, expression::TempoAlteration, expression::TechniqueText, expression::RehearsalMark, expression::MultimeasureRestNumber, expression::MeasureRepeatCount, expression::GenericText, expression::Error, expression::Suppress > ExpressionValue
Semantic payload associated with an ExpressionClassification.
Definition expressions.h:322
ClassificationBasis
Diagnostic reason for the selected expression classification.
Definition expressions.h:72
@ Heuristic
Classification was inferred without a usable Finale category.
@ FinaleCategory
Classification follows the assigned Finale category.
@ FallbackToGenericText
No specialized classification matched the expression.
@ FinaleCategoryConfirmed
Content analysis confirmed the assigned Finale category.
@ FinaleCategoryCorrected
Content analysis overrode the assigned Finale category.
ExpressionType
Exporter-neutral semantic classes for Finale/MUSX text expressions.
Definition expressions.h:48
@ RehearsalMark
A rehearsal mark.
@ BreathMark
A breath-mark symbol.
@ MetronomeMark
A standalone metronome-note equation.
@ TechniqueText
Text identifying a performance technique.
@ StringMute
A string-mute on/off symbol.
@ KeyboardPedal
A keyboard-pedal marking.
@ HarpDiagram
A harp-pedal diagram.
@ TempoAlteration
A relative tempo alteration.
@ Suppress
An expression that should not be exported.
@ Error
An expression that could not be classified because of invalid source data.
@ MeasureRepeatCount
A count of the iterations of a measure repeat.
@ NonArpeggio
A shape expression used as a non-arpeggio sign.
@ MultimeasureRestNumber
A numeric label for a multimeasure rest.
@ TempoMark
A tempo indication.
@ GenericText
Text with no more specific recognized semantic.
ExpressionClassification classifyExpression(const musx::dom::MusxInstance< musx::dom::others::MeasureExprAssign > &assignment)
Classifies the expression referenced by a Finale measure-expression assignment.
Core public API for the Denigma conversion libraries.
Definition articulations.h:32
Classification paired with the Finale measure-expression assignment that produced it.
Definition expressions.h:448
musx::dom::MusxInstance< musx::dom::others::MeasureExprAssign > assignment
Source measure-expression assignment.
Definition expressions.h:450
ExpressionClassification classification
Semantic classification of the assigned expression.
Definition expressions.h:452
Exporter-neutral semantic classification of one Finale expression.
Definition expressions.h:327
std::vector< expression::RunClassification > runs
Per-run classifications for expressions containing mixed content.
Definition expressions.h:337
const expression::GenericText & genericText() const
Returns the unclassified expression text.
Definition expressions.h:436
ClassificationBasis basis
Evidence used to select type and value.
Definition expressions.h:331
const PseudoTie & pseudoTie() const
Returns the classified pseudo-tie.
Definition expressions.h:391
const expression::BreathMark & breathMark() const
Returns the classified breath mark.
Definition expressions.h:371
const expression::RehearsalMark & rehearsalMark() const
Returns the classified rehearsal mark.
Definition expressions.h:421
ExpressionValue value
Semantic payload associated with type.
Definition expressions.h:335
std::optional< musx::util::EnigmaParsingContext > enigmaCtx
Parsing context retained when the source contains Enigma text commands.
Definition expressions.h:333
const expression::MetronomeMark & metronomeMark() const
Returns the classified standalone metronome marking.
Definition expressions.h:406
const expression::TechniqueText & techniqueText() const
Returns the classified performance-technique text.
Definition expressions.h:416
const expression::TempoAlteration & tempoAlteration() const
Returns the classified relative tempo alteration.
Definition expressions.h:411
const dynamics::Mark & dynamic() const
Returns the classified dynamic mark.
Definition expressions.h:361
const articulation::StringMute & stringMute() const
Returns the classified string-mute symbol.
Definition expressions.h:376
const expression::TempoText & tempoText() const
Returns the classified absolute tempo indication.
Definition expressions.h:401
keyboardpedal::Type keyboardPedal() const
Returns the classified keyboard-pedal marking.
Definition expressions.h:386
const expression::NonArpeggio & nonArpeggio() const
Returns the classified non-arpeggio sign.
Definition expressions.h:396
ExpressionType type
Top-level semantic class.
Definition expressions.h:329
const expression::HarpDiagram & harpDiagram() const
Returns the classified harp-pedal diagram.
Definition expressions.h:381
const expression::Error & error() const
Returns the classification diagnostic.
Definition expressions.h:441
const expression::MeasureRepeatCount & measureRepeatCount() const
Returns the classified measure repeat count.
Definition expressions.h:431
const expression::Fermata & fermata() const
Returns the classified fermata.
Definition expressions.h:366
const expression::MultimeasureRestNumber & multimeasureRestNumber() const
Returns the classified multimeasure rest number.
Definition expressions.h:426
const T * as() const noexcept
Returns the payload as T when it contains that type.
Definition expressions.h:343
Visual style encoded by the source glyph variant.
Definition classifier_common.h:32
A source shape used as a stand-in for a laissez-vibrer tie or tie end.
Definition classifier_common.h:49
Classification for breath marks.
Definition articulations.h:224
Classification for fermata articulation marks.
Definition articulations.h:187
Classification for a string mute on/off symbol.
Definition articulations.h:149
Dynamic metadata attached to a source text run.
Definition dynamics.h:149
Breath-mark expression and its resolved source glyph.
Definition expressions.h:180
articulation::BreathMark breathMark
Semantic breath-mark classification.
Definition expressions.h:182
std::optional< std::string > glyphName
SMuFL glyph name when the source glyph can be resolved.
Definition expressions.h:184
Text run that qualifies a neighboring dynamic mark.
Definition expressions.h:269
std::string text
Source display text.
Definition expressions.h:273
dynamics::Change change
Dynamic change indicated by the qualifier.
Definition expressions.h:271
Classification failure caused by invalid or unsupported source data.
Definition expressions.h:279
std::string message
Human-readable diagnostic.
Definition expressions.h:281
Fermata expression and its source-specific display properties.
Definition expressions.h:166
articulation::Fermata fermata
Semantic fermata classification.
Definition expressions.h:168
std::optional< std::string > glyphName
SMuFL glyph name when the source glyph can be resolved.
Definition expressions.h:170
bool isRightBarline
Whether the fermata is assigned to the right barline.
Definition expressions.h:174
GlyphStyle glyphStyle
Visual style encoded by the source glyph.
Definition expressions.h:172
Expression text without a more specific semantic classification.
Definition expressions.h:261
std::string text
Source display text.
Definition expressions.h:263
Seven-pedal state encoded by a Finale harp-pedal diagram.
Definition expressions.h:190
PedalPosition b
B-pedal position.
Definition expressions.h:205
PedalPosition c
C-pedal position.
Definition expressions.h:203
PedalPosition a
A-pedal position.
Definition expressions.h:213
PedalPosition d
D-pedal position.
Definition expressions.h:201
PedalPosition e
E-pedal position.
Definition expressions.h:207
PedalPosition
Notated position of one harp pedal.
Definition expressions.h:194
PedalPosition g
G-pedal position.
Definition expressions.h:211
PedalPosition f
F-pedal position.
Definition expressions.h:209
Classified count of the iterations of a measure repeat.
Definition expressions.h:253
int count
Iteration number displayed by the marking.
Definition expressions.h:255
A standalone metronome-note equation.
Definition expressions.h:142
int displayedBeatsPerMinute
Number displayed to the right of the equals sign.
Definition expressions.h:152
std::string noteGlyphName
Canonical SMuFL name of the metronome-note glyph.
Definition expressions.h:148
std::size_t augmentationDots
Number of augmentation dots following the note.
Definition expressions.h:150
TempoInfo tempo
Source text and any independently configured Finale playback values.
Definition expressions.h:144
musx::dom::NoteType noteType
Undotted semantic value of the displayed metronome note.
Definition expressions.h:146
Classified numeric label for a multimeasure rest.
Definition expressions.h:240
int number
Measure count displayed by the marking.
Definition expressions.h:242
Shape expression recognized as a non-arpeggio sign.
Definition expressions.h:219
musx::util::ArpeggioSpanCandidate candidate
Source candidate describing the vertical arpeggio span.
Definition expressions.h:221
Classified rehearsal-mark text.
Definition expressions.h:227
std::string text
Display text of the rehearsal mark.
Definition expressions.h:229
Classification of one logical run within an expression.
Definition expressions.h:298
const T * as() const noexcept
Returns the payload as T when it contains that type.
Definition expressions.h:310
RunValue value
Semantic payload for this run.
Definition expressions.h:304
musx::util::EnigmaTextChunk chunk
Parsed Finale text chunk represented by this run.
Definition expressions.h:300
ClassificationBasis basis
Evidence used to select value.
Definition expressions.h:302
Marker payload for an expression that should not be exported.
Definition expressions.h:287
Classified text identifying a performance technique.
Definition expressions.h:85
Type type
Semantic technique identified by the classifier.
Definition expressions.h:114
std::string text
Source display text.
Definition expressions.h:116
Type
Common performance technique text values recognized by the classifier.
Definition expressions.h:89
@ ColLegno
Unqualified col legno technique.
@ ColLegnoTratto
Draw the wood of the bow across the string.
@ Other
A recognized technique not represented by another value.
@ ColLegnoBattuto
Strike the string with the wood of the bow.
@ Stopped
Use the stopped-horn technique.
@ Open
Return to an open or unmuted technique.
Classified relative tempo alteration.
Definition expressions.h:158
TempoInfo tempo
Tempo text and any associated playback values.
Definition expressions.h:160
Text and playback data associated with a tempo expression.
Definition expressions.h:122
std::string text
Source display text.
Definition expressions.h:124
int beatUnitEdu
Finale EDU duration of one playback beat, or zero when unspecified.
Definition expressions.h:128
int beatsPerMinute
Finale playback tempo in beats per minute, or zero when unspecified.
Definition expressions.h:126
Classified absolute tempo indication.
Definition expressions.h:134
TempoInfo tempo
Tempo text and playback values.
Definition expressions.h:136