PatternList

class datastructuretools.PatternList(items=None, item_class=None)

Pattern list.

>>> import abjad
>>> from abjad.tools import rhythmmakertools

Three patterns:

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

Two patterns:

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

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.PatternList.PatternList" [color=black, fontcolor=white, group=2, label=<<B>PatternList</B>>, shape=box, style="filled, rounded"]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" [color=3, group=2, label=TypedCollection, shape=oval, style=bold]; "abjad.tools.datastructuretools.TypedTuple.TypedTuple" [color=3, group=2, label=TypedTuple, shape=box]; "abjad.tools.datastructuretools.TypedCollection.TypedCollection" -> "abjad.tools.datastructuretools.TypedTuple.TypedTuple"; "abjad.tools.datastructuretools.TypedTuple.TypedTuple" -> "abjad.tools.datastructuretools.PatternList.PatternList"; } 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"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Attribute summary

count(item) Counts item in collection.
get_matching_pattern(index, total_length[, …]) Gets pattern matching index.
get_matching_payload(index, total_length[, …]) Gets payload attached to pattern matching index.
index(item) Gets index of item in collection.
item_class Gets item class of collection.
items Gets items in collection.
__add__(argument) Adds typed tuple to argument.
__contains__(item) Is true if typed tuple 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.
__getitem__(argument) Gets item or slice identified by argument.
__hash__() Hashes typed tuple.
__iter__() Iterates typed collection.
__len__() Gets length of typed collection.
__mul__(argument) Multiplies typed tuple by argument.
__ne__(argument) Is true when Abjad object does not equal argument.
__radd__(argument) Right-adds argument to typed tuple.
__repr__() Gets interpreter representation of Abjad object.
__rmul__(argument) Multiplies argument by typed tuple.

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.

Methods

(TypedTuple).count(item)

Counts item in collection.

Coerces item.

Returns nonnegative integer.

PatternList.get_matching_pattern(index, total_length, rotation=None)

Gets pattern matching index.

Two patterns:

>>> patterns = abjad.PatternList([
...     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.PatternList([
...     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.

PatternList.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.PatternList([
...     abjad.Pattern(
...         indices=[0],
...         payload=rhythmmakertools.NoteRhythmMaker(),
...         period=1,
...         ),
...     abjad.Pattern(
...         indices=[-3, -2, -1],
...         payload=rhythmmakertools.EvenDivisionRhythmMaker(),
...         ),
...     ])

Over ten indices:

>>> for i in range(10):
...     match = patterns.get_matching_payload(i, 10)
...     print(i, match)
...
0 NoteRhythmMaker()
1 NoteRhythmMaker()
2 NoteRhythmMaker()
3 NoteRhythmMaker()
4 NoteRhythmMaker()
5 NoteRhythmMaker()
6 NoteRhythmMaker()
7 EvenDivisionRhythmMaker(denominators=[8], preferred_denominator='from_counts')
8 EvenDivisionRhythmMaker(denominators=[8], preferred_denominator='from_counts')
9 EvenDivisionRhythmMaker(denominators=[8], preferred_denominator='from_counts')

Over fifteen indices:

>>> for i in range(15):
...     match = patterns.get_matching_payload(i, 15)
...     print(i, match)
...
0 NoteRhythmMaker()
1 NoteRhythmMaker()
2 NoteRhythmMaker()
3 NoteRhythmMaker()
4 NoteRhythmMaker()
5 NoteRhythmMaker()
6 NoteRhythmMaker()
7 NoteRhythmMaker()
8 NoteRhythmMaker()
9 NoteRhythmMaker()
10 NoteRhythmMaker()
11 NoteRhythmMaker()
12 EvenDivisionRhythmMaker(denominators=[8], preferred_denominator='from_counts')
13 EvenDivisionRhythmMaker(denominators=[8], preferred_denominator='from_counts')
14 EvenDivisionRhythmMaker(denominators=[8], preferred_denominator='from_counts')
(TypedTuple).index(item)

Gets index of item in collection.

Coerces item.

Returns nonnegative integer.

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

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

(AbjadObject).__ne__(argument)

Is true when Abjad object does not equal argument. Otherwise false.

Returns true or false.

(TypedTuple).__radd__(argument)

Right-adds argument to typed tuple.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(TypedTuple).__rmul__(argument)

Multiplies argument by typed tuple.

Returns new typed tuple.