MCC
Loading...
Searching...
No Matches
Chords.h
1#ifndef MCC_CHORD_CHORDS_H
2#define MCC_CHORD_CHORDS_H
3
4#include <stddef.h>
5#include <stdint.h>
6
7#include <MCC/Chord/Chord.h>
8#include <MCC/Chord/ChordPattern.h>
9#include <MCC/Pitch/NoteName.h>
10#include <MCC/Scale/Scale.h>
11
12namespace MCC {
13
21namespace Chords {
22
24 enum class Id : uint8_t {
25 Major = 0,
26 Minor,
27 Augmented,
28 Diminished,
29 Sixth,
30 MinorSixth,
31 DominantSeventh,
32 MajorSeventh,
33 MinorSeventh,
34 HalfDiminishedSeventh,
35 DiminishedSeventh,
36 DominantNinth,
37 DominantMinorNinth,
38 MajorNinth,
39 MinorNinth,
40 DominantEleventh,
41 MajorEleventh,
42 MinorEleventh,
43 DominantThirteenth,
44 MajorThirteenth,
45 MinorThirteenth,
46 SuspendedSecond,
47 SuspendedFourth,
48 MinorMajorSeventh,
49 AugmentedSeventh,
50 AddedNinth,
51 SeventhSuspendedFourth,
52 Power,
53 Invalid = 0xFF
54 };
55
57 constexpr uint8_t Count = static_cast<uint8_t>(Id::Power) + 1;
58
60 constexpr uint8_t AliasCount = 7;
61
63 constexpr size_t NameCapacity = 28;
64
66 constexpr size_t SymbolCapacity = 8;
67
69 ChordPattern Pattern(Id id) noexcept;
70
75 size_t CopyName(Id id, char* destination, size_t capacity) noexcept;
76
81 size_t CopySymbol(Id id, char* destination, size_t capacity) noexcept;
82
88 size_t CopyAlias(uint8_t index, char* destination, size_t capacity, Id& target) noexcept;
89
94 Id Find(const char* name) noexcept;
95
97 inline Chord Make(NoteName root, Id id) noexcept {
98 return Chord(root, Pattern(id));
99 }
100
102 struct ScaleChord {
103 uint8_t degree;
105 };
106
116 size_t FromScale(const Scale& scale, ScaleChord* chords, size_t capacity) noexcept;
117
118} // namespace Chords
119
120} // namespace MCC
121
122#endif // MCC_CHORD_CHORDS_H
Root-independent chord structure: up to seven ascending tones within two octaves.
Definition ChordPattern.h:33
A chord pattern spelled from a root note name.
Definition Chord.h:29
Written note name: a letter plus an accidental, without octave.
Definition NoteName.h:29
A scale pattern spelled from a root note name.
Definition Scale.h:28
Reviewed catalog of named chords stored in program memory.
Definition Chords.h:21
Id Find(const char *name) noexcept
Finds a chord by exact canonical name or alias; returns Id::Invalid when nothing matches.
constexpr size_t SymbolCapacity
Buffer size that fits every symbol with its terminator.
Definition Chords.h:66
constexpr uint8_t Count
Number of catalog entries.
Definition Chords.h:57
constexpr size_t NameCapacity
Buffer size that fits every name and alias with its terminator.
Definition Chords.h:63
size_t FromScale(const Scale &scale, ScaleChord *chords, size_t capacity) noexcept
Lists every catalog chord whose tones are all written in scale (SPEC-CHD-5).
size_t CopyAlias(uint8_t index, char *destination, size_t capacity, Id &target) noexcept
Copies alias index (0-based, below AliasCount) and returns its length, also reporting the chord it na...
Id
Stable catalog identifier.
Definition Chords.h:24
Chord Make(NoteName root, Id id) noexcept
Spells catalog entry id from root.
Definition Chords.h:97
constexpr uint8_t AliasCount
Number of aliases.
Definition Chords.h:60
size_t CopyName(Id id, char *destination, size_t capacity) noexcept
Copies the canonical name of id with snprintf semantics and returns its length; an invalid id writes ...
size_t CopySymbol(Id id, char *destination, size_t capacity) noexcept
Copies the chord symbol of id ("", "m", "maj7", ...) with snprintf semantics and returns its length.
ChordPattern Pattern(Id id) noexcept
Returns the pattern of id, or the invalid pattern.
Music Composition Core public namespace.
Definition Version.h:4
One chord found on a scale degree.
Definition Chords.h:102
Id id
Catalog entry built on that degree.
Definition Chords.h:104
uint8_t degree
1-based scale degree of the root.
Definition Chords.h:103