Skip to content

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 D\sf{D}\flat and C\sf{C}\sharp are not the same pitch class in meantonal, even if they are equivalent in the more common 12-tone pitch class sets).

You should begin by manually initialising a PitchClassSet to NULL:

PitchClassSet s = NULL;

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);
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
bool pc_set_contains(PitchClassSet set, int chroma);

Predicate function that checks whether the specified chroma is an element of the passed in PitchClassSet.

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.

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));
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.

PitchClassSet pc_set_intersection(PitchClassSet a, PitchClassSet b);

Creates a new set containing all the elements present in both of the passed in sets.

PitchClassSet pc_set_difference(PitchClassSet a, PitchClassSet b);

Creates a new set containing any elements in the first set not shared with the second.