PatternTuple

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=1]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjad/utilities/../system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", label="Abjad\nObject", target=_top]; } subgraph "cluster_abjad.utilities" { graph [label="abjad.utilities"]; node [color=2]; "abjad.utilities.PatternTuple.PatternTuple" [URL="../api/abjad/utilities/PatternTuple.html#abjad.utilities.PatternTuple.PatternTuple", color=black, fontcolor=white, label="Pattern\nTuple", target=_top]; "abjad.utilities.TypedCollection.TypedCollection" [URL="../api/abjad/utilities/TypedCollection.html#abjad.utilities.TypedCollection.TypedCollection", label="Typed\nCollection", shape=oval, style=bold, target=_top]; "abjad.utilities.TypedTuple.TypedTuple" [URL="../api/abjad/utilities/TypedTuple.html#abjad.utilities.TypedTuple.TypedTuple", label="Typed\nTuple", target=_top]; "abjad.utilities.TypedCollection.TypedCollection" -> "abjad.utilities.TypedTuple.TypedTuple"; "abjad.utilities.TypedTuple.TypedTuple" -> "abjad.utilities.PatternTuple.PatternTuple"; } subgraph cluster_builtins { graph [label=builtins]; node [color=3]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } subgraph "cluster_collections.abc" { graph [label="collections.abc"]; node [color=4]; "collections.abc.Collection" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Collection", label=Collection, shape=oval, style=bold, target=_top]; "collections.abc.Container" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Container", label=Container, shape=oval, style=bold, target=_top]; "collections.abc.Iterable" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Iterable", label=Iterable, shape=oval, style=bold, target=_top]; "collections.abc.Reversible" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Reversible", label=Reversible, shape=oval, style=bold, target=_top]; "collections.abc.Sequence" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Sequence", label=Sequence, shape=oval, style=bold, target=_top]; "collections.abc.Sized" [URL="https://docs.python.org/3.6/library/collections.abc.html#collections.abc.Sized", label=Sized, shape=oval, style=bold, target=_top]; "collections.abc.Collection" -> "collections.abc.Sequence"; "collections.abc.Container" -> "collections.abc.Collection"; "collections.abc.Iterable" -> "collections.abc.Collection"; "collections.abc.Iterable" -> "collections.abc.Reversible"; "collections.abc.Reversible" -> "collections.abc.Sequence"; "collections.abc.Sized" -> "collections.abc.Collection"; } "abjad.system.AbjadObject.AbjadObject" -> "abjad.utilities.TypedCollection.TypedCollection"; "builtins.object" -> "abjad.system.AbjadObject.AbjadObject"; "builtins.object" -> "collections.abc.Container"; "builtins.object" -> "collections.abc.Iterable"; "builtins.object" -> "collections.abc.Sized"; "collections.abc.Sequence" -> "abjad.utilities.TypedTuple.TypedTuple"; }

class abjad.utilities.PatternTuple.PatternTuple(items=None, item_class=None)

Pattern tuple.

Three patterns:

>>> patterns = abjad.PatternTuple([
...     abjad.Pattern(
...         indices=[0, 1, 7],
...         period=10,
...         ),
...     abjad.Pattern(
...         indices=[-2, -1],
...         ),
...     abjad.Pattern(
...         indices=[2],
...         period=3,
...         ),
...     ])
>>> abjad.f(patterns)
abjad.PatternTuple(
    (
        abjad.Pattern(
            indices=[0, 1, 7],
            period=10,
            ),
        abjad.Pattern(
            indices=[-2, -1],
            ),
        abjad.Pattern(
            indices=[2],
            period=3,
            ),
        )
    )

Two patterns:

>>> patterns = abjad.PatternTuple([
...     abjad.Pattern(
...         indices=[1],
...         period=2,
...         ),
...     abjad.Pattern(
...         indices=[-3, -2, -1],
...         ),
...     ])
>>> abjad.f(patterns)
abjad.PatternTuple(
    (
        abjad.Pattern(
            indices=[1],
            period=2,
            ),
        abjad.Pattern(
            indices=[-3, -2, -1],
            ),
        )
    )

Attributes Summary

get_matching_pattern Gets pattern matching index.
get_matching_payload Gets payload attached to pattern matching index.

Special methods

(TypedTuple).__add__(argument)

Adds typed tuple to argument.

Returns new typed tuple.

(TypedTuple).__contains__(item)

Is true if typed tuple contains item.

Coerces item.

Returns none.

(TypedCollection).__eq__(argument)

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

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to '' or 'storage'. Interprets '' equal to 'storage'.

Returns string.

(TypedTuple).__getitem__(argument)

Gets item or slice identified by argument.

Returns item or new typed tuple.

(TypedTuple).__hash__()

Hashes typed tuple.

Returns integer.

(TypedCollection).__iter__()

Iterates typed collection.

Returns generator.

(TypedCollection).__len__()

Gets length of typed collection.

Returns nonnegative integer.

