setclass package
setclass module
- class setclass.setclass.SetClass(*args: int, tonality: int = 12)[source]
Bases:
listMusical 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
ClassSetobject 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)
- 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_classesin 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
listof adjacency intervals between the pitch classes.
- property interval_vector: list
An ordered
listcontaining 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
listof 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 byinversion,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_classesis determined by the difference of the pitch class values, modulotonality. For example with tonality 12:i⟨a,b⟩ = b-a mod 12
— Rahn (1980), p. 25
- 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_classesis the smaller of the possible values ofordered_interval(differences in pitch class value):i(a,b) = min: i⟨a,b⟩, i⟨b,a⟩
— Rahn (1980), p. 28
- 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_formof {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
brightnessvalue, most packed to the left.
- property brightest_form: SetClass
The version of this set class with the largest
brightnessvalue, 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_classesabsent 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
tonalityno 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
tonalityno 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_intervalsbetween the pitch classes instead of commas, and the overallbrightness(sum of the values ofpitch_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
SetClassfrom 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:
- Returns:
A
SetClassinstance with the pitch classes found in the string.
- classmethod from_decimal(decimal: int, tonality: int = 12) SetClass[source]
Create a
SetClassfrom 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:
- Returns:
A
SetClassinstance with the pitch classes encoded in the decimal representation.
- classmethod from_forte_name(name: str) SetClass[source]
Create a
SetClassfrom 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}
- classmethod all_of_cardinality(cardinality: int, tonality: int = 12) set[source]
Returns a
setof all possibleSetClassobjects with a givencardinality.Warning
High values of tonality can take a long time to calculate (T=24 takes about a minute on an Intel i7-13700H CPU).
- classmethod darkest_of_cardinality(cardinality: int, tonality: int = 12) set[source]
Returns a
setof allSetClassobjects with a givencardinalityin their darkest forms.This produces a smaller set than
all_of_cardinality, since it eliminates set classes that are “brighter” transpositions of the darkestSetClassreturned by thedarkest_formproperty.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
cardinalityof 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
setofSetClassobjects indarkest_form.
- classmethod normal_of_cardinality(cardinality: int, tonality: int = 12) set[source]
Returns a
setof allSetClassobjects with a givencardinalityin their Rahn normal form.This produces a smaller set than
all_of_cardinality, since it eliminates set classes that are transpositions of the normalisedSetClassreturned by therahn_normal_formproperty.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
cardinalityof 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
setofSetClassobjects inrahn_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 thedarkest_form(that with the smallestbrightnessvalue), except for all the times when that is not the case!- Returns:
A
setof (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 thedarkest_form(that with the smallestbrightnessvalue), except for all the times when that is not the case!- Returns:
A
setof (cardinality,darkest_form,prime_form) tuples.