setclass package

setclass module

class setclass.setclass.SetClass(*args: int, tonality: int = 12)[source]

Bases: list

Musical set class, containing zero or more pitch classes. This implementation can handle set classes of any arbitrary tonality, or number of uniform divisions of the octave.

__init__(*args: int, tonality: int = 12) None[source]

Instantiate a ClassSet object with a series of integers.

Each supplied pitch class is “normalised” by modulo the tonality, the set is sorted in ascending order, and values are transposed until the lowest pitch class value is 0. For a number of divisions of the octave other than the default (Western harmony) value of 12, supply an integer value using the ‘tonality’ keyword. Example:

>>> sc1 = SetClass(0, 7, 9)
>>> sc1
SetClass{0,7,9}
>>> sc2 = SetClass(0, 2, 3, tonality=7)
>>> sc2
SetClass{0,2,3} (T=7)
Parameters:
  • *args (int) – The pitch class values.

  • tonality (int) – The tonality, or modulus, is the number of uniform divisions of the octave. If unspecified, the default value of 12 is assumed (Western harmony).

property pitch_classes: list(int)

The pitch classes as an ordered list of integers.

property tonality: int

The number of uniform divisions of the octave. The default value is 12, which represents traditional Western chromatic harmony, the octave divided into twelve semitones.

property cardinality: int

The cardinality of the set class, i.e. the number of pitch_classes.

property brightness: int

The brightness of the set class.

Brightness (B) is a property proposed by Brian Leonard, defined as the sum of the values of the pitch_classes in the set class.

property decimal: int

The decimal value of the binary representation of the pitch_classes.

Returns the decimal value of the pitch classes expressed as a binary bit mask, i.e. the sum of 2ⁱ where i is each pitch class value in ascending order. For example, set class {0,1,4,6} has a binary value of 000001010011, which is the decimal value 83.

Further reading: Goyette (2012) p. 25, citing Brinkman (1986).

property adjacency_intervals: list(int)

The ordered list of adjacency intervals between the pitch classes.

property interval_vector: list

An ordered list containing the multiplicities of each interval class in the set class. Denoted in angle-brackets, e.g. the interval vector of {0,2,4,5,7,9,11} is ⟨2,5,4,3,6,1⟩. Each element in the vector is the frequency of occurrence of the interval represented by its ordinal position, i.e. ⟨2,5,4,3,6,1⟩ means two semitones, five major seconds, four minor thirds, and so on. — Rahn (1980), p. 100.

property z_relations: list

A list of the Z-relations of this set class.

Allen Forte in his book The Structure of Atonal Music (1973) described the relationship between twins of set classes that share the same interval_vector, but are not related by inversion, complement, or transposition, as Z-related (‘Z’ for zygote from Greek: ζυγωτός, ‘joined’ or ‘paired’). This property returns all distinct set classes with the same interval vector.

For example, Forte 4-Z15 {0,1,4,6} and Forte 4-Z29 {0,1,3,7} both have iv⟨1,1,1,1,1,1⟩ but are not inversions, complements, or transpositions of each other.

ordered_interval(a: int, b: int) int[source]

Return the ordered interval of two pitch classes.

The ordered interval, or “directed interval” (Babbitt) of two pitch_classes is determined by the difference of the pitch class values, modulo tonality. For example with tonality 12:

i⟨a,b⟩ = b-a mod 12

— Rahn (1980), p. 25

Parameters:
  • a (int) – the first pitch class value.

  • b (int) – the second pitch class value.

Returns:

The ordered interval as ann integer.

unordered_interval(a: int, b: int) int[source]

Return the unordered interval of two pitch classes.

The unordered interval (also “interval distance”, “interval class”, “ic”, or “undirected interval”) of two pitch_classes is the smaller of the possible values of ordered_interval (differences in pitch class value):

i(a,b) = min: i⟨a,b⟩, i⟨b,a⟩

— Rahn (1980), p. 28

Parameters:
  • a (int) – the first pitch class value.

  • b (int) – the second pitch class value.

Returns:

The ordered interval as ann integer.

property versions: list(SetClass)

All possible zero-normalised transpositions of this set class, sorted by brightness. See Rahn (1980), Tₙ set types.

