Pitch
This page details all the functions that create, transform or query Pitch
vectors.
Creating Pitches
Section titled “Creating Pitches”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.
pitch_from_spn
Section titled “pitch_from_spn”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_from_chroma
Section titled “pitch_from_chroma”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).
Common Queries
Section titled “Common Queries”These functions query commonly required information from Pitch
vectors.
pitch_chroma
Section titled “pitch_chroma”int pitch_chroma(Pitch p);
Returns the number of perfect fifths (signed) separating a Pitch
from C. Abstracts octave information away.
pitch_letter
Section titled “pitch_letter”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!
pitch_accidental
Section titled “pitch_accidental”int pitch_accidental(Pitch p);
Returns a Pitch
’s accidental as an offset from , so:
2 | |
1 | |
0 | |
-1 | |
-2 |
etc. for triple sharps/flats and beyond.
pitch_octave
Section titled “pitch_octave”int pitch_octave(Pitch p);
Returns the SPN octave number of a Pitch
. Middle C is 4.
pitch_midi
Section titled “pitch_midi”int pitch_midi(Pitch p);
Returns the standard MIDI value for a given Pitch
.
pitches_equal
Section titled “pitches_equal”bool pitches_equal(Pitch p, Pitch q);
Predicate function that checks whether two Pitch
vectors are equal.
pitches_enharmonic
Section titled “pitches_enharmonic”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 12tetpitches_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 31tetpitches_enharmonic(p, q, 12); // false; Gbb and Ex are not enharmonic in 12tet
Transformations
Section titled “Transformations”transpose_real
Section titled “transpose_real”Pitch transpose_real(Pitch p, Interval m);
This function takes a Pitch
and an Interval
, and returns a new Pitch
formed by their sum.
axis_create
Section titled “axis_create”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
.
axis_from_spn
Section titled “axis_from_spn”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_invert
Section titled “pitch_invert”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.
Conversions
Section titled “Conversions”pitch_to_standard
Section titled “pitch_to_standard”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_from_standard
Section titled “pitch_from_standard”Pitch pitch_from_standard(StandardPitch p);
Converts from the StandardPitch
type back to a regular Pitch
vector.