3.4. pctheory.pcseg
This module contains classes and functions for working with pcsegs. A pcseg is any permutation of pitch-classes, represented as a list of PitchClass12 or PitchClass24 elements. A row is a pcseg that contains all of the pitch-classes in some order.
Functions marked with * can be used with chromatic or microtonal pcsegs.
class InvarianceMatrix
Represents an invariance matrix, as developed by Bo Alphonse. An invariance matrix allows you to easily visualize invariances under the operations of transposition and various forms of multiplication (M5, M7, M11/I in the chromatic system). This class builds an invariance matrix automatically from two provided pcsegs and the operation requested.
InvarianceMatrix constructor
InvarianceMatrix.__init__(mx_type="T", a: list, c: list)
Constructs a InvarianceMatrix. The mx_type specifies what kind of invariance matrix is being created. (For chromatic pcsegs, these are "T", "M5", "M7", and "M11" or "I". For microtonal pcsegs, these are "T", "M5", "M7", "M11", "M13", "M17", "M19", and "M23" or "I".) You can also provide pcsegs A and C to the constructor, or you can load them later using the load_matrix() method.
InvarianceMatrix read-only properties
InvarianceMatrix.mx[list]
Gets the entire invariance matrix.
InvarianceMatrix.pcseg_a[PitchClass12]or[PitchClass24]
Gets the pcseg A.
InvarianceMatrix.pcseg_b[PitchClass12]or[PitchClass24]
Gets the transformed pcseg B.
InvarianceMatrix.pcseg_c[PitchClass12]or[PitchClass24]
Gets the pcseg C.
InvarianceMatrix methods
InvarianceMatrix.get_column(j: int)[PitchClass12]or[PitchClass24]
Gets the column at index j of the invariance matrix.
InvarianceMatrix.get_row(i: int)[PitchClass12]or[PitchClass24]
Gets the row at index i of the invariance matrix.
InvarianceMatrix.load_matrix(a: list, c: list)
Imports pcsegs A and C and generates the InvarianceMatrix.
InvarianceMatrix.print(include: list = None)
Prints the invariance matrix. You can filter the matrix by providing a list of pitch-classes as a parameter to this function. This will print only the pcs in the list, which is useful for isolating invariances at specific transpositions.
InvarianceMatrix overloaded special functions
Overloaded special functions include __getitem__(), __repr__(), and __str__(). Basically, this means that you can index an InvarianceMatrix object (for example, my_invariance_mx[i][j]) to get the contents of a specific cell. The str() implementation allows InvarianceMatrix objects to be printed.
class TwelveToneMatrix
Represents a twelve-tone matrix. This matrix is really only useful for visualization, as you can create rows as pcsegs and transform them without creating a TwelveToneMatrix object.
TwelveToneMatrix constructor
TwelveToneMatrix.__init__(row=None)
Constructs a TwelveToneMatrix. You can provide a row to initialize the matrix.
TwelveToneMatrix read-only properties
TwelveToneMatrix.matrix[list]
Gets the entire twelve-tone matrix.
TwelveToneMatrix.labels_bottom[PitchClass12]
Gets the RI labels for the bottom side of the matrix.
TwelveToneMatrix.labels_left[PitchClass12]
Gets the T labels for the right side of the matrix.
TwelveToneMatrix.labels_right[PitchClass12]
Gets the R labels for the left side of the matrix.
TwelveToneMatrix.labels_top[PitchClass12]
Gets the I labels for the top side of the matrix.
TwelveToneMatrix.row[PitchClass12]
Gets the row that represents the row-class in the TwelveToneMatrix.
TwelveToneMatrix methods
TwelveToneMatrix.get_column(j: int)[PitchClass12]
Gets the column at index j of the matrix.
TwelveToneMatrix.get_row(i: int)[PitchClass12]
Gets the row at index i of the matrix.
TwelveToneMatrix.import_row(row: list)
Imports a row and generates the TwelveToneMatrix.
TwelveToneMatrix overloaded special functions
Overloaded special functions include __getitem__(), __repr__(), and __str__(). Basically, this means that you can index an TwelveToneMatrix object (for example, my_tt_mx[i][j]) to get the contents of a specific cell. The str() implementation allows TwelveToneMatrix objects to be printed.
are_combinatorial2(row1: list, row2: list)bool
Determines if two twelve‐tone rows are hexachordally combinatorial. The rows do not need to belong to the same row‐class.
are_combinatorial3(row1: list, row2: list, row3: list)bool
Determines if three twelve‐tone rows are tetrachordally combinatorial. The rows do not need to belong to the same row‐class.
are_combinatorial4(row1: list, row2: list, row3: list, row4: list)bool
Determines if four twelve‐tone rows are trichordally combinatorial. The rows do not need to belong to the same row‐class.
bip_n(imb_n: list)[int]
Gets the basic interval pattern (BIP) of a pcseg. Requires a list of imbricated set-classes from the imb_n() function.
*create_ormap(pcseg: list){PitchClass12: int}or{PitchClass24: int}
Creates an order map (ORMAP) of a pcseg. The map is a dictionary, with PitchClass12 or PitchClass24 keys and int values (which represent the index of the pitch-class in the row).
*find_otos(pcseg1: list, pcseg2: list){OTO}
Finds all OTOs that transform pcseg1 so that it contains pcseg2. This function can be used to find individual pcs, subsegs, or the entire transformed pcseg.
generate_pcseg12_from_interval_list(interval_list: list, starting_pc=None)[PitchClass12]
Generates a chromatic pcseg from an interval list. If the starting pc is None, a random starting pc will be selected. The starting pc can be an int or PitchClass12.
generate_pcseg24_from_interval_list(interval_list: list, starting_pc=None)[PitchClass24]
Generates a microtonal pcseg from an interval list. If the starting pc is None, a random starting pc will be selected. The starting pc can be an int or PitchClass24.
generate_random_all_interval_row(starting_pc=None)[PitchClass12]
Generates a random all‐interval twelve‐tone row. The starting pc can be an int or PitchClass12.
generate_random_all_trichord_babbitt_row(starting_pc=None)[PitchClass12]
Generates a random all‐trichord twelve‐tone row after Milton Babbitt. The starting pc can be an int or PitchClass12. Note that this is not a true all‐trichord row; set‐classes [036] and [048] are excluded, and rotation is not considered.
generate_random_all_trichord_row(starting_pc=None)[PitchClass12]
Generates a random all‐trichord twelve‐tone row. The starting pc can be an int or PitchClass12. Note that this is a true all‐trichord row; all twelve trichordal set‐classes are present exactly once to within rotation. This is not the same as Babbit's all‐trichord rows, which exclude set‐classes [036] and [048].
generate_random_pcseg12(length: int, non_duplicative: False, starting_pc=None)[PitchClass12]
Generates a random chromatic pcseg. This pcseg will be a row if the length is 12 and it is nonduplicative. The starting pc can be an int or PitchClass12.
generate_random_pcseg24(length: int, non_duplicative: False, starting_pc=None)[PitchClass24]
Generates a random microtonal pcseg. The starting pc can be an int or PitchClass24.
*generate_random_pcseg_from_pcset(pcset: set)[PitchClass12]or[PitchClass24]
Generates a pcseg from a provided pcset. The order of the pitch-classes will be random. This is useful for experimenting with different orderings of a pcset.
generate_random_ten_trichord_row(starting_pc=None)[PitchClass12]
Generates a random ten‐trichord twelve‐tone row. The starting pc can be an int or PitchClass12. Rotation is not considered.
*get_intervals(pcseg: list)[int]
Gets the interval succession of a pcseg.
*get_row_class(row: list){[PitchClass12]}or[[PitchClass24]]
Gets the row‐class of a row, as a list of rows.
*get_row_dsym(row: list)int
Gets the degree of symmetry of a row.
*imb_n(pcseg: list, n: int)[SetClass12]or[SetClass24]
Gets the succession of imbricated set-classes of cardinality n from a pcseg.
*invert(pcseg: list)[PitchClass12]or[PitchClass24]
Inverts a pcset by using the M11 or M23 operations, depending on whether the pcset contains PitchClass12 or PitchClass24 elements.
is_all_interval_row(pcseg: list)bool
Determines if a pcseg is a valid all‐interval row.
is_all_trichord_babbitt_row(pcseg: list)bool
Determines if a pcseg is a valid Babbitt “all‐trichord” row. This is a ten‐trichord row that does not contain set‐classes [036] and [048] as imbricated trichords.
is_all_trichord_row(pcseg: list)bool
Determines if a pcseg is a valid all‐trichord row (not a Babbitonian all‐trichord row).
is_link_chord(pcseg: list)bool
Determines if a pcseg is a Link chord (a twelve‐tone row with the all‐trichord hexachord (ATH) as a contiguous subset).
*is_row(pcseg: list)bool
Determines if a pcseg is a valid row. A row needs to be 12 pcs long for a chromatic row, or 24 pcs long for a microtonal row, and cannot contain duplicates.
is_row_generator(rgen: list)bool
Determines if a provided row generator (rgen) can generate a valid row. A row generator is a succession of 11 intervals.
is_ten_trichord_row(pcseg: list)bool
Determines if a pcseg is a valid ten‐trichord row. A ten‐trichord row contains ten unique imbricated trichords (not counting rotations).
make_pcseg12(*args)[PitchClass12]
Creates a chromatic pcseg from one or more int values.
make_pcseg24(*args)[PitchClass24]
Creates a microtonal pcseg from one or more int values.
*multiply(pcseg: list, n: int)[PitchClass12]or[PitchClass24]
Multiplies a pcseg using the operator Mn.
*multiply_order(pcseg: list, n: int)[PitchClass12]or[PitchClass24]
Multiplies the order of a pcseg, mod the length of the pcseg.
*ormap(row: list, ormap: dict)[int]
Applies an existing ORMAP to a row, and returns a list with the mapping of that row.
*prot(pcseg: list, n: int){(PitchClass12, PitchClass12)}or{(PitchClass12, PitchClass12)}
Generates the protocol pairs of a pcseg. A protocol pair is an ordered pair of pitch-classes (p, q), such that both p and q are in the pcseg, and p comes before q in the pcseg. A complete list of protocol pairs unambiguously defines the ordering of a pcseg.
*retrograde(pcseg: list)[PitchClass12]or[PitchClass24]
Retrogrades a pcset. This is the same as list.reverse() but this function returns a copy rather than reversing the original list.
*rotate(pcset: set, n: int)[PitchClass12]or[PitchClass24]
Rotates a pcseg to the left n positions, using the operator rn.
*transpose(pcset: set, n: int)[PitchClass12]or[PitchClass24]
Transposes a pcseg using the operator Tn.
*transpositional_combination(pcseg1: list, pcseg2: list)[PitchClass12]or[PitchClass24]
Transpositionally combines two pcsegs. This is Boulez's “multiplication.”