property rahn_normal_form: SetClass

The Rahn normal form of the set class.

John Rahn’s normal form described in his book Basic Atonal Theory (1980) is an algorithm to produce a unique form for each set class. Often wrongly described as “most packed to the left”, Leonard describes it as “most dispersed from the right”. Find the smallest outside interval, and if necessary proceed inwards from the right finding the smallest next interval until one result remains. See Rahn (1980), p. 33.

property rahn_prime_form: SetClass

The Rahn prime is the most dispersed from the right of the Rahn normal forms of a set class and its inversion.

property packed_left: SetClass

The form of the set class that is most packed to the left (the smallest adjacency intervals to the left). Find the smallest first adjacency interval, and proceed towards the right until one result remains.

property prime_form: SetClass

Return the prime form of the set class.

Allen Forte describes the algorithm for finding this normal form in his book The Structure of Atonal Music (1973) in section 1.2 (pp. 3-5), citing Milton Babbitt (1961). Find the forms with the smallest outside interval, and if necessary chose the form most packed to the left (the smallest adjacency intervals working from left to right).

property forte_prime: SetClass

Return the Forte prime of the set class, including its inversions. Forte’s list of named set classes included inversions, for instance his “3-11” set class has a normal form of {0,3,7} which describes the minor chord, and also describes its (set) inversion {0,5,9} which has a prime_form of {0,4,7}, the major chord.

property forte_name: str

Return the Forte name of this set class. Only applies to 12-tonality set classes.

Allen Forte listed and named all possible prime set classes in his book The Structure of Atonal Music (1973) in Appendix 1, p. 179-181.

property darkest_form: SetClass

The version of this set class with the smallest brightness value, most packed to the left.

property brightest_form: SetClass

The version of this set class with the largest brightness value, most packed to the right.

property inversion: SetClass

The inversion of this set class, transposed so the smallest pitch class is 0. Equivalent to a reflection through the 0 axis on a clock diagram.

property is_symmetrical: bool

Whether this set class is symmetrical upon inversion, for example Forte 5-Z37:

>>> sc = SetClass(0, 1, 2, 5, 9)
>>> sc.rahn_normal_form
SetClass{0,3,4,5,8}
>>> sc.inversion.rahn_normal_form
SetClass{0,3,4,5,8}
>>> sc.is_symmetrical
True
property complement: SetClass

The set class containing all pitch_classes absent in this one, transposed so the smallest pitch class is 0.

property dozenal_notation: str

A string representation using ↊ and ↋ for 10 and 11.

For a set class with a tonality no greater than 12, this property replaces the 10 and 11 pitch classes with the Dozenal Society characters ‘↊’ and ‘↋’ respectively. These are the Pitman forms from the Unicode 8.0 specification released in 2015.

property duodecimal_notation: str

A string representation using T and E for 10 and 11.

For a set class with a tonality no greater than 12, this property replaces the 10 and 11 pitch classes with the letters ‘T’ and ‘E’ respectively.

property leonard_notation: str

The string representation proposed by Brian Leonard.

Returns a string representation of this set class using subscripts to denote the adjacency_intervals between the pitch classes instead of commas, and the overall brightness (sum of the values of pitch_classes) denoted as a superscript. In standard tonality (T=12) the letters T and E are used for pitch classes 10 and 11. For example, Forte 7-34 would be written as [0₁1₂3₁4₂6₂8₂T₂]⁽³²⁾ in this scheme:

>>> SetClass.from_string('{0,1,3,4,6,8,10}').leonard_notation
[0₁1₂3₁4₂6₂8₂T₂]⁽³²⁾
classmethod from_string(string: str, tonality: int = 12) SetClass[source]

Create a SetClass from a string.

A useful convenience function for converting from various text representations of set classes that contain a sequence of zero or more integers. Non-integer content is ignored, and integers must be separated by some non-integer character(s), usually a space, comma, or similar. For instance:

>>> SetClass.from_string("Prélude à l'après-midi d'un faune uses [0,2,4,6,8,9]")
SetClass{0,2,4,6,8,9}
>>> SetClass.from_string('{0, 3, 7}', tonality=8)
SetClass{0,3,7} (T=8)
Parameters:
  • string (str) – Any string representation of a set class, containing some integer content.

  • tonality (int) – The tonality, or modulus, is the number of uniform divisions of the octave. If unspecified, the default value of 12 is assumed (Western harmony).

