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

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.

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