Skip to content

Pitch

This page details all the functions that create, transform or query Pitch vectors.

Pitch vectors can be initialised directly:

Pitch p = { 25, 10 }; // initialised to middle C

It’s often more convenient, however, to be able to create a new Pitch from existing vectors, or to assign them values by parsing strings in accepted formats.

int pitch_from_spn(const char *s, Pitch *out);

Parses a Pitch from Scientific Pitch Notation. Outputs the Pitch via an out-param (you must pass in a pointer to a Pitch). Returns 1 if there is a parsing error.

Safe usage if the string is being passed in dynamically:

Pitch p;
if (int pitch_from_spn(str, &p)) {
// handle parsing error
}
Pitch pitch_from_chroma(int chroma, int octave);

Creates a Pitch vector from a specified chroma (signed distance from C in 5ths) and octave (following SPN numbering).

These functions query commonly required information from Pitch vectors.

int pitch_chroma(Pitch p);

Returns the number of perfect fifths (signed) separating a Pitch from C. Abstracts octave information away.

int pitch_letter(Pitch p);

Returns the offset of a Pitch’s letter from ‘A’ / ‘a’. It’s up to you to add ‘A’ or ‘a’ to the result to get an actual character though!

int pitch_accidental(Pitch p);

Returns a Pitch’s accidental as an offset from \natural, so:

\sharp\sharp2
\sharp1
\natural0
\flat-1
\flat\flat-2

etc. for triple sharps/flats and beyond.

int pitch_octave(Pitch p);

Returns the SPN octave number of a Pitch. Middle C is 4.

int pitch_midi(Pitch p);

Returns the standard MIDI value for a given Pitch.

bool pitches_equal(Pitch p, Pitch q);

Predicate function that checks whether two Pitch vectors are equal.

bool pitches_enharmonic(Pitch m, Pitch n, int edo);

Predicate function that checks whether two Pitch vectors are enharmonics in a given EDO tuning system. The third parameter ‘edo’ is for passing in the tuning system to check against. So for example:

Pitch p, q;
pitch_from_spn("C#4", &p);
pitch_from_spn("Db4", &q);
pitches_enharmonic(p, q, 12); // true; C# and Db are enharmonic in 12tet
pitches_enharmonic(p, q, 31); // false; C# and Db are not enharmonic in 31tet
pitch_from_spn("Gbb4", &p);
pitch_from_spn("Ex4", &q);
pitches_enharmonic(p, q, 31); // true; Gbb and Ex are enharmonic in 31tet
pitches_enharmonic(p, q, 12); // false; Gbb and Ex are not enharmonic in 12tet
Pitch transpose_real(Pitch p, Interval m);

This function takes a Pitch and an Interval, and returns a new Pitch formed by their sum.

MirrorAxis axis_create(Pitch p, Pitch q);

Creates a MirrorAxis about which to invert a Pitch by adding two Pitch vectors together. To be used in conjunction with pitch_invert.

int axis_from_spn(char *p_str, char *q_str, MirrorAxis *out);

Creates a MirrorAxis about which to invert a Pitch by adding two Pitch vectors together. To be used in conjunction with pitch_invert.

Unlike axis_create, axis_from_spn takes two pitch names as SPN strings, and returns the created MirrorAxis via a passed in pointer. Returns 1 if there is a parsing error.

Safe usage if the strings are being passed in dynamically:

MirrorAxis a;
if (int axis_from_spn(str1, str2, &a)) {
// handle parsing error
}
Pitch pitch_invert(Pitch p, MirrorAxis a);

Invert a Pitch about a passed in MirrorAxis, returning a new Pitch (the result of subtracting p from a). Inversion is real, not diatonic.

StandardPitch pitch_to_standard(Pitch p);

Converts from Meantonal’s standard Pitch representation to the StandardPitch representation. Useful as a preliminary step to rendering standard notation.

Pitch pitch_from_standard(StandardPitch p);

Converts from the StandardPitch type back to a regular Pitch vector.