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

Root-independent scale structure: up to twelve ascending degrees. More...

#include <ScalePattern.h>

Collaboration diagram for MCC::ScalePattern:
Collaboration graph

Public Member Functions

constexpr ScalePattern () 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 DegreeCount () const noexcept
 Returns the number of degrees, or 0 for the invalid pattern.
MCC_CONSTEXPR14 Interval DegreeInterval (int32_t degree) const noexcept
 Returns the ascending interval from the root to degree (1-based), or the invalid interval outside [1, DegreeCount()].
MCC_CONSTEXPR14 bool ContainsSemitone (int32_t semitones) const noexcept
 Returns true when a degree lies semitones (reduced modulo 12) above the root.

Static Public Member Functions

static constexpr ScalePattern Invalid () noexcept
 Returns the invalid pattern.
static MCC_CONSTEXPR14 ScalePattern FromFormula (const char *formula) noexcept
 Builds a pattern from a degree formula such as "1 2 b3 4 5 b6 b7".

Static Public Attributes

static constexpr uint8_t MaximumDegrees = 12
 Largest number of degrees: every chromatic semitone.

Friends

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

Detailed Description

Root-independent scale structure: up to twelve ascending degrees.

Each degree stores its diatonic steps (0-6) and semitones (0-11) above the root, so a scale spelled from any root keeps its written letters: the third degree of a major pattern is always a third (SPEC-SCL-2). Semitones are strictly ascending and the first degree is the perfect unison (SPEC-SCL-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 ScalePattern MCC::ScalePattern::FromFormula ( const char * formula)
inlinestaticnoexcept

Builds a pattern from a degree formula such as "1 2 b3 4 5 b6 b7".

Each space-separated token is an optional run of b or # followed by a degree number from 1 to 7, read against the major scale. The formula must start with 1 and its semitones must be strictly ascending inside one octave; otherwise the invalid pattern is returned.


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