A dependency-free, header-only collection of useful functions for music theory.
More...
|
class | Transposer |
| Provides dependency-free transposition utilities that work with any scale that has 7 diatonic steps and an equal number of divisions of the octave (EDO). The most common Western scales use 12 divisions of the octave, .i.e., 12-EDO. More...
|
|
|
int | calcDisplacement (int pitchClass, int octave) |
| Calculates the displacement value for a given absolute pitch class and octave.
|
|
template<typename T > |
constexpr T | sign (T n) |
| Calculates the sign of an integer.
|
|
template<typename T > |
constexpr T | signedModulus (T n, T d) |
| Calculates the modulus of positive and negative numbers in a predictable manner.
|
|
|
constexpr int | STANDARD_DIATONIC_STEPS = 7 |
| currently this is the only supported number of diatonic steps.
|
|
constexpr int | STANDARD_12EDO_STEPS = 12 |
| this can be overriden when constructing a Transposer instance.
|
|
A dependency-free, header-only collection of useful functions for music theory.
◆ calcDisplacement()
int music_theory::calcDisplacement |
( |
int |
pitchClass, |
|
|
int |
octave |
|
) |
| |
|
inline |
Calculates the displacement value for a given absolute pitch class and octave.
- Parameters
-
pitchClass | 0..6 corresponding to C..B |
octave | Octave 4 is the middle-C octave |
- Returns
- A displacement value that can be used to create a Transposer instance.
◆ sign()
template<typename T >
constexpr T music_theory::sign |
( |
T |
n | ) |
|
|
inlineconstexpr |
Calculates the sign of an integer.
- Parameters
-
- Returns
- -1 for negative; 1 for non-negative.
◆ signedModulus()
template<typename T >
constexpr T music_theory::signedModulus |
( |
T |
n, |
|
|
T |
d |
|
) |
| |
|
constexpr |
Calculates the modulus of positive and negative numbers in a predictable manner.
- Template Parameters
-
- Parameters
-
n | The number (positive or negative) for which to calculate the modulus |
d | The base of the modulus. This must be a positive number. |
- Returns
- For non-negative, the result is the same as
%
. For negative numbers, the result is -1 * (abs(n) % d)
.