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

Directed interval: a diatonic step count and a chromatic semitone count (SPEC-INT-1). More...

#include <Interval.h>

Collaboration diagram for MCC::Interval:
Collaboration graph

Public Member Functions

constexpr Interval () noexcept
 Creates the invalid interval (SPEC-ERR-2).
MCC_CONSTEXPR14 Interval (IntervalQuality quality, IntervalNumber number, IntervalDirection direction=IntervalDirection::Ascending) noexcept
 Creates the interval of quality and number in direction, for example Interval(IntervalQuality::Major(), IntervalNumber(3)).
constexpr bool IsValid () const noexcept
 Returns true unless this is the invalid interval.
constexpr int16_t DiatonicSteps () const noexcept
 Returns the signed diatonic step count, or InvalidSteps for the invalid interval (SPEC-ERR-7).
constexpr int16_t Semitones () const noexcept
 Returns the signed semitone count, or 0 for the invalid interval (SPEC-ERR-7).
MCC_CONSTEXPR14 IntervalDirection Direction () const noexcept
 Returns the direction (SPEC-INT-2); Unison for the perfect unison and for the invalid interval (SPEC-ERR-7).
MCC_CONSTEXPR14 IntervalNumber Number () const noexcept
 Returns the 1-based number (SPEC-INT-2); invalid if invalid.
MCC_CONSTEXPR14 IntervalQuality Quality () const noexcept
 Returns the quality (SPEC-INT-4); invalid if invalid.
MCC_CONSTEXPR14 bool IsSimple () const noexcept
 Returns true for numbers 1-8 (SPEC-INT-3).
MCC_CONSTEXPR14 bool IsCompound () const noexcept
 Returns true for numbers above 8 (SPEC-INT-3).
MCC_CONSTEXPR14 Interval Simple () const noexcept
 Removes whole octaves while keeping direction and quality (SPEC-INT-3): a major tenth becomes a major third; an octave stays an octave.
MCC_CONSTEXPR14 Interval Inverted () const noexcept
 Returns the inversion of the simple interval, in the same direction (SPEC-INT-6): numbers add up to 9, major and minor swap, augmented and diminished swap. Compound intervals invert their simple part.
MCC_CONSTEXPR14 Interval Reversed () const noexcept
 Returns the same interval in the opposite direction.

Static Public Member Functions

static MCC_CONSTEXPR14 Interval FromSteps (int32_t diatonicSteps, int32_t semitones) noexcept
 Creates the interval spanning diatonicSteps letters and semitones semitones, both signed (SPEC-INT-1).
static constexpr Interval Invalid () noexcept
 Returns the invalid interval.
static MCC_CONSTEXPR14 Interval Unison () noexcept
 Returns the perfect unison.

Static Public Attributes

static constexpr int16_t MaximumSteps = IntervalNumber::Maximum - 1
 Largest step magnitude: IntervalNumber::Maximum - 1.
static constexpr int16_t MaximumSemitones = 3079
 Largest semitone magnitude between two writable pitches.
static constexpr int16_t InvalidSteps = 32767
 Sentinel returned by DiatonicSteps() for the invalid interval (SPEC-ERR-7). Do not rely on it; check IsValid().

Friends

MCC_CONSTEXPR14 Interval operator+ (Interval a, Interval b) noexcept
 Adds two intervals by adding their steps and semitones: major third + minor third = perfect fifth. The result is invalid when either operand is invalid or the sum is unrepresentable.
constexpr bool operator== (Interval a, Interval b) noexcept
 Written equality: same steps and semitones. An augmented fourth and a diminished fifth are different intervals. All invalid intervals are equal (SPEC-ERR-6).
constexpr bool operator!= (Interval a, Interval b) noexcept

Detailed Description

Directed interval: a diatonic step count and a chromatic semitone count (SPEC-INT-1).

Both counts are signed. The direction follows the diatonic steps, or the semitones for a unison, so Cb from C is a descending augmented unison and no diminished unison exists (SPEC-INT-2, SPEC-INT-5). Number and quality are derived from the magnitudes: an ascending major third is +2 steps and +4 semitones; a descending one is -2 and -4.

An interval is valid when its counts lie within the span of writable pitches and its quality is perfect, major, minor, or augmented/diminished at most four times (SPEC-INT-4). Default construction and every other input produce the single invalid value (SPEC-ERR-1..3).

Constructor & Destructor Documentation

◆ Interval()

MCC_CONSTEXPR14 MCC::Interval::Interval ( IntervalQuality quality,
IntervalNumber number,
IntervalDirection direction = IntervalDirection::Ascending )
inlinenoexcept

Creates the interval of quality and number in direction, for example Interval(IntervalQuality::Major(), IntervalNumber(3)).

The result is invalid when the quality does not apply to the number (a perfect third, a major fifth), for a diminished unison (SPEC-INT-5), for direction Unison with anything but a perfect unison, or when either argument is invalid. A perfect unison ignores direction.

Member Function Documentation

◆ FromSteps()

MCC_CONSTEXPR14 Interval MCC::Interval::FromSteps ( int32_t diatonicSteps,
int32_t semitones )
inlinestaticnoexcept

Creates the interval spanning diatonicSteps letters and semitones semitones, both signed (SPEC-INT-1).

The result is invalid when either count exceeds the writable span or the quality would need more than four augmentations or diminutions (SPEC-ERR-3, SPEC-ERR-5).

◆ Inverted()

MCC_CONSTEXPR14 Interval MCC::Interval::Inverted ( ) const
inlinenoexcept

Returns the inversion of the simple interval, in the same direction (SPEC-INT-6): numbers add up to 9, major and minor swap, augmented and diminished swap. Compound intervals invert their simple part.

An augmented octave inverts to a descending augmented unison, because a diminished unison does not exist (SPEC-INT-5).


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