XJ music engine  1.9.6
In-game runtime engine for XJ music.
Note.h
Go to the documentation of this file.
1 // Copyright (c) XJ Music Inc. (https://xjmusic.com) All Rights Reserved.
2 
3 #ifndef XJMUSIC_MUSIC_NOTE_H
4 #define XJMUSIC_MUSIC_NOTE_H
5 
6 #include <optional>
7 #include <regex>
8 #include <string>
9 
10 #include "PitchClass.h"
11 
12 namespace XJ {
13 
19  class Note {
20  private:
21  static std::regex rgxValidNote;
22 
23  // this max is only for extreme-case infinite loop prevention
24  static int MAX_DELTA_SEMITONES;
25 
26  public:
30  int octave;
31 
36 
42  bool operator==(const Note &other) const;
43 
49  bool operator<(const Note &other) const;
50 
56  bool operator>(const Note &other) const;
57 
63  bool operator<=(const Note &other) const;
64 
70  bool operator>=(const Note &other) const;
71 
75  static std::string ATONAL;
76 
80  Note();
81 
86  explicit Note(const std::string &name);
87 
94 
100  static Note of(const std::string &name);
101 
108  static Note of(PitchClass pitchClass, int octave);
109 
115  static Note atonal();
116 
123  static std::optional<Note> ifValid(const std::string &name);
124 
131  static std::optional<Note> ifTonal(const std::string &name);
132 
138  static bool isValid(const std::string &name);
139 
145  static bool containsAnyValidNotes(const std::string &noteCsv);
146 
153  static std::optional<Note> median(std::optional<Note> n1, std::optional<Note> n2);
154 
160  [[nodiscard]] std::string toString(Accidental accidental) const;
161 
167  [[nodiscard]] Note shift(int inc) const;
168 
174  [[nodiscard]] Note shiftOctave(int inc) const;
175 
181  [[nodiscard]] Note copy() const;
182 
193  Note setOctaveNearest(Note fromNote);
194 
200  [[nodiscard]] int delta(const Note &target) const;
201 
207  [[nodiscard]] bool isAtonal() const;
208 
214  Note nextUp(PitchClass target) const;
215 
222  Note nextDown(PitchClass target) const;
223 
231  Note next(PitchClass target, int delta) const;
232  };
233 
234 }// namespace XJ
235 
236 #endif// XJMUSIC_MUSIC_NOTE_H
Definition: Note.h:19
static std::optional< Note > ifValid(const std::string &name)
Definition: Note.cpp:73
static std::string ATONAL
Definition: Note.h:75
Note nextUp(PitchClass target) const
Definition: Note.cpp:166
Note()
Definition: Note.cpp:47
std::string toString(Accidental accidental) const
Definition: Note.cpp:129
bool operator<=(const Note &other) const
Definition: Note.cpp:34
Note shiftOctave(int inc) const
Definition: Note.cpp:140
static bool containsAnyValidNotes(const std::string &noteCsv)
Definition: Note.cpp:93
bool operator==(const Note &other) const
Definition: Note.cpp:19
Note nextDown(PitchClass target) const
Definition: Note.cpp:171
Note shift(int inc) const
Definition: Note.cpp:134
static std::optional< Note > ifTonal(const std::string &name)
Definition: Note.cpp:80
Note setOctaveNearest(Note fromNote)
Definition: Note.cpp:150
bool operator>=(const Note &other) const
Definition: Note.cpp:39
int delta(const Note &target) const
Definition: Note.cpp:107
bool operator>(const Note &other) const
Definition: Note.cpp:29
Note next(PitchClass target, int delta) const
Definition: Note.cpp:176
PitchClass pitchClass
Definition: Note.h:35
Note copy() const
Definition: Note.cpp:145
int octave
Definition: Note.h:30
bool operator<(const Note &other) const
Definition: Note.cpp:24
static Note atonal()
Definition: Note.cpp:68
static std::optional< Note > median(std::optional< Note > n1, std::optional< Note > n2)
Definition: Note.cpp:99
static bool isValid(const std::string &name)
Definition: Note.cpp:88
bool isAtonal() const
Definition: Note.cpp:161
static Note of(const std::string &name)
Definition: Note.cpp:56
Definition: ActiveAudio.h:11
Accidental
Definition: Accidental.h:12
PitchClass
Definition: PitchClass.h:19