XJ music engine  1.9.6
In-game runtime engine for XJ music.
NoteRange.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_RANGE_H
4 #define XJMUSIC_MUSIC_NOTE_RANGE_H
5 
6 #include <set>
7 
8 #include "Note.h"
9 
10 namespace XJ {
11 
15  class NoteRange {
16  private:
17  std::string UNKNOWN = "Unknown";
18  int MAX_SEEK_OCTAVES = 3;
19 
20  public:
21 
22  std::optional<Note> low;
23 
24  std::optional<Note> high;
25 
26  NoteRange();
27 
28  NoteRange(std::optional<Note> low, std::optional<Note> high);
29 
30  NoteRange(const std::string &low, const std::string &high);
31 
32  static NoteRange from(Note low, Note high);
33 
34  static NoteRange from(const std::string &low, const std::string &high);
35 
36  static NoteRange copyOf(const NoteRange &range);
37 
38  static NoteRange ofNotes(std::vector<Note> notes);
39 
40  static NoteRange ofNotes(const std::set<Note>& notes);
41 
42  static NoteRange ofStrings(const std::vector<std::string> &notes);
43 
44  static NoteRange median(const NoteRange &r1, const NoteRange &r2);
45 
53  static int computeMedianOptimalRangeShiftOctaves(const NoteRange *sourceRange, const NoteRange *targetRange);
54 
55  std::string toString(Accidental accidental);
56 
57  void expand(const std::vector<Note> &notes);
58 
63  void expand(Note note);
64 
69  void expand(const NoteRange *range);
70 
76  int getDeltaSemitones(NoteRange target);
77 
82  std::optional<Note> getMedianNote();
83 
89  NoteRange shifted(int inc) const;
90 
95  bool empty() const;
96 
102  std::optional<Note> getNoteNearestMedian(PitchClass root);
103 
110  Note toAvailableOctave(Note note) const;
111 
118  bool includes(Note note) const;
119  };
120 
121 }// namespace XJ
122 
123 #endif// XJMUSIC_MUSIC_NOTE_RANGE_H
Definition: NoteRange.h:15
NoteRange()
Definition: NoteRange.cpp:10
static NoteRange ofNotes(std::vector< Note > notes)
Definition: NoteRange.cpp:40
NoteRange shifted(int inc) const
Definition: NoteRange.cpp:152
static NoteRange copyOf(const NoteRange &range)
Definition: NoteRange.cpp:35
bool includes(Note note) const
Definition: NoteRange.cpp:196
static NoteRange median(const NoteRange &r1, const NoteRange &r2)
Definition: NoteRange.cpp:65
static int computeMedianOptimalRangeShiftOctaves(const NoteRange *sourceRange, const NoteRange *targetRange)
Definition: NoteRange.cpp:70
Note toAvailableOctave(Note note) const
Definition: NoteRange.cpp:176
static NoteRange from(Note low, Note high)
Definition: NoteRange.cpp:22
std::optional< Note > high
Definition: NoteRange.h:24
std::optional< Note > getMedianNote()
Definition: NoteRange.cpp:144
std::optional< Note > low
Definition: NoteRange.h:22
void expand(const std::vector< Note > &notes)
Definition: NoteRange.cpp:119
static NoteRange ofStrings(const std::vector< std::string > &notes)
Definition: NoteRange.cpp:55
int getDeltaSemitones(NoteRange target)
Definition: NoteRange.cpp:136
bool empty() const
Definition: NoteRange.cpp:159
std::string toString(Accidental accidental)
Definition: NoteRange.cpp:101
std::optional< Note > getNoteNearestMedian(PitchClass root)
Definition: NoteRange.cpp:165
Definition: Note.h:19
Definition: ActiveAudio.h:11
Accidental
Definition: Accidental.h:12
PitchClass
Definition: PitchClass.h:19