denigma 4.0.0
Loading...
Searching...
No Matches
formatted_text.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 <string>
26#include <vector>
27
28#include "musx/musx.h"
29
30namespace denigma {
31namespace classify {
32
33namespace text {
34
41struct Insert
42{
53
57 std::string command;
59 std::vector<std::string> parameters;
60};
61
64struct Run
65{
67 std::string text;
69 musx::dom::ResolvedFontInfo font;
71 std::vector<std::string> glyphNames;
73 std::optional<Insert> insert;
74
76 [[nodiscard]] bool isGlyphRun() const noexcept { return !glyphNames.empty(); }
77};
78
79} // namespace text
80
91{
93 std::vector<text::Run> runs;
95 std::string plainText;
96};
97
100FormattedText classifyFormattedText(const musx::util::EnigmaParsingContext& text);
101
102} // namespace classify
103} // namespace denigma
FormattedText classifyFormattedText(const musx::util::EnigmaParsingContext &text)
Classifies a formatted Enigma text.
Core public API for the Denigma conversion libraries.
Definition articulations.h:33
Document-independent classification of a formatted Enigma text.
Definition formatted_text.h:91
std::vector< text::Run > runs
Visible runs in source order.
Definition formatted_text.h:93
std::string plainText
The runs' text joined, with Unicode accidental characters.
Definition formatted_text.h:95
The Enigma text insert a run was substituted for.
Definition formatted_text.h:42
std::vector< std::string > parameters
The insert's parameters as written.
Definition formatted_text.h:59
Kind kind
The insert's meaning.
Definition formatted_text.h:55
std::string command
The insert as written, without the leading caret.
Definition formatted_text.h:57
Kind
The insert's meaning, for the inserts the classifier names.
Definition formatted_text.h:45
@ RehearsalMark
The rehearsal mark's sequence text: ^rehearsal.
@ PlaybackPass
The expression's repeat pass: ^pass.
@ PlaybackController
The expression's playback controller value: ^control.
@ Other
An insert the classifier does not name; command and parameters still identify it.
@ PlaybackValue
The expression's playback value: ^value.
@ Accidental
An accidental symbol: ^flat, ^sharp, ^natural, ^dbflat, ^dbsharp.
One stretch of formatted text in a single font, holding either text or music glyphs.
Definition formatted_text.h:65
std::string text
Visible UTF-8 text of the run. For a glyph run, the source characters the glyphs came from.
Definition formatted_text.h:67
musx::dom::ResolvedFontInfo font
Document-independent snapshot of the run's font.
Definition formatted_text.h:69
std::optional< Insert > insert
The insert the run was substituted for, when it was. Such a run is never merged with its neighbors.
Definition formatted_text.h:73
std::vector< std::string > glyphNames
One SMuFL glyph name per code point when the run is music glyphs; empty for a text run.
Definition formatted_text.h:71
bool isGlyphRun() const noexcept
True when the run is music glyphs rather than text.
Definition formatted_text.h:76