MUSX Document Model
Loading...
Searching...
No Matches
music_theory Namespace Reference

A dependency-free, header-only collection of useful functions for music theory. More...

Classes

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...
 

Enumerations

enum class  DiatonicMode : int {
  Ionian = 0 , Dorian = 1 , Phrygian = 2 , Lydian = 3 ,
  Mixolydian = 4 , Aeolian = 5 , Locrian = 6
}
 Represents the seven standard diatonic musical modes. More...
 

Functions

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.
 

Variables

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.
 

Detailed Description

A dependency-free, header-only collection of useful functions for music theory.

Enumeration Type Documentation

◆ DiatonicMode

enum class music_theory::DiatonicMode : int
strong

Represents the seven standard diatonic musical modes.

Values correspond to their roots with no sharps or flats C (0) through B (6).

Enumerator
Ionian 

major

Dorian 

minor with raised 6

Phrygian 

minor with flat 2

Lydian 

major with raised 4

Mixolydian 

major with flat 7

Aeolian 

natural minor

Locrian 

diminished with flat 2 and 5

Function Documentation

◆ calcDisplacement()

int music_theory::calcDisplacement ( int  pitchClass,
int  octave 
)
inline

Calculates the displacement value for a given absolute pitch class and octave.

Parameters
pitchClass0..6 corresponding to C..B
octaveOctave 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 ( n)
inlineconstexpr

Calculates the sign of an integer.

Parameters
nThe integer to process.
Returns
-1 for negative; 1 for non-negative.

◆ signedModulus()

template<typename T >
constexpr T music_theory::signedModulus ( n,
d 
)
constexpr

Calculates the modulus of positive and negative numbers in a predictable manner.

Template Parameters
Tan integer type
Parameters
nThe number (positive or negative) for which to calculate the modulus
dThe 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).