PatternInventory

class patterntools.PatternInventory(items=None, item_class=None)

Pattern inventory.

Example 1. Inventory of three patterns:

>>> inventory = patterntools.PatternInventory([
...     patterntools.Pattern(
...         indices=[0, 1, 7],
...         period=10,
...         ),
...     patterntools.Pattern(
...         indices=[-2, -1],
...         ),
...     patterntools.Pattern(
...         indices=[2],
...         period=3,
...         ),
...     ])
>>> print(format(inventory))
patterntools.PatternInventory(
    (
        patterntools.Pattern(
            indices=(0, 1, 7),
            period=10,
            ),
        patterntools.Pattern(
            indices=(-2, -1),
            ),
        patterntools.Pattern(
            indices=(2,),
            period=3,
            ),
        )
    )

Example 2. Inventory of two patterns:

>>> inventory = patterntools.PatternInventory([
...     patterntools.Pattern(
...         indices=[1],
...         period=2,
...         ),
...     patterntools.Pattern(
...         indices=[-3, -2, -1],
...         ),
...     ])
>>> print(format(inventory))
patterntools.PatternInventory(
    (
        patterntools.Pattern(
            indices=(1,),
            period=2,
            ),
        patterntools.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.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"; } subgraph cluster_patterntools { graph [label=patterntools]; "abjad.tools.patterntools.PatternInventory.PatternInventory" [color=black, fontcolor=white, group=3, label=<<B>PatternInventory</B>>, shape=box, style="filled, rounded"]; } 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.TypedTuple.TypedTuple" -> "abjad.tools.patterntools.PatternInventory.PatternInventory"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Attribute summary

count(item) Changes item to item.
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) Changes item to item.
item_class Item class to coerce items into.
items Gets collection items.
__add__(expr) Adds typed tuple to expr.
__contains__(item) Change item to item and return true if item exists in collection.
__eq__(expr) Is true when expr is a typed collection with items that compare equal to those of this typed collection.
__format__([format_specification]) Formats Abjad object.
__getitem__(i) Gets i from type tuple.
__getslice__(start, stop) Gets slice from start to stop in typed tuple.
__hash__() Hashes typed tuple.
__iter__() Iterates typed collection.
__len__() Length of typed collection.
__mul__(expr) Multiplies typed tuple by expr.
__ne__(expr) Is true when expr is not a typed collection with items equal to this typed collection.
__radd__(expr) Right-adds expr to typed tuple.
__repr__() Gets interpreter representation of Abjad object.
__rmul__(expr) Multiplies expr by typed tuple.

Read-only properties

(TypedCollection).item_class

Item class to coerce items into.

(TypedCollection).items

Gets collection items.

Methods

(TypedTuple).count(item)

Changes item to item.

Returns count in collection.

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

Gets pattern matching index.

Inventory of two patterns:

>>> inventory = patterntools.PatternInventory([
...     patterntools.Pattern(
...         indices=[1],
...         period=2,
...         ),
...     patterntools.Pattern(
...         indices=[-3, -2, -1],
...         ),
...     ])

Example 1a. Gets patterns that match the first ten indices:

>>> for i in range(10):
...     match = inventory.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.

Example 1b. Gets patterns that match next ten indices:

>>> for i in range(10, 20):
...     match = inventory.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.

Example 2a. Gets patterns that match the first ten indices, with rotation set to 1:

>>> for i in range(10):
...     match = inventory.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.

Example 2b. Gets patterns that match next ten indices with rotation set to 1:

>>> for i in range(10, 20):
...     match = inventory.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.

Example 3. With inverted patterns:

>>> inventory = patterntools.PatternInventory([
...     patterntools.Pattern(
...         indices=[-3],
...         inverted=True,
...         ),
...     ])
>>> for i in range(10):
...     match = inventory.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.

PatternInventory.get_matching_payload(index, total_length, rotation=None)

Gets payload attached to pattern matching index.

Example 1. Inventory of two patterns. Underlying notes with even divisions assigned to the last three indices:

>>> inventory = patterntools.PatternInventory([
...     patterntools.Pattern(
...         indices=[0],
...         payload=rhythmmakertools.NoteRhythmMaker(),
...         period=1,
...         ),
...     patterntools.Pattern(
...         indices=[-3, -2, -1],
...         payload=rhythmmakertools.EvenDivisionRhythmMaker(),
...         ),
...     ])

Over ten indices:

>>> for i in range(10):
...     match = inventory.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 = inventory.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)

Changes item to item.

Returns index in collection.

Special methods

(TypedTuple).__add__(expr)

Adds typed tuple to expr.

Returns new typed tuple.

(TypedTuple).__contains__(item)

Change item to item and return true if item exists in collection.

Returns none.

(TypedCollection).__eq__(expr)

Is true when expr 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__(i)

Gets i from type tuple.

Returns item.

(TypedTuple).__getslice__(start, stop)

Gets slice from start to stop in typed tuple.

Returns new typed tuple.

(TypedTuple).__hash__()

Hashes typed tuple.

Returns integer.

(TypedCollection).__iter__()

Iterates typed collection.

Returns generator.

(TypedCollection).__len__()

Length of typed collection.

Returns nonnegative integer.

(TypedTuple).__mul__(expr)

Multiplies typed tuple by expr.

Returns new typed tuple.

(TypedCollection).__ne__(expr)

Is true when expr is not a typed collection with items equal to this typed collection. Otherwise false.

Returns true or false.

(TypedTuple).__radd__(expr)

Right-adds expr to typed tuple.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(TypedTuple).__rmul__(expr)

Multiplies expr by typed tuple.

Returns new typed tuple.