MCC
Loading...
Searching...
No Matches
MCC::ChordPattern Class Reference

Root-independent chord structure: up to seven ascending tones within two octaves. More...

#include <ChordPattern.h>

Collaboration diagram for MCC::ChordPattern:
Collaboration graph

Public Member Functions

constexpr ChordPattern () noexcept
 Creates the invalid pattern (SPEC-ERR-2).
constexpr bool IsValid () const noexcept
 Returns true unless this is the invalid pattern.
MCC_CONSTEXPR14 uint8_t ToneCount () const noexcept
 Returns the number of tones, or 0 for the invalid pattern.
MCC_CONSTEXPR14 Interval ToneInterval (int32_t tone) const noexcept
 Returns the ascending interval from the root to tone (1-based, in root-position order), or the invalid interval outside [1, ToneCount()].
constexpr uint16_t PitchClassMask () const noexcept
 Returns the twelve-bit set of semitones above the root reduced modulo 12; bit k is set when a tone sounds k semitones above the root.

Static Public Member Functions

static constexpr ChordPattern Invalid () noexcept
 Returns the invalid pattern.
static MCC_CONSTEXPR14 ChordPattern FromFormula (const char *formula) noexcept
 Builds a pattern from a chord formula such as "1 3 5 b7 9".

Static Public Attributes

static constexpr uint8_t MaximumTones = 7
 Largest number of tones: a full thirteenth chord.

Friends

struct Detail::ChordPatternStorage
MCC_CONSTEXPR14 bool operator== (const ChordPattern &a, const ChordPattern &b) noexcept
 Compares tones, including their written steps.
MCC_CONSTEXPR14 bool operator!= (const ChordPattern &a, const ChordPattern &b) noexcept
 Negation of operator==.

Detailed Description

Root-independent chord structure: up to seven ascending tones within two octaves.

Each tone stores its diatonic steps (0-12) and semitones (0-23) above the root, so extensions keep their written numbers: the ninth of a chord is spelled as a ninth, not as a second (SPEC-CHD-2). Semitones are strictly ascending and the first tone is the perfect unison (SPEC-CHD-1).

A pattern is eight bytes, trivially copyable and allocation-free, so the same representation is stored in the flash catalog (SPEC-EMB-5). Default construction and every malformed input produce the single invalid pattern (SPEC-ERR-1..3).

Member Function Documentation

◆ FromFormula()

MCC_CONSTEXPR14 ChordPattern MCC::ChordPattern::FromFormula ( const char * formula)
inlinestaticnoexcept

Builds a pattern from a chord formula such as "1 3 5 b7 9".

Each space-separated token is an optional run of b or # followed by a tone number from 1 to 13, read against the major scale. The formula must start with 1, contain at most seven tones and have strictly ascending semitones below two octaves; otherwise the invalid pattern is returned.


The documentation for this class was generated from the following file: