1#ifndef MCC_SCALE_SCALE_H
2#define MCC_SCALE_SCALE_H
4#include <MCC_BuildSettings.h>
8#include <MCC/Interval/Transposition.h>
9#include <MCC/Pitch/NoteName.h>
10#include <MCC/Pitch/Pitch.h>
11#include <MCC/Pitch/PitchClass.h>
12#include <MCC/Scale/ScalePattern.h>
34 constexpr Scale() noexcept : _root(), _pattern() {}
47 constexpr bool IsValid() const noexcept {
return _pattern.IsValid(); }
56 MCC_CONSTEXPR14 uint8_t
DegreeCount() const noexcept {
return _pattern.DegreeCount(); }
63 return _root + _pattern.DegreeInterval(degree);
71 return MCC::Pitch(_root, rootOctave) + _pattern.DegreeInterval(degree);
79 if (!noteName.IsValid()) {
83 for (uint8_t degree = 1; degree <= count; ++degree) {
84 if (
NoteAt(degree) == noteName) {
101 return IsValid() && pitchClass.IsValid() &&
102 _pattern.ContainsSemitone(
103 static_cast<int32_t
>(pitchClass.Value()) - _root.PitchClass().Value());
108 return a._root == b._root && a._pattern == b._pattern;
Written note name: a letter plus an accidental, without octave.
Definition NoteName.h:29
static constexpr NoteName Invalid() noexcept
Returns the invalid note name.
Definition NoteName.h:59
Pitch class 0-11 with spelling discarded (C = 0).
Definition PitchClass.h:21
Written absolute pitch: a note name plus an octave.
Definition Pitch.h:35
Root-independent scale structure: up to twelve ascending degrees.
Definition ScalePattern.h:32
static constexpr ScalePattern Invalid() noexcept
Returns the invalid pattern.
Definition ScalePattern.h:78
constexpr Scale() noexcept
Creates the invalid scale (SPEC-ERR-2).
Definition Scale.h:34
friend constexpr bool operator==(const Scale &a, const Scale &b) noexcept
Compares roots by spelling and patterns by degrees.
Definition Scale.h:107
constexpr bool ContainsPitchClass(MCC::PitchClass pitchClass) const noexcept
Returns true when any degree sounds as pitchClass, regardless of spelling (explicit enharmonic member...
Definition Scale.h:100
MCC_CONSTEXPR14 uint8_t DegreeOf(NoteName noteName) const noexcept
Returns the 1-based degree written exactly as noteName, or 0 when no degree has that spelling.
Definition Scale.h:78
constexpr Scale(NoteName root, ScalePattern pattern) noexcept
Spells pattern from root; invalid when either is invalid.
Definition Scale.h:39
MCC_CONSTEXPR14 NoteName NoteAt(int32_t degree) const noexcept
Returns the note name of degree (1-based), or the invalid note name outside the scale or when it cann...
Definition Scale.h:62
MCC_CONSTEXPR14 bool Contains(NoteName noteName) const noexcept
Returns true when a degree is written exactly as noteName.
Definition Scale.h:92
constexpr NoteName Root() const noexcept
Returns the root note name.
Definition Scale.h:50
MCC_CONSTEXPR14 uint8_t DegreeCount() const noexcept
Returns the number of degrees, or 0 for the invalid scale.
Definition Scale.h:56
constexpr bool IsValid() const noexcept
Returns true unless this is the invalid scale.
Definition Scale.h:47
constexpr ScalePattern Pattern() const noexcept
Returns the root-independent pattern.
Definition Scale.h:53
friend constexpr bool operator!=(const Scale &a, const Scale &b) noexcept
Negation of operator==.
Definition Scale.h:112
MCC_CONSTEXPR14 MCC::Pitch PitchAt(int32_t degree, int32_t rootOctave) const noexcept
Returns the pitch of degree when the root is placed in rootOctave; degrees above the root may fall in...
Definition Scale.h:70
static constexpr Scale Invalid() noexcept
Returns the invalid scale.
Definition Scale.h:44
Music Composition Core public namespace.
Definition Version.h:4