Sets
This page details functions that build and operate on the PitchClassSet
, a generalised set representation where a “pitch class” is taken to mean any unique letter name + accidental combination (so and are not the same pitch class in meantonal, even if they are equivalent in the more common 12-tone pitch class sets).
Managing a PitchClassSet
Section titled “Managing a PitchClassSet”You should begin by manually initialising a PitchClassSet
to NULL
:
PitchClassSet s = NULL;
pc_set_destroy
Section titled “pc_set_destroy”You are responsible for freeing up the memory allocated to a PitchClassSet
when you are done using pc_set_destroy
:
void pc_set_destroy(PitchClassSet set);
pc_set_insert
Section titled “pc_set_insert”void pc_set_insert(PitchClassSet *set, int chroma);
To add a pitch class to a set, pass its chroma to pc_set_insert
;
PitchClassSet s = NULL;pc_set_insert(&s, 3); // adds "A" to the set
Common Queries
Section titled “Common Queries”pc_set_contains
Section titled “pc_set_contains”bool pc_set_contains(PitchClassSet set, int chroma);
Predicate function that checks whether the specified chroma is an element of the passed in PitchClassSet
.
Transformations
Section titled “Transformations”pc_set_transpose
Section titled “pc_set_transpose”PitchClassSet pc_set_transpose(PitchClassSet set, int offset);
Returns a copy of the passed in set with each element transposed by the given chroma offset.
pc_set_invert
Section titled “pc_set_invert”PitchClassSet pc_set_invert(PitchClassSet set, int axis);
Returns a copy of the passed in set with each element inverted about the passed in chroma axis. Taking the pitch_chroma
of a regular MirrorAxis
works for a second argument with this function:
PitchClassSet s = NULL;
// ...
MirrorAxis axis;axis_from_spn("C4", "G4", &axis);
PitchClassSet s_flip = pc_set_invert(s, pitch_chroma((Pitch) axis));
pc_set_union
Section titled “pc_set_union”PitchClassSet pc_set_union(PitchClassSet a, PitchClassSet b);
Creates a new set containing all the elements present in at least one of the passed in sets.
pc_set_intersection
Section titled “pc_set_intersection”PitchClassSet pc_set_intersection(PitchClassSet a, PitchClassSet b);
Creates a new set containing all the elements present in both of the passed in sets.
pc_set_difference
Section titled “pc_set_difference”PitchClassSet pc_set_difference(PitchClassSet a, PitchClassSet b);
Creates a new set containing any elements in the first set not shared with the second.