Returns:

A SetClass instance with the pitch classes found in the string.

classmethod from_decimal(decimal: int, tonality: int = 12) SetClass[source]

Create a SetClass from its decimal number.

A useful convenience function for converting from a decimal representation of set classes. For instance:

>>> SetClass.from_decimal(145)
SetClass{0,4,7}
>>> SetClass.from_decimal(137, tonality=8)
SetClass{0,3,7} (T=8)
Parameters:
  • decmial (int) – The decimal to convert from.

  • tonality (int) – The tonality, or modulus, is the number of uniform divisions of the octave. If unspecified, the default value of 12 is assumed (Western harmony).

Returns:

A SetClass instance with the pitch classes encoded in the decimal representation.

classmethod from_forte_name(name: str) SetClass[source]

Create a SetClass from its Forte prime form designation. Assumes 12-tonality. Name is case insensitive.

A useful convenience function for creating a set class from its Forte name. For instance:

>>> SetClass.from_forte_name('3-11')
SetClass{0,3,7}
Parameters:

name (str) – The Forte name (case insensitive).

Returns:

A SetClass instance in Forte prime form.

classmethod all_of_cardinality(cardinality: int, tonality: int = 12) set[source]

Returns a set of all possible SetClass objects with a given cardinality.

Warning

High values of tonality can take a long time to calculate (T=24 takes about a minute on an Intel i7-13700H CPU).

Parameters:
  • cardinality (int) – The cardinality of the set classes to return.

  • tonality (int) – The tonality, or modulus, is the number of uniform divisions of the octave. If unspecified, the default value of 12 is assumed (Western harmony).

Returns:

A set of SetClass objects.

classmethod darkest_of_cardinality(cardinality: int, tonality: int = 12) set[source]

Returns a set of all SetClass objects with a given cardinality in their darkest forms.

This produces a smaller set than all_of_cardinality, since it eliminates set classes that are “brighter” transpositions of the darkest SetClass returned by the darkest_form property.

Warning

High values of tonality can take a long time to calculate (T=24 takes about a minute on an Intel i7-13700H CPU).

Parameters:
  • cardinality (int) – The cardinality of the set classes to return.

  • tonality (int) – The tonality, or modulus, is the number of uniform divisions of the octave. If unspecified, the default value of 12 is assumed (Western harmony).

Returns:

A set of SetClass objects in darkest_form.

classmethod normal_of_cardinality(cardinality: int, tonality: int = 12) set[source]

Returns a set of all SetClass objects with a given cardinality in their Rahn normal form.

This produces a smaller set than all_of_cardinality, since it eliminates set classes that are transpositions of the normalised SetClass returned by the rahn_normal_form property.

Warning

High values of tonality can take a long time to calculate (T=24 takes about a minute on an Intel i7-13700H CPU).

Parameters:
  • cardinality (int) – The cardinality of the set classes to return.

  • tonality (int) – The tonality, or modulus, is the number of uniform divisions of the octave. If unspecified, the default value of 12 is assumed (Western harmony).

Returns:

A set of SetClass objects in rahn_normal_form.

classmethod bright_rahn_normal_forms() set[source]

The set of Rahn normal forms that are not the same as the darkest form.

John Rahn’s normal form from Basic Atonal Theory (1980) is an algorithm to produce a unique form for each set class (see rahn_normal_form). Most of the time it is also the same as the darkest_form (that with the smallest brightness value), except for all the times when that is not the case!

Returns:

A set of (cardinality, darkest_form, rahn_normal_form) tuples.

classmethod bright_prime_forms() set[source]

The set of Forte prime forms that are not the same as the darkest form.

Allen Forte describes the algorithm for deriving the “prime” or zeroed normal form, in his book The Structure of Atonal Music (1973) in section 1.2 (pp. 3-5), citing Milton Babbitt (1961). It produces a unique form for each set class (see prime_form), which most of the time is the same as the darkest_form (that with the smallest brightness value), except for all the times when that is not the case!

Returns:

A set of (cardinality, darkest_form, prime_form) tuples.

Module contents