1#ifndef MCC_RHYTHM_NOTE_H
2#define MCC_RHYTHM_NOTE_H
6#include <MCC_BuildSettings.h>
7#include <MCC/Pitch/Pitch.h>
8#include <MCC/Rhythm/NoteValue.h>
31 constexpr Note() noexcept : _pitch(), _value() {}
76 return _pitch.IsValid() && _value.IsValid();
99 constexpr int8_t
Octave() const noexcept {
return _pitch.Octave(); }
113 return Note(pitch, _value);
118 return Note(_pitch, value);
123 return Note(_pitch, _value.WithDots(dots));
128 return Note(_pitch.MovedDiatonically(steps), _value);
133 return Note(_pitch.Altered(semitones), _value);
138 return Note(_pitch.MovedByOctaves(octaves), _value);
143 return a._pitch == b._pitch && a._value == b._value;
146 friend constexpr bool operator!=(
Note a,
Note b)
noexcept {
155 if (!a.IsValid() || !b.IsValid()) {
156 return a.IsValid() && !b.IsValid();
158 return a._pitch != b._pitch ? a._pitch < b._pitch : a._value < b._value;
161 friend MCC_CONSTEXPR14
bool operator>(
Note a,
Note b)
noexcept {
165 friend MCC_CONSTEXPR14
bool operator<=(
Note a,
Note b)
noexcept {
169 friend MCC_CONSTEXPR14
bool operator>=(
Note a,
Note b)
noexcept {
179 if (!a.IsValid() || !b.IsValid()) {
180 return a.IsValid() && !b.IsValid();
182 if (a.ChromaticIndex() != b.ChromaticIndex()) {
183 return a.ChromaticIndex() < b.ChromaticIndex();
185 return a.Pitch() != b.Pitch() ? a.Pitch() < b.Pitch() : a.Value() < b.Value();
Chromatic alteration of a letter, from -4 (quadruple flat) to +4 (quadruple sharp).
Definition Accidental.h:20
constexpr Accidental() noexcept
Creates the invalid accidental (SPEC-ERR-2).
Definition Accidental.h:39
Absolute semitone position of a pitch, with origin C-1 = 0.
Definition ChromaticIndex.h:26
constexpr ChromaticIndex() noexcept
Creates the invalid index (SPEC-ERR-2).
Definition ChromaticIndex.h:45
Written note name: a letter plus an accidental, without octave.
Definition NoteName.h:29
constexpr NoteName() noexcept
Creates the invalid note name (SPEC-ERR-2).
Definition NoteName.h:37
Exact written note length: a power-of-two base and zero to four dots.
Definition NoteValue.h:21
static constexpr NoteValue Quarter(int32_t dots=0) noexcept
Creates a quarter note, optionally augmented by dots.
Definition NoteValue.h:64
A written pitch combined with an exact written note value.
Definition Note.h:25
constexpr Note(MCC::NoteName noteName, int32_t octave, MCC::NoteValue value=MCC::NoteValue::Quarter()) noexcept
Creates noteName in octave, with a quarter by default.
Definition Note.h:47
MCC_CONSTEXPR14 MCC::ChromaticIndex ChromaticIndex() const noexcept
Returns the chromatic index, or the invalid chromatic index.
Definition Note.h:107
constexpr Note WithPitch(MCC::Pitch pitch) const noexcept
Returns the same note value with a new written pitch.
Definition Note.h:112
constexpr MCC::NoteValue Value() const noexcept
Returns the written note value, or the invalid value.
Definition Note.h:83
static constexpr Note Invalid() noexcept
Returns the invalid note.
Definition Note.h:72
constexpr MCC::Pitch Pitch() const noexcept
Returns the written pitch, or the invalid pitch.
Definition Note.h:80
constexpr Note() noexcept
Creates the invalid note (SPEC-ERR-2).
Definition Note.h:31
constexpr MCC::Accidental Accidental() const noexcept
Returns the written accidental, or the invalid accidental.
Definition Note.h:94
friend MCC_CONSTEXPR14 bool operator<(Note a, Note b) noexcept
Written order by pitch, then exact note-value duration; invalid notes sort last.
Definition Note.h:154
MCC_CONSTEXPR14 Note Altered(int32_t semitones) const noexcept
Alters the pitch and preserves the note value.
Definition Note.h:132
constexpr MCC::NoteName NoteName() const noexcept
Returns the written note name, or the invalid note name.
Definition Note.h:86
friend constexpr bool operator==(Note a, Note b) noexcept
Written equality of both pitch and note value.
Definition Note.h:142
constexpr Note WithValue(MCC::NoteValue value) const noexcept
Returns the same written pitch with a new note value.
Definition Note.h:117
constexpr bool IsValid() const noexcept
Returns true unless this is the invalid note.
Definition Note.h:75
MCC_CONSTEXPR14 MCC::PitchClass PitchClass() const noexcept
Returns the pitch class, or the invalid pitch class.
Definition Note.h:102
constexpr MCC::Letter Letter() const noexcept
Returns the written letter.
Definition Note.h:91
constexpr int8_t Octave() const noexcept
Returns the written octave, or 0 for the invalid note.
Definition Note.h:99
constexpr Note(MCC::Letter letter, MCC::Accidental accidental, int32_t octave, MCC::NoteValue value=MCC::NoteValue::Quarter()) noexcept
Creates letter + accidental in octave, with a quarter by default.
Definition Note.h:64
constexpr Note(MCC::Pitch pitch, MCC::NoteValue value=MCC::NoteValue::Quarter()) noexcept
Creates pitch with value; the default value is a quarter.
Definition Note.h:36
constexpr Note(MCC::Letter letter, int32_t octave, MCC::NoteValue value=MCC::NoteValue::Quarter()) noexcept
Creates natural letter in octave, with a quarter by default.
Definition Note.h:54
MCC_CONSTEXPR14 Note MovedDiatonically(int32_t steps) const noexcept
Moves the pitch diatonically and preserves the note value.
Definition Note.h:127
constexpr Note WithDots(int32_t dots) const noexcept
Returns the same written pitch and base with a new dot count.
Definition Note.h:122
MCC_CONSTEXPR14 Note MovedByOctaves(int32_t octaves) const noexcept
Moves the pitch by octaves and preserves the note value.
Definition Note.h:137
Pitch class 0-11 with spelling discarded (C = 0).
Definition PitchClass.h:21
constexpr PitchClass() noexcept
Creates the invalid pitch class (SPEC-ERR-2).
Definition PitchClass.h:37
Written absolute pitch: a note name plus an octave.
Definition Pitch.h:35
Letter
Diatonic letter name.
Definition Letter.h:22
MCC_CONSTEXPR14 bool IsNoteLowerThan(Note a, Note b) noexcept
Orders notes by sounding pitch, then by written pitch and value.
Definition Note.h:178
Music Composition Core public namespace.
Definition Version.h:4