denigma 4.0.0
Loading...
Searching...
No Matches
gaps.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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
17 * THE SOFTWARE.
18 */
19#pragma once
20
21#include <optional>
22#include <span>
23#include <string>
24#include <utility>
25#include <variant>
26#include <vector>
27
28#include "denigma/classify/chords.h"
29#include "denigma/classify/expressions.h"
30#include "denigma/classify/formatted_text.h"
31#include "denigma/classify/lyrics.h"
32#include "denigma/classify/noteheads.h"
33#include "denigma/classify/smartshapes.h"
34
35namespace denigma {
36namespace classify {
37
41{
42 std::string id;
43 std::optional<int> staff;
45 std::optional<musx::util::Fraction> position;
46};
47
50enum class GapExtent {
51 Complete,
52 Partial
53};
54
61{
64 enum class Kind {
65 Staff,
66 SystemTop,
68 };
69
70 Kind kind{Kind::Staff};
71 GapAnchor anchor;
72};
73
78{};
79
82
85struct Gap
86{
87 GapAnchor anchor;
89 std::optional<GapAnchor> end;
92 std::vector<GapPlacement> placements;
93 GapPayload payload;
94};
95
103{
104public:
106 void retainDocument(musx::dom::DocumentPtr document) { m_documents.push_back(std::move(document)); }
107
109 template <typename Payload>
110 void add(GapAnchor anchor, Payload payload, GapExtent extent = GapExtent::Complete, std::vector<GapPlacement> placements = {})
111 {
112 m_gaps.push_back({std::move(anchor), std::nullopt, extent, std::move(placements), GapPayload(std::move(payload))});
113 }
114
116 template <typename Payload>
117 void addSpan(GapAnchor anchor, GapAnchor end, Payload payload, GapExtent extent = GapExtent::Complete)
118 {
119 m_gaps.push_back({std::move(anchor), std::move(end), extent, {}, GapPayload(std::move(payload))});
120 }
121
123 [[nodiscard]] std::span<const Gap> gaps() const noexcept { return m_gaps; }
124
125private:
126 std::vector<Gap> m_gaps;
127 std::vector<musx::dom::DocumentPtr> m_documents;
128};
129
130} // namespace classify
131} // namespace denigma
Collects typed conversion gaps for inspection or later serialization.
Definition gaps.h:103
std::span< const Gap > gaps() const noexcept
Returns collected gaps in source traversal order.
Definition gaps.h:123
void add(GapAnchor anchor, Payload payload, GapExtent extent=GapExtent::Complete, std::vector< GapPlacement > placements={})
Adds one typed gap.
Definition gaps.h:110
void addSpan(GapAnchor anchor, GapAnchor end, Payload payload, GapExtent extent=GapExtent::Complete)
Adds one typed gap for a feature that spans from anchor to end.
Definition gaps.h:117
void retainDocument(musx::dom::DocumentPtr document)
Keeps document alive for the collector's lifetime.
Definition gaps.h:106
GapExtent
How much of the feature the conversion target lacks.
Definition gaps.h:50
@ Partial
The anchored object stands for the feature but lost the reported payload.
@ Complete
Nothing in the target stands for the feature.
Core public API for the Denigma conversion libraries.
Definition articulations.h:33
Target-neutral musical and display semantics of a Finale chord assignment.
Definition chords.h:151
Exporter-neutral semantic classification of one Finale expression.
Definition expressions.h:338
Document-independent classification of a formatted Enigma text.
Definition formatted_text.h:91
Stable target object identity and optional location within that object.
Definition gaps.h:41
std::optional< musx::util::Fraction > position
Position within the anchored measure as a fraction of a whole note.
Definition gaps.h:45
One place the target document would draw a feature that is reported once.
Definition gaps.h:61
Kind
What the placement's anchor names.
Definition gaps.h:64
@ SystemBottom
The bottom staff of every system: the anchor is the global measure.
@ SystemTop
The top staff of every system: the anchor is the global measure.
@ Staff
A staff of a part measure: the anchor is the part measure with a staff.
One classified feature omitted, in whole or in part, from a conversion target.
Definition gaps.h:86
std::vector< GapPlacement > placements
Where the target would draw the feature. Empty when anchor alone says so.
Definition gaps.h:92
std::optional< GapAnchor > end
Where a spanning feature ends. Empty for a feature that occupies one place.
Definition gaps.h:89
Result returned by lyric word-extension classification.
Definition lyrics.h:45
Result returned by notehead classification.
Definition noteheads.h:65
Marker payload: the anchored object sounds in the source without being drawn, and the target cannot h...
Definition gaps.h:78
Result returned by smart-shape classification.
Definition smartshapes.h:197