Interval
This page details all the functions that create, transform or query Interval
vectors.
Creating Intervals
Section titled “Creating Intervals”Interval
vectors can be initialised directly:
Interval m = { 3, 0 }; // initialised to an augmented 4th
It’s often more convenient, however, to be able to create new Interval
s from old, or to assign them values by parsing strings in accepted formats.
interval_from_name
Section titled “interval_from_name”int interval_from_name(const char *s, Interval *out);
Parses an Interval
from a standard abbreviated name. Outputs via a passed in Interval
pointer. Returns 1 if anything went wrong during parsing.
Interval name can be in the scientific style. For example:
- “M3” will make a major third.
- “m3” will make a minor third.
- “P5” will make a perfect fifth.
- “A6” will make an augmented 6th.
- “d5” will make a diminished 5th.
It can also be in the “jazz” style:
- Plain numbers like “5” and “7” will default to major.
- b or # will alter intervals from these default positions, and can be stacked.
So “m7” and “b7” will both produce a minor 7th Interval
vector.
Safe usage if the string is being passed in dynamically:
Interval m;if (int interval_from_name(str, &p)) { // handle parsing error}
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}
interval_between
Section titled “interval_between”Interval interval_between(Pitch p, Pitch q);
Creates an Interval
from two Pitch
vectors by subtracting the first from the second.
Common Queries
Section titled “Common Queries”interval_chroma
Section titled “interval_chroma”int interval_chroma(Interval m);
Returns the number of perfect fifths (signed) separating an Interval
from the unison. Abstracts octave information away.
stepspan
Section titled “stepspan”int stepspan(Interval m);
Returns the number of diatonic steps subtended by an interval. Basically the same as the standard generic interval sizes used in musical discourse, except zero-indexed so a “third” will have a stepspan of 2, not 3.
This format is more amenable to basic arithmetic, and allows negative stepspans to represent descending horizontal intervals, or voice crossed vertical intervals.
interval_quality
Section titled “interval_quality”int interval_quality(Interval m);
Returns an Interval
’s quality as a signed integer:
Augmented | 2 |
Major | 1 |
Perfect | 0 |
Minor | -1 |
Diminished | -2 |
etc. for doubly-augmented/diminished intervals and beyond.
intervals_equal
Section titled “intervals_equal”bool intervals_equal(Interval m, Interval n);
Predicate function that checks whether two Interval
vectors are equal.
intervals_enharmonic
Section titled “intervals_enharmonic”bool intervals_enharmonic(Interval m, Interval 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:
Interval m, n;interval_from_name("A6", &m);interval_from_name("m7", &n);intervals_enharmonic(m, n, 12); // true; A6 and m7 are enharmonic in 12tetintervals_enharmonic(m, n, 31); // false; A6 and m7 are not enharmonic in 31tet
interval_from_name("dddd10", &m);interval_from_name("p8", &n);intervals_enharmonic(m, n, 31); // true;intervals_enharmonic(m, n, 12); // false;
Transformations
Section titled “Transformations”interval_negate
Section titled “interval_negate”Interval interval_negate(Interval m);
Flips the direction of an Interval
. Horizontally, an ascending major 3rd will become a descending major 3rd. Vertically, flipping an Interval
represents voices swapping locations.
intervals_add
Section titled “intervals_add”Interval intervals_add(Interval m, Interval n);
Adds two Interval
vectors to produce a new Interval
.
interval_simple
Section titled “interval_simple”Interval interval_simple(Interval m);
Reduces an interval’s size until it is smaller than an octave. This includes the octave, which is considered a compound unison here.