Skip to content

Map

This page details functions that apply linear maps to generic 2d vectors. Many of Meantonal’s built-in functions that operate on Pitch and Interval vectors are essentially performing these maps under the hood, but these generalised mapping operations are available in case something you need isn’t a built-in.

int map_to_1d(MapVec v, Map1d T);

This function allows an arbitrary Map1d matrix to multiply a MapVec, sending it to some integer. Allows things like:

(int)map_to_1d((MapVec){p.w, p.h}, ED31);

This would send any Pitch to a 31-tone equal temperament equivalent of MIDI numbering, such that:

0C10\rightarrow\sf{C}_{-1}

1D11\rightarrow\sf{D}\flat\flat_{-1}

2C12\rightarrow\sf{C}\sharp_{-1}

3D13\rightarrow\sf{D}\flat_{-1}

4C14\rightarrow\sf{C}\sharp\sharp_{-1}

5D15\rightarrow\sf{D}_{-1}

6E16\rightarrow\sf{E}\flat\flat_{-1}

and so on…

static inline Map1D map_compose_1d_2d(Map1D A, Map2D B);

Composes a Map1D with a Map2D; essentially carries out matrix multiplication:

[a0,a1][b00b01b10b11]=[c0,c1][a_0, a_1] \begin{bmatrix} b_{00} & b_{01} \\ b_{10} & b_{11} \end{bmatrix} = [c_0, c_1]

Returns a new Map1D. Creating new maps from the composition of existing maps can save on unnecessary computation. Just be aware that floating point arithmetic is cursed, and (AB)x(AB)x does not necessarily equal A(Bx)A(Bx).

MapVec map_to_2d(MapVec v, Map2d T);

This function allows an arbitrary Map2d matrix to multiply a MapVec. If it’s an invertible matrix, this essentially facilitates a change of basis. The returned vector is another MapVec.

This could be useful if working with generalised isomorphic keyboard layouts. For example, if reading numbers off a grid intended to represent a Wicki-Hayden layout, they could be parsed into Meantonal Pitch vectors simply:

typedef struct {
int x, y;
} WickiKey;
Pitch pitch_from_key(WickiKey k) {
MapVec v = map_to_2d((MapVec) k, WICKI_FROM);
return (Pitch){v.x, v.y};
}
static inline Map2D map_compose_2d_2d(Map2D A, Map2D B);

Composes a Map2D with another Map2D; essentially carries out matrix multiplication:

[a00a01a10a11][b00b01b10b11]=[c00c01c10c11]\begin{bmatrix} a_{00} & a_{01} \\ a_{10} & a_{11} \end{bmatrix} \begin{bmatrix} b_{00} & b_{01} \\ b_{10} & b_{11} \end{bmatrix} = \begin{bmatrix} c_{00} & c_{01} \\ c_{10} & c_{11} \end{bmatrix}

Returns a new Map2D. Creating new maps from the composition of existing maps can save on unnecessary computation. Just be aware that floating point arithmetic is cursed, and (AB)x(AB)x does not necessarily equal A(Bx)A(Bx).

TuningMap tuning_map_from_fifth(double fifth, Pitch ref_pitch, double ref_freq);

Construct a TuningMap from the width of the fifth in the target tuning system in cents, along with a reference Pitch and its frequency in the tuning in Hertz (e.g. A4 = 440Hz).

TuningMap tuning_map_from_edo(int edo, Pitch ref_pitch, double ref_freq);

Construct a TuningMap for an EDO tuning system from the number of parts the octave will be divided into, along with a reference Pitch and its frequency in the tuning in Hertz (e.g. A4 = 440Hz).

double to_hz(Pitch p, TuningMap T);

Returns the frequency of a Pitch in a given tuning in Hertz.

Pitch p;
pitch_from_spn("C4");
TuningMap T = tuning_map_from_edo(12, "C4", CONCERT_C4);
to_hz(p); // 261.6255653
double to_ratio(Interval m, TuningMap T);

Returns a decimal approximation of the ratio of an Interval in a given tuning system.

Interval m;
interval_from_name("A6");
TuningMap T = tuning_map_from_edo(31, "C4", CONCERT_C4);
to_ratio(m, T); // 1.7489046221194973 (very close to 7/4)
double to_cents(Interval m, TuningMap T);

Returns the width of an Interval in a given tuning system in cents.

Interval m;
interval_from_name("P5");
TuningMap T = tuning_map_from_edo(31, "C4", CONCERT_C4);
to_cents(m, T); // 696.7741935483871
int to_pitch_number(Pitch p, TuningMap T);

Returns an ordered pitch numbering for the passed Pitch as an integer. Available in any EDO TuningMap created via TuningMap.fromEDO. For 12TET, this will be the ordinary MIDI value for a given Pitch, but for other EDO tunings it provides an ordered MIDI-equvalent mapping.