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

Written note name: a letter plus an accidental, without octave. More...

#include <NoteName.h>

Collaboration diagram for MCC::NoteName:
Collaboration graph

Public Member Functions

constexpr NoteName () noexcept
 Creates the invalid note name (SPEC-ERR-2).
constexpr NoteName (MCC::Letter letter, MCC::Accidental accidental) noexcept
 Creates the note name spelled letter + accidental.
constexpr NoteName (MCC::Letter letter) noexcept
 Creates the natural note name of letter.
constexpr bool IsValid () const noexcept
 Returns true unless this is the invalid note name.
constexpr MCC::Letter Letter () const noexcept
 Returns the written letter, or Letter::C for the invalid note name (SPEC-ERR-7).
constexpr MCC::Accidental Accidental () const noexcept
 Returns the written accidental; invalid for the invalid note name.
MCC_CONSTEXPR14 MCC::PitchClass PitchClass () const noexcept
 Returns (NaturalSemitone(letter) + accidental) mod 12, always in [0, 11] (SPEC-ORD-4). The invalid note name yields the invalid pitch class (SPEC-ERR-4).
MCC_CONSTEXPR14 NoteName MovedDiatonically (int32_t steps) const noexcept
 Moves the letter by steps diatonic letters and keeps the written accidental: C# moved by 2 is E#, B moved by 1 is C.
MCC_CONSTEXPR14 NoteName Altered (int32_t semitones) const noexcept
 Keeps the letter and alters the accidental by semitones: C# altered by +1 is C##, never D.

Static Public Member Functions

static constexpr NoteName Invalid () noexcept
 Returns the invalid note name.

Friends

constexpr bool operator== (NoteName a, NoteName b) noexcept
 Written equality: letter and accidental (SPEC-EQ-1). All invalid note names are equal (SPEC-ERR-6).
constexpr bool operator!= (NoteName a, NoteName b) noexcept
constexpr bool operator< (NoteName a, NoteName b) noexcept
 Written order: letter, then accidental (SPEC-ORD-5). The invalid note name sorts last.
constexpr bool operator> (NoteName a, NoteName b) noexcept
constexpr bool operator<= (NoteName a, NoteName b) noexcept
constexpr bool operator>= (NoteName a, NoteName b) noexcept

Detailed Description

Written note name: a letter plus an accidental, without octave.

The spelling is preserved: C# and Db are different note names that share a pitch class (SPEC-EQ-1). Enharmonic equivalence is tested only through MCC::IsEnharmonic() (SPEC-EQ-2), and no implicit conversion to PitchClass exists (SPEC-EQ-3).

Default construction, a non-enumerator Letter or an invalid accidental produce the single invalid value (SPEC-ERR-1..3). Operations on the invalid value return the invalid value (SPEC-ERR-4).

Constructor & Destructor Documentation

◆ NoteName()

MCC::NoteName::NoteName ( MCC::Letter letter,
MCC::Accidental accidental )
inlineconstexprnoexcept

Creates the note name spelled letter + accidental.

An invalid accidental or a Letter outside the enumerators produces the invalid note name (SPEC-ERR-3).

Member Function Documentation

◆ Altered()

MCC_CONSTEXPR14 NoteName MCC::NoteName::Altered ( int32_t semitones) const
inlinenoexcept

Keeps the letter and alters the accidental by semitones: C# altered by +1 is C##, never D.

A result outside [-4, +4] is the invalid note name; the note is never respelled with another letter (SPEC-ACC-3, SPEC-ERR-5).

◆ MovedDiatonically()

MCC_CONSTEXPR14 NoteName MCC::NoteName::MovedDiatonically ( int32_t steps) const
inlinenoexcept

Moves the letter by steps diatonic letters and keeps the written accidental: C# moved by 2 is E#, B moved by 1 is C.

The spelling is never rewritten, so the accidental of a valid note name always remains within [-4, +4] (SPEC-ACC-3).


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