(TypedTuple).__mul__(argument)

Multiplies typed tuple by argument.

Returns new typed tuple.

(TypedTuple).__radd__(argument)

Right-adds argument to typed tuple.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(Sequence).__reversed__()
(TypedTuple).__rmul__(argument)

Multiplies argument by typed tuple.

Returns new typed tuple.


Methods

(TypedTuple).count(item)

Counts item in collection.

Coerces item.

Returns nonnegative integer.

get_matching_pattern(index, total_length, rotation=None)

Gets pattern matching index.

Two patterns:

>>> patterns = abjad.PatternTuple([
...     abjad.Pattern(
...         indices=[1],
...         period=2,
...         ),
...     abjad.Pattern(
...         indices=[-3, -2, -1],
...         ),
...     ])

Gets patterns that match the first ten indices:

>>> for i in range(10):
...     match = patterns.get_matching_pattern(i, 10)
...     print(i, match)
...
0 None
1 Pattern(indices=[1], period=2)
2 None
3 Pattern(indices=[1], period=2)
4 None
5 Pattern(indices=[1], period=2)
6 None
7 Pattern(indices=[-3, -2, -1])
8 Pattern(indices=[-3, -2, -1])
9 Pattern(indices=[-3, -2, -1])

Last three indices match the second pattern.

Gets patterns that match next ten indices:

>>> for i in range(10, 20):
...     match = patterns.get_matching_pattern(i, 10)
...     print(i, match)
...
10 None
11 Pattern(indices=[1], period=2)
12 None
13 Pattern(indices=[1], period=2)
14 None
15 Pattern(indices=[1], period=2)
16 None
17 Pattern(indices=[1], period=2)
18 None
19 Pattern(indices=[1], period=2)

Last three indices no longer match the second pattern.

Gets patterns that match the first ten indices, with rotation set to 1:

>>> for i in range(10):
...     match = patterns.get_matching_pattern(i, 10, rotation=1)
...     print(i, match)
...
0 Pattern(indices=[1], period=2)
1 None
2 Pattern(indices=[1], period=2)
3 None
4 Pattern(indices=[1], period=2)
5 None
6 Pattern(indices=[1], period=2)
7 Pattern(indices=[-3, -2, -1])
8 Pattern(indices=[-3, -2, -1])
9 Pattern(indices=[-3, -2, -1])

Matching indices of first pattern offset by 1.

Gets patterns that match next ten indices with rotation set to 1:

>>> for i in range(10, 20):
...     match = patterns.get_matching_pattern(i, 10, rotation=1)
...     print(i, match)
...
10 Pattern(indices=[1], period=2)
11 None
12 Pattern(indices=[1], period=2)
13 None
14 Pattern(indices=[1], period=2)
15 None
16 Pattern(indices=[1], period=2)
17 None
18 Pattern(indices=[1], period=2)
19 None

Matching indices of first pattern offset by 1.

With inverted patterns:

>>> patterns = abjad.PatternTuple([
...     abjad.Pattern(
...         indices=[-3],
...         inverted=True,
...         ),
...     ])
>>> for i in range(10):
...     match = patterns.get_matching_pattern(i, 10)
...     print(i, match)
...
0 Pattern(indices=[-3], inverted=True)
1 Pattern(indices=[-3], inverted=True)
2 Pattern(indices=[-3], inverted=True)
3 Pattern(indices=[-3], inverted=True)
4 Pattern(indices=[-3], inverted=True)
5 Pattern(indices=[-3], inverted=True)
6 Pattern(indices=[-3], inverted=True)
7 None
8 Pattern(indices=[-3], inverted=True)
9 Pattern(indices=[-3], inverted=True)

Returns pattern or none.

get_matching_payload(index, total_length, rotation=None)

Gets payload attached to pattern matching index.

Two patterns. Underlying notes with even divisions assigned to the last three indices:

>>> patterns = abjad.PatternTuple([
...     abjad.Pattern(
...         indices=[0],
...         payload='staccato',
...         period=1,
...         ),
...     abjad.Pattern(
...         indices=[-3, -2, -1],
...         payload='tenuto',
...         ),
...     ])

Over ten indices:

>>> for i in range(10):
...     match = patterns.get_matching_payload(i, 10)
...     print(i, match)
...
0 staccato
1 staccato
2 staccato
3 staccato
4 staccato
5 staccato
6 staccato
7 tenuto
8 tenuto
9 tenuto

Over fifteen indices:

>>> for i in range(15):
...     match = patterns.get_matching_payload(i, 15)
...     print(i, match)
...
0 staccato
1 staccato
2 staccato
3 staccato
4 staccato
5 staccato
6 staccato
7 staccato
8 staccato
9 staccato
10 staccato
11 staccato
12 tenuto
13 tenuto
14 tenuto
(TypedTuple).index(item)

Gets index of item in collection.

Coerces item.

Returns nonnegative integer.


Read-only properties

(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.