PitchSet

class pitchtools.PitchSet(items=None, item_class=None)

Pitch set.

Numbered pitch set:

>>> set_ = PitchSet(
...     items=[-2, -1.5, 6, 7, -1.5, 7],
...     item_class=NumberedPitch,
...     )
>>> set_
PitchSet([-2, -1.5, 6, 7])
>>> f(set_)
pitchtools.PitchSet(
    [-2, -1.5, 6, 7]
    )

Named pitch set:

>>> set_ = PitchSet(
...     ['bf,', 'aqs', "fs'", "g'", 'bqf', "g'"],
...     item_class=NamedPitch,
...     )
>>> set_
PitchSet(['bf,', 'aqs', 'bqf', "fs'", "g'"])
>>> f(set_)
pitchtools.PitchSet(
    ['bf,', 'aqs', 'bqf', "fs'", "g'"]
    )

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_datastructuretools { graph [label=datastructuretools]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" [color=3, group=2, label=TypedCollection, shape=oval, style=bold]; "abjad.tools.datastructuretools.TypedFrozenset.TypedFrozenset" [color=3, group=2, label=TypedFrozenset, shape=box]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" -> "abjad.tools.datastructuretools.TypedFrozenset.TypedFrozenset"; } subgraph cluster_pitchtools { graph [label=pitchtools]; "abjad.tools.pitchtools.PitchSet.PitchSet" [color=black, fontcolor=white, group=3, label=<<B>PitchSet</B>>, shape=box, style="filled, rounded"]; "abjad.tools.pitchtools.Set.Set" [color=4, group=3, label=Set, shape=oval, style=bold]; "abjad.tools.pitchtools.Set.Set" -> "abjad.tools.pitchtools.PitchSet.PitchSet"; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.datastructuretools.TypedCollection.TypedCollection"; "abjad.tools.datastructuretools.TypedFrozenset.TypedFrozenset" -> "abjad.tools.pitchtools.Set.Set"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Attribute summary

cardinality Gets cardinality of set.
copy() Copies typed frozen set.
difference(argument) Typed frozen set set-minus argument.
duplicate_pitch_classes Gets duplicate pitch-classes in pitch set.
from_selection(class_, selection[, item_class]) Makes pitch set from selection.
hertz Gets hertz of pitches in pitch segment.
intersection(argument) Set-theoretic intersection of typed frozen set and argument.
invert(axis) Inverts pitch set about axis.
is_pitch_class_unique Is true when pitch set is pitch-class-unique.
isdisjoint(argument) Is true when typed frozen set shares no elements with argument.
issubset(argument) Is true when typed frozen set is a subset of argument.
issuperset(argument) Is true when typed frozen set is a superset of argument.
item_class Gets item class of collection.
items Gets items in collection.
register(pitch_classes) Registers pitch_classes by pitch set.
symmetric_difference(argument) Symmetric difference of typed frozen set and argument.
transpose([n]) Transposes pitch set by index n.
union(argument) Union of typed frozen set and argument.
__and__(argument) Logical AND of typed frozen set and argument.
__contains__(item) Is true when typed collection contains item.
__eq__(argument) Is true when argument is a typed collection with items that compare equal to those of this typed collection.
__format__([format_specification]) Formats Abjad object.
__ge__(argument) Is true when typed frozen set is greater than or equal to argument.
__gt__(argument) Is true when typed frozen set is greater than argument.
__hash__() Hashes typed frozen set.
__illustrate__() Illustrates pitch set.
__iter__() Iterates typed collection.
__le__(argument) Is true when typed frozen set is less than or equal to argument.
__len__() Gets length of typed collection.
__lt__(argument) Is true when typed frozen set is less than argument.
__ne__(argument) Is true when typed frozen set is not equal to argument.
__or__(argument) Logical OR of typed frozen set and argument.
__repr__() Gets interpreter representation of Abjad object.
__str__() Gets string representation.
__sub__(argument) Subtracts argument from typed frozen set.
__xor__(argument) Logical XOR of typed frozen set and argument.

Read-only properties

(Set).cardinality

Gets cardinality of set.

Defined equal to length of set.

Returns nonnegative integer.

PitchSet.duplicate_pitch_classes

Gets duplicate pitch-classes in pitch set.

Returns pitch-class set.

PitchSet.hertz

Gets hertz of pitches in pitch segment.

>>> pitch_set = PitchSet('c e g b')
>>> sorted(pitch_set.hertz)
[130.8127826502993, 164.81377845643496, 195.99771799087463, 246.94165062806206]

Returns set.

PitchSet.is_pitch_class_unique

Is true when pitch set is pitch-class-unique. Otherwise false.

Returns true or false.

(TypedCollection).item_class

Gets item class of collection.

Collection coerces items according to item_class.

Returns class.

(TypedCollection).items

Gets items in collection.

Returns list.

Methods

(TypedFrozenset).copy()

Copies typed frozen set.

Returns new typed frozen set.

(TypedFrozenset).difference(argument)

Typed frozen set set-minus argument.

Returns new typed frozen set.

(TypedFrozenset).intersection(argument)

Set-theoretic intersection of typed frozen set and argument.

Returns new typed frozen set.

PitchSet.invert(axis)

Inverts pitch set about axis.

Returns new pitch set.

(TypedFrozenset).isdisjoint(argument)

Is true when typed frozen set shares no elements with argument. Otherwise false.

Returns true or false.

(TypedFrozenset).issubset(argument)

Is true when typed frozen set is a subset of argument. Otherwise false.

Returns true or false.

(TypedFrozenset).issuperset(argument)

Is true when typed frozen set is a superset of argument. Otherwise false.

Returns true or false.

PitchSet.register(pitch_classes)

Registers pitch_classes by pitch set.

>>> pitch_set = PitchSet(
...     items=[10, 19, 20, 23, 24, 26, 27, 29, 30, 33, 37, 40],
...     item_class=NumberedPitch,
...     )
>>> pitch_classes = [10, 0, 2, 6, 8, 7, 5, 3, 1, 9, 4, 11]
>>> pitches = pitch_set.register(pitch_classes)
>>> for pitch in pitches:
...     pitch
... 
NumberedPitch(10)
NumberedPitch(24)
NumberedPitch(26)
NumberedPitch(30)
NumberedPitch(20)
NumberedPitch(19)
NumberedPitch(29)
NumberedPitch(27)
NumberedPitch(37)
NumberedPitch(33)
NumberedPitch(40)
NumberedPitch(23)

Returns list of zero or more numbered pitches.

(TypedFrozenset).symmetric_difference(argument)

Symmetric difference of typed frozen set and argument.

Returns new typed frozen set.

PitchSet.transpose(n=0)

Transposes pitch set by index n.

Returns new pitch set.

(TypedFrozenset).union(argument)

Union of typed frozen set and argument.

Returns new typed frozen set.

Class & static methods

classmethod PitchSet.from_selection(class_, selection, item_class=None)

Makes pitch set from selection.

>>> staff_1 = Staff("c'4 <d' fs' a'>4 b2")
>>> staff_2 = Staff("c4. r8 g2")
>>> selection = select((staff_1, staff_2))
>>> PitchSet.from_selection(selection)
PitchSet(['c', 'g', 'b', "c'", "d'", "fs'", "a'"])

Returns pitch set.

Special methods

(TypedFrozenset).__and__(argument)

Logical AND of typed frozen set and argument.

Returns new typed frozen set.

(TypedCollection).__contains__(item)

Is true when typed collection contains item. Otherwise false.

Returns true or false.

(TypedCollection).__eq__(argument)

Is true when argument is a typed collection with items that compare equal to those of this typed collection. Otherwise false.

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

(TypedFrozenset).__ge__(argument)

Is true when typed frozen set is greater than or equal to argument. Otherwise false.

Returns true or false.

(TypedFrozenset).__gt__(argument)

Is true when typed frozen set is greater than argument. Otherwise false.

Returns true or false.

(TypedFrozenset).__hash__()

Hashes typed frozen set.

Returns integer.

PitchSet.__illustrate__()

Illustrates pitch set.

Treble and bass pitches:

>>> set_ = PitchSet(
...     items=[-2, -1.5, 6, 7, -1.5, 7],
...     item_class=NumberedPitch,
...     )
>>> show(set_) 

Treble pitches only:

>>> set_ = PitchSet(
...     items=[6, 7, 7],
...     item_class=NumberedPitch,
...     )
>>> show(set_) 

Returns LilyPond file.

(TypedCollection).__iter__()

Iterates typed collection.

Returns generator.

(TypedFrozenset).__le__(argument)

Is true when typed frozen set is less than or equal to argument. Otherwise false.

Returns true or false.

(TypedCollection).__len__()

Gets length of typed collection.

Returns nonnegative integer.

(TypedFrozenset).__lt__(argument)

Is true when typed frozen set is less than argument. Otherwise false.

Returns true or false.

(TypedFrozenset).__ne__(argument)

Is true when typed frozen set is not equal to argument. Otherwise false.

Returns true or false.

(TypedFrozenset).__or__(argument)

Logical OR of typed frozen set and argument.

Returns new typed frozen set.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(Set).__str__()

Gets string representation.

Returns string.

(TypedFrozenset).__sub__(argument)

Subtracts argument from typed frozen set.

Returns new typed frozen set.

(TypedFrozenset).__xor__(argument)

Logical XOR of typed frozen set and argument.

Returns new typed frozen set.