Parse
The functions listed here enable the parsing of Pitch
vectors and derived types to and from strings.
Scientific Notation
Section titled “Scientific Notation”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_spn
Section titled “pitch_spn”void pitch_spn(Pitch p, char *out);
Returns the Scientific Pitch Notation name of a Pitch as a string. You must pass a char
array with at least 8 characters to store the result, which is returned via an out-param.
Pitch p;pitch_from_spn("G#5", &p);
char buf[8];pitch_spn(p, buf); // buf now holds the string "G#5"
interval_from_spn
Section titled “interval_from_spn”int interval_from_spn(const char *p_str, const char *q_str, Interval *out);
Parses two strings into Pitch
vectors from Scientific Pitch Notation to generate an Interval
vector from. Outputs via a passed in Interval
pointer. Returns 1 if anything went wrong during parsing.
Safe usage if the string is being passed in dynamically:
Interval m;if (int interval_from_spn(str1, str2, &p)) { // handle parsing error}
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}
Helmholtz Notation
Section titled “Helmholtz Notation”pitch_from_helmholtz
Section titled “pitch_from_helmholtz”int pitch_from_helmholtz(const char *s, Pitch *out);
Parses a Pitch
from Helmholtz 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_helmholtz(str, &p)) { // handle parsing error}
pitch_helmholtz
Section titled “pitch_helmholtz”void pitch_helmholtz(Pitch p, char *out);
Returns the Helmholtz pitch notation name of a Pitch as a string. You must pass a char
array with at least 16 characters to store the result, which is returned via an out-param.
Pitch p;pitch_from_helmholtz("g#'", &p);
char buf[16];pitch_helmholtz(p, buf); // buf now holds the string "g#'"
LilyPond Notation
Section titled “LilyPond Notation”pitch_from_lily
Section titled “pitch_from_lily”int pitch_from_lily(const char *s, Pitch *out);
Parses a Pitch
from LilyPond notation (absolute mode, no rhythmic values). 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_lily(str, &p)) { // handle parsing error}
pitch_lily
Section titled “pitch_lily”void pitch_lily(Pitch p, char *out);
Returns the LilyPond name of a Pitch as a string. You must pass a char
array with at least 16 characters to store the result, which is returned via an out-param.
Pitch p;pitch_from_lily("gis'", &p);
char buf[16];pitch_lily(p, buf); // buf now holds the string "gis'"
ABC Notation
Section titled “ABC Notation”pitch_from_abc
Section titled “pitch_from_abc”int pitch_from_abc(const char *s, Pitch *out);
Parses a Pitch
from ABC 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_abc(str, &p)) { // handle parsing error}
pitch_abc
Section titled “pitch_abc”void pitch_abc(Pitch p, char *out);
Returns the ABC name of a Pitch as a string. You must pass a char
array with at least 16 characters to store the result, which is returned via an out-param.
Pitch p;pitch_from_abc("^g'", &p);
char buf[16];pitch_abc(p, buf); // buf now holds the string "^g'"