XJ music engine  1.9.6
In-game runtime engine for XJ music.
Tuning.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_TUNING_H
4 #define XJMUSIC_MUSIC_TUNING_H
5 
6 #include <map>
7 #include <string>
8 #include <cmath>
9 
10 #include "Note.h"
11 
12 namespace XJ {
13 
23  class Tuning {
24  private:
25  double TWELFTH_ROOT_OF_TWO = std::pow(2.0, 1.0 / 12.0);
26  double NATURAL_LOGARITHM_OF_TWELFTH_ROOT_OF_TWO = std::log(TWELFTH_ROOT_OF_TWO);
27  float ROOT_PITCH_MINIMUM = 1.0;
28  float ROOT_PITCH_MAXIMUM = 100000.0;
29  int ROOT_OCTAVE_MINIMUM = 0;
30  int ROOT_OCTAVE_MAXIMUM = 15;
31  std::map <int, std::map<PitchClass, float>> _notePitches;
32  std::map <float, int> _deltaFromRootPitch;
33  std::map <float, Note> _pitchNotes;
34 
35  public:
37  float rootPitch;
38 
42  Tuning();
43 
47  Tuning(const Note &rootNote, const float &rootPitch);
48 
55  static Tuning atA4(float a4);
56 
64  static Tuning at(Note note, float pitch);
65 
73  float pitch(Note note);
74 
80  Note getTones(float pitch);
81 
88  int deltaFromRootPitch(float pitch);
89 
96  [[nodiscard]] float pitchAtDelta(int delta) const;
97 
103  void validate() const;
104  };
105 
106 }// namespace XJ
107 
108 #endif //XJMUSIC_MUSIC_TUNING_H
Definition: Note.h:19
Definition: Tuning.h:23
Tuning()
Definition: Tuning.cpp:10
Note rootNote
Definition: Tuning.h:36
static Tuning at(Note note, float pitch)
Definition: Tuning.cpp:25
void validate() const
Definition: Tuning.cpp:66
static Tuning atA4(float a4)
Definition: Tuning.cpp:20
float pitchAtDelta(int delta) const
Definition: Tuning.cpp:61
Note getTones(float pitch)
Definition: Tuning.cpp:44
float pitch(Note note)
Definition: Tuning.cpp:30
float rootPitch
Definition: Tuning.h:37
int deltaFromRootPitch(float pitch)
Definition: Tuning.cpp:52
Definition: ActiveAudio.h:11