denigma 4.0.0
Loading...
Searching...
No Matches
chords.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 <string_view>
27#include <vector>
28
29#include "musx/musx.h"
30
31namespace denigma {
32namespace classify {
33
34namespace chord {
35
38enum class BassArrangement {
39 Horizontal,
40 Vertical,
41 Diagonal
42};
43
49enum class Quality {
50 Major,
51 Minor,
52 Augmented,
53 Diminished,
54 Dominant,
55 AugmentedSeventh,
56 MajorSeventh,
57 MinorSeventh,
58 DiminishedSeventh,
59 HalfDiminished,
60 MajorMinor,
61 MajorSixth,
62 MinorSixth,
63 DominantNinth,
64 MajorNinth,
65 MinorNinth,
66 DominantEleventh,
67 MajorEleventh,
68 MinorEleventh,
69 DominantThirteenth,
70 MajorThirteenth,
71 MinorThirteenth,
72 SuspendedSecond,
73 SuspendedFourth,
74 Pedal,
75 None,
76 Power
77};
78
81struct Degree
82{
85 enum class Type {
86 Add,
87 Remove,
88 Alter
89 };
90
91 int value{};
92 int alteration{};
97};
98
105{
111 enum class Position {
112 Inline,
113 Above,
114 Below
115 };
116
117 std::string text;
119};
120
121} // namespace chord
122
126{
128 std::vector<chord::SuffixString> strings;
130 std::optional<chord::Quality> quality;
132 std::vector<chord::Degree> degrees;
142
145 std::string calcText() const;
146};
147
151{
153 music_theory::Pitch root;
154 bool rootLowerCase{};
155 bool showRoot{};
156 ChordSuffixClassification suffix;
157 bool showSuffix{};
159 std::optional<music_theory::Pitch> bass;
160 bool bassLowerCase{};
161 std::optional<chord::BassArrangement> bassArrangement;
162};
163
166ChordSuffixClassification classifyChordSuffix(const musx::dom::MusxInstanceList<musx::dom::others::ChordSuffixElement>& suffix);
167
170
174{
176 musx::dom::MusxInstance<musx::dom::details::ChordAssign> assignment;
178 musx::util::Fraction position;
181};
182
185std::optional<ChordSymbolClassification> classifyChordSymbol(const musx::dom::MusxInstance<musx::dom::details::ChordAssign>& assignment,
186 const musx::dom::MusxInstance<musx::dom::KeySignature>& keySignature, musx::dom::KeySignature::KeyContext keyContext);
187
194std::vector<ChordAssignmentClassification> classifyChordAssignments(const musx::dom::MusxInstanceList<musx::dom::details::ChordAssign>& assignments,
195 const musx::dom::MusxInstance<musx::dom::KeySignature>& keySignature, musx::dom::KeySignature::KeyContext keyContext);
196
197} // namespace classify
198} // namespace denigma
std::optional< ChordSymbolClassification > classifyChordSymbol(const musx::dom::MusxInstance< musx::dom::details::ChordAssign > &assignment, const musx::dom::MusxInstance< musx::dom::KeySignature > &keySignature, musx::dom::KeySignature::KeyContext keyContext)
Classifies a Finale chord assignment using the effective key signature.
ChordSuffixClassification classifyChordSuffix()
Classifies a Finale chord with no displayed suffix as a major triad.
std::vector< ChordAssignmentClassification > classifyChordAssignments(const musx::dom::MusxInstanceList< musx::dom::details::ChordAssign > &assignments, const musx::dom::MusxInstance< musx::dom::KeySignature > &keySignature, musx::dom::KeySignature::KeyContext keyContext)
Classifies a list of Finale chord assignments, normally one staff's assignments in one measure.
Core public API for the Denigma conversion libraries.
Definition articulations.h:33
Classification paired with the Finale chord assignment that produced it.
Definition chords.h:174
musx::dom::MusxInstance< musx::dom::details::ChordAssign > assignment
Source chord assignment.
Definition chords.h:176
ChordSymbolClassification classification
Semantic classification of the assigned chord.
Definition chords.h:180
musx::util::Fraction position
Position of the chord from the start of its measure, as a fraction of a whole note.
Definition chords.h:178
Classified logical strings reconstructed from Finale chord-suffix elements.
Definition chords.h:126
bool hasUnrecognizedGlyphs
True when the suffix contains a private-use character that no known font mapping resolved.
Definition chords.h:141
bool stackDegrees
True when the suffix shows degrees stacked vertically instead of running left to right.
Definition chords.h:136
std::vector< chord::SuffixString > strings
The suffix's logical strings in Finale's source order. (See chord::SuffixString.)
Definition chords.h:128
std::string calcText() const
Concatenates the classified strings in Finale's source order.
bool hasOuterParentheses
True when a single pair of parentheses encloses the entire suffix text.
Definition chords.h:138
std::vector< chord::Degree > degrees
Degrees the suffix applies on top of quality, in source order.
Definition chords.h:132
std::optional< chord::Quality > quality
The recognized harmonic quality, or std::nullopt when the suffix text could not be parsed.
Definition chords.h:130
bool parenthesizeDegrees
True when the suffix shows degrees inside parentheses.
Definition chords.h:134
Target-neutral musical and display semantics of a Finale chord assignment.
Definition chords.h:151
music_theory::Pitch root
The written root spelling. A chord symbol has no octave, so only the note name and alteration are mea...
Definition chords.h:153
std::optional< music_theory::Pitch > bass
The written alternate-bass spelling, when the chord shows one. Its octave is not meaningful either.
Definition chords.h:159
One degree alteration that a chord suffix applies on top of its chord::Quality.
Definition chords.h:82
Type type
How the degree modifies the chord.
Definition chords.h:93
int alteration
Chromatic alteration in semitones: -1 for flat, 1 for sharp, 0 for none.
Definition chords.h:92
int value
Degree number relative to the root, such as 9, 11, or 13.
Definition chords.h:91
Type
How the degree modifies the chord.
Definition chords.h:85
@ Remove
The degree is omitted from the chord.
@ Alter
A degree already present in the chord is chromatically altered.
@ Add
The degree is added to the chord.
bool impliedByText
True when the suffix text already spells this degree out, such as the seventh in "7sus4".
Definition chords.h:94
One contiguous logical text string within a Finale chord suffix.
Definition chords.h:105
Position position
The string's position relative to the suffix baseline.
Definition chords.h:118
Position
Logical vertical position of a Finale chord-suffix string.
Definition chords.h:111
@ Above
Stacked above the suffix baseline.
@ Below
Stacked below the suffix baseline.
std::string text
The string's text as Unicode.
Definition chords.h:117