pattern

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.pattern" { graph [label="abjad.pattern"]; node [color=1]; "abjad.pattern.Pattern" [URL="../api/abjad/pattern.html#abjad.pattern.Pattern", color=black, fontcolor=white, label=Pattern, target=_top]; "abjad.pattern.PatternTuple" [URL="../api/abjad/pattern.html#abjad.pattern.PatternTuple", color=black, fontcolor=white, label="Pattern\nTuple", target=_top]; } subgraph cluster_builtins { graph [label=builtins]; node [color=2]; "builtins.object" [URL="https://docs.python.org/3.10/library/functions.html#object", label=object, target=_top]; } "builtins.object" -> "abjad.pattern.Pattern" [minlen=1]; "builtins.object" -> "abjad.pattern.PatternTuple" [minlen=2]; }


Classes

Pattern

Pattern.

PatternTuple

Pattern tuple.

class abjad.pattern.Pattern(indices=None, inverted=None, operator=None, patterns=None, payload=None, period=None)[source]

Pattern.

Matches three indices out of every eight:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 
3 
4 
5 
6 
7 True
8 True
9 True
10 
11 
12 
13 
14 
15 True

Matches three indices out of every sixteen:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=16,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 
3 
4 
5 
6 
7 True
8 
9 
10 
11 
12 
13 
14 
15 

Works with improper indices:

>>> pattern = abjad.Pattern(
...     indices=[16, 17, 23],
...     period=16,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 
3 
4 
5 
6 
7 True
8 
9 
10 
11 
12 
13 
14 
15 

Sieve from opening of Xenakis’s Psappha:

>>> sieve_1a = abjad.index([0, 1, 7], 8)
>>> sieve_1b = abjad.index([1, 3], 5)
>>> sieve_1 = sieve_1a & sieve_1b
>>> sieve_2a = abjad.index([0, 1, 2], 8)
>>> sieve_2b = abjad.index([0], 5)
>>> sieve_2 = sieve_2a & sieve_2b
>>> sieve_3 = abjad.index([3], 8)
>>> sieve_4 = abjad.index([4], 8)
>>> sieve_5a = abjad.index([5, 6], 8)
>>> sieve_5b = abjad.index([2, 3, 4], 5)
>>> sieve_5 = sieve_5a & sieve_5b
>>> sieve_6a = abjad.index([1], 8)
>>> sieve_6b = abjad.index([2], 5)
>>> sieve_6 = sieve_6a & sieve_6b
>>> sieve_7a = abjad.index([6], 8)
>>> sieve_7b = abjad.index([1], 5)
>>> sieve_7 = sieve_7a & sieve_7b
>>> sieve = sieve_1 | sieve_2 | sieve_3 | sieve_4 | sieve_5 | sieve_6 | sieve_7
>>> sieve.get_boolean_vector(total_length=40)
[1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0]

Inverted works like this:

Matches three indices out of every eight:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> pattern.inverted is None
True
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 
3 
4 
5 
6 
7 True
8 True
9 True
10 
11 
12 
13 
14 
15 True

Pattern that rejects three indices from every eight; equivalently, pattern matches 8-3=5 indices out of every eight:

>>> pattern = abjad.Pattern(indices=[0, 1, 7], period=8, inverted=True)
>>> pattern.inverted
True
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 
1 
2 True
3 True
4 True
5 True
6 True
7 
8 
9 
10 True
11 True
12 True
13 True
14 True
15 

Matches every index that is (one of the first three indices) OR (one of the last three indices):

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern = pattern_1 | pattern_2
>>> pattern.inverted is None
True
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]

Matches every index that is NOT (one of the first three indices) OR (one of the last three indices):

>>> import dataclasses
>>> pattern = dataclasses.replace(pattern, inverted=True)
>>> pattern.inverted
True
>>> pattern.get_boolean_vector(total_length=16)
[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]

Payload works like this: Pattern with string payload assigned to three of every eight indices:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     payload="Allegro non troppo",
...     period=8,
... )
>>> total_length = 10
>>> for index in range(10):
...     match = pattern.matches_index(index, total_length)
...     if match:
...         payload = pattern.payload
...     else:
...         payload = ""
...     print(index, repr(payload))
... 
0 'Allegro non troppo'
1 'Allegro non troppo'
2 ''
3 ''
4 ''
5 ''
6 ''
7 'Allegro non troppo'
8 'Allegro non troppo'
9 'Allegro non troppo'

Period works like this:

Pattern with a period of eight:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> pattern.period
8
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 
3 
4 
5 
6 
7 True
8 True
9 True
10 
11 
12 
13 
14 
15 True

Same pattern with a period of sixteen:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=16,
... )
>>> pattern.period
16
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 
3 
4 
5 
6 
7 True
8 
9 
10 
11 
12 
13 
14 
15 

Gets period of pattern that indexs every fourth and fifth element:

>>> pattern_1 = abjad.Pattern([0], period=4)
>>> pattern_2 = abjad.Pattern([0], period=5)
>>> pattern = pattern_1 | pattern_2
>>> pattern
Pattern(indices=None, inverted=None, operator='or', patterns=(Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=4), Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=5)), payload=None, period=20)
>>> pattern.period
20

Returns none when pattern contains acyclic parts:

>>> pattern_1 = abjad.Pattern([0], period=4)
>>> pattern_2 = abjad.Pattern([0])
>>> pattern = pattern_1 | pattern_2
>>> pattern
Pattern(indices=None, inverted=None, operator='or', patterns=(Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=4), Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)
>>> pattern.period is None
True

Attributes Summary

__and__

Logical AND of two patterns.

__eq__

Return self==value.

__invert__

Inverts pattern.

__len__

Gets length of pattern.

__or__

Logical OR of two patterns.

__post_init__

__repr__

Return repr(self).

__xor__

Logical XOR of two patterns.

advance

Advances pattern.

from_vector

Makes pattern from boolean vector.

get_boolean_vector

Gets boolean vector of pattern applied to input sequence with total_length.

get_matching_items

Gets maching items from sequence.

index

Makes pattern that matches indices.

index_all

Makes pattern that matches all indices.

index_first

Makes pattern that matches the first n indices.

index_last

Makes pattern that matches the last n indices.

matches_index

Is true when pattern matches index taken under total_length.

reverse

Reverses pattern.

rotate

Rotates pattern by index n.

weight

Gets weight of pattern.


Special methods

__and__(pattern)[source]

Logical AND of two patterns.

Flat grouping of two patterns:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_1 & pattern_2
Pattern(indices=None, inverted=None, operator='and', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)

Flat grouping of three patterns:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index([0], 2)
>>> pattern = pattern_1 & pattern_2 & pattern_3
>>> pattern
Pattern(indices=None, inverted=None, operator='and', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=2)), payload=None, period=None)
>>> pattern.get_boolean_vector(total_length=16)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Nested grouping of three patterns:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index([0], 2)
>>> pattern = pattern_1 & pattern_2 | pattern_3
>>> pattern
Pattern(indices=None, inverted=None, operator='or', patterns=(Pattern(indices=None, inverted=None, operator='and', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None), Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=2)), payload=None, period=None)
>>> pattern.get_boolean_vector(total_length=16)
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]

In-place AND is allowed:

>>> pattern = abjad.index_first(3)
>>> pattern &= abjad.index_last(3)
>>> pattern
Pattern(indices=None, inverted=None, operator='and', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)

Returns new pattern.

overridden __eq__(other)

Return self==value.

__invert__()[source]

Inverts pattern.

>>> pattern = abjad.index_first(3)
>>> pattern
Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None)
>>> pattern = ~pattern
>>> pattern
Pattern(indices=(0, 1, 2), inverted=True, operator=None, patterns=None, payload=None, period=None)
>>> pattern = ~pattern
>>> pattern
Pattern(indices=(0, 1, 2), inverted=False, operator=None, patterns=None, payload=None, period=None)

Negation defined equal to inversion.

Matches every index that is (one of the first three indices) or (one of the last three indices):

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern = pattern_1 | pattern_2
>>> pattern
Pattern(indices=None, inverted=None, operator='or', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]

Matches every index that is NOT (one of the first three indices) or (one of the last three indices):

>>> pattern = ~pattern
>>> pattern
Pattern(indices=None, inverted=True, operator='or', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)
>>> pattern.get_boolean_vector(total_length=16)
[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]

Returns new pattern.

__len__()[source]

Gets length of pattern.

Gets length of cyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> len(pattern)
8

Length of cyclic pattern defined equal to period of the pattern.

Gets length of acyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[0, 2, 3],
... )
>>> len(pattern)
4

Length of acyclic pattern defined equal to greatest index in pattern, plus 1.

Gets length of pattern with negative indices:

>>> pattern = abjad.Pattern(
...     indices=[-3],
... )
>>> len(pattern)
3

Length of pattern with negative indices defined equal to absolute value of least index.

Returns nonnegative integer.

overridden __or__(pattern)[source]

Logical OR of two patterns.

Flat grouping of two patterns:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern = pattern_1 | pattern_2
>>> pattern
Pattern(indices=None, inverted=None, operator='or', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)

Flat grouping:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index([0], 2)
>>> pattern = pattern_1 | pattern_2 | pattern_3
>>> pattern
Pattern(indices=None, inverted=None, operator='or', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=2)), payload=None, period=None)
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1]

Nested grouping:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index([0], 2)
>>> pattern = pattern_1 | pattern_2 & pattern_3
>>> pattern
Pattern(indices=None, inverted=None, operator='or', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=None, inverted=None, operator='and', patterns=(Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=2)), payload=None, period=None)), payload=None, period=None)
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]

In-place OR is allowed:

>>> pattern = abjad.index_first(3)
>>> pattern |= abjad.index_last(3)
>>> pattern
Pattern(indices=None, inverted=None, operator='or', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)

Returns new pattern.

__post_init__()[source]
overridden __repr__()

Return repr(self).

__xor__(pattern)[source]

Logical XOR of two patterns.

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern = pattern_1 ^ pattern_2
>>> pattern
Pattern(indices=None, inverted=None, operator='xor', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)

Flat grouping:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index([0], 2)
>>> pattern = pattern_1 ^ pattern_2 ^ pattern_3
>>> pattern
Pattern(indices=None, inverted=None, operator='xor', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=2)), payload=None, period=None)
>>> pattern.get_boolean_vector(total_length=16)
[0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1]

Nested grouping:

>>> pattern_1 = abjad.index_first(3)
>>> pattern_2 = abjad.index_last(3)
>>> pattern_3 = abjad.index([0], 2)
>>> pattern = pattern_1 ^ pattern_2 & pattern_3
>>> pattern
Pattern(indices=None, inverted=None, operator='xor', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=None, inverted=None, operator='and', patterns=(Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=2)), payload=None, period=None)), payload=None, period=None)
>>> pattern.get_boolean_vector(total_length=16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]

In-place XOR is allowed:

>>> pattern = abjad.index_first(3)
>>> pattern ^= abjad.index_last(3)
>>> pattern
Pattern(indices=None, inverted=None, operator='xor', patterns=(Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)

Returns new pattern.


Methods

advance(count=None)[source]

Advances pattern.

>>> pattern = abjad.Pattern([0, 2, 12])
>>> pattern = pattern.advance(8)
>>> pattern
Pattern(indices=(4,), inverted=None, operator=None, patterns=None, payload=None, period=None)
>>> pattern = pattern.advance(8)
>>> pattern
Pattern(indices=(), inverted=None, operator=None, patterns=None, payload=None, period=None)

Returns copy of pattern when count is none:

>>> pattern = abjad.Pattern([0, 2, 12])
>>> pattern.advance()
Pattern(indices=(0, 2, 12), inverted=None, operator=None, patterns=None, payload=None, period=None)

Raises exception on attempt to advance negative pattern:

>>> pattern = abjad.Pattern([-2, -1])
>>> pattern.advance(8)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/trevor/abjad/abjad/pattern.py", line 780, in advance
    raise Exception(message)
Exception: can not advance pattern with negative indices (Pattern(indices=(-2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)).
Return type:

Pattern

get_boolean_vector(total_length=None)[source]

Gets boolean vector of pattern applied to input sequence with total_length.

Gets boolean vector of acyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[4, 5, 6, 7],
... )
>>> pattern.get_boolean_vector(4)
[0, 0, 0, 0]
>>> pattern.get_boolean_vector(8)
[0, 0, 0, 0, 1, 1, 1, 1]
>>> pattern.get_boolean_vector(16)
[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]

Sets total length to length of pattern when total_length is none:

>>> pattern.get_boolean_vector()
[0, 0, 0, 0, 1, 1, 1, 1]

Gets vector of cyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[4, 5, 6, 7],
...     period=20,
... )
>>> pattern.get_boolean_vector(4)
[0, 0, 0, 0]
>>> pattern.get_boolean_vector(8)
[0, 0, 0, 0, 1, 1, 1, 1]
>>> pattern.get_boolean_vector(16)
[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]

Sets total length to length of pattern when total_length is none:

>>> pattern.get_boolean_vector()
[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Gets vector of inverted pattern:

>>> pattern = abjad.Pattern(
...     indices=[4, 5, 6, 7],
...     period=20,
... )
>>> pattern.get_boolean_vector(4)
[0, 0, 0, 0]
>>> pattern.get_boolean_vector(8)
[0, 0, 0, 0, 1, 1, 1, 1]
>>> pattern.get_boolean_vector(16)
[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]

Sets total length to length of pattern when total_length is none:

>>> pattern.get_boolean_vector()
[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Two-part pattern with logical OR:

>>> pattern = abjad.Pattern(
...     operator="or",
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...         ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...         ),
...     ],
... )
>>> pattern.get_boolean_vector(4)
[1, 1, 1, 1]
>>> pattern.get_boolean_vector(8)
[1, 1, 1, 0, 0, 1, 1, 1]
>>> pattern.get_boolean_vector(16)
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]

Matches every index that is (one of the first three indices) OR (one of the last three indices).

Two-part pattern with mixed periodic and inverted parts:

>>> pattern = abjad.Pattern(
...     operator="and",
...     patterns=[
...         abjad.Pattern(
...             indices=[0],
...             period=2,
...         ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...         ),
...     ],
... )
>>> pattern.get_boolean_vector(4)
[1, 0, 0, 0]
>>> pattern.get_boolean_vector(8)
[1, 0, 1, 0, 1, 0, 0, 0]
>>> pattern.get_boolean_vector(16)
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0]

Matches every index that is (equal to 0 % 2) AND (not one of the last three indices).

Cyclic pattern that indexes every fourth and fifth item:

>>> pattern_1 = abjad.Pattern([0], period=4)
>>> pattern_2 = abjad.Pattern([0], period=5)
>>> pattern = pattern_1 | pattern_2
>>> pattern
Pattern(indices=None, inverted=None, operator='or', patterns=(Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=4), Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=5)), payload=None, period=20)
>>> pattern.get_boolean_vector(4)
[1, 0, 0, 0]
>>> pattern.get_boolean_vector(8)
[1, 0, 0, 0, 1, 1, 0, 0]
>>> pattern.get_boolean_vector(16)
[1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1]

Sets total length to period of pattern when total_length is none:

>>> pattern.period
20
>>> pattern.get_boolean_vector()
[1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0]
>>> pattern.period == len(pattern.get_boolean_vector())
True

Returns list of ones and zeroes.

get_matching_items(sequence)[source]

Gets maching items from sequence.

>>> pattern = abjad.Pattern(
...     indices=[4, 5, 6, 7],
... )
>>> pattern.get_matching_items("abcdefghijklmnopqrstuvwxyz")
['e', 'f', 'g', 'h']
>>> pattern = abjad.Pattern(
...     indices=[8, 9],
...     period=10,
... )
>>> pattern.get_matching_items("abcdefghijklmnopqrstuvwxyz")
['i', 'j', 's', 't']
>>> pattern = abjad.index_first(1) | abjad.index_last(2)
>>> pattern.get_matching_items("abcdefghijklmnopqrstuvwxyz")
['a', 'y', 'z']

Returns list.

matches_index(index, total_length, rotation=None)[source]

Is true when pattern matches index taken under total_length.

Matches three indices out of every eight:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 
3 
4 
5 
6 
7 True
8 True
9 True
10 
11 
12 
13 
14 
15 True

Matches three indices out of every eight, offset 1 to the left:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(
...         index,
...         total_length,
...         rotation=1,
...     )
...     match = match or ""
...     print(index, match)
... 
0 True
1 
2 
3 
4 
5 
6 True
7 True
8 True
9 
10 
11 
12 
13 
14 True
15 True

Matches three indices out of every eight, offset 2 to the left:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(
...         index,
...         total_length,
...         rotation=2,
...     )
...     match = match or ""
...     print(index, match)
... 
0 
1 
2 
3 
4 
5 True
6 True
7 True
8 
9 
10 
11 
12 
13 True
14 True
15 True

Matches three indices out of every sixteen:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=16,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 
3 
4 
5 
6 
7 True
8 
9 
10 
11 
12 
13 
14 
15 

Matches three indices out of every sixteen, offset 1 to the left:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=16,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(
...         index,
...         total_length,
...         rotation=1,
...     )
...     match = match or ""
...     print(index, match)
... 
0 True
1 
2 
3 
4 
5 
6 True
7 
8 
9 
10 
11 
12 
13 
14 
15 True

Matches three indices out of every sixteen, offset 2 to the left:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=16,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(
...         index,
...         total_length,
...         rotation=2,
...     )
...     match = match or ""
...     print(index, match)
... 
0 
1 
2 
3 
4 
5 True
6 
7 
8 
9 
10 
11 
12 
13 
14 True
15 True

Empty pattern:

>>> pattern = abjad.Pattern()

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 
1 
2 
3 
4 
5 
6 
7 

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 
1 
2 
3 

Matches nothing.

Simple pattern:

Logical OR:

>>> pattern = abjad.Pattern(
...     operator="or",
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...         ),
...     ],
... )
>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 True
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 

Logical AND:

>>> pattern = abjad.Pattern(
...     operator="and",
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...         ),
...     ],
... )
>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 True
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 

Logical XOR:

>>> pattern = abjad.Pattern(
...     operator="xor",
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...         ),
...     ],
... )
>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 True
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 

Matches every index that is (one of the first three indices).

Ignores operator.

Two-part pattern with logical OR:

>>> pattern = abjad.Pattern(
...     operator="or",
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...         ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...         ),
...     ],
... )

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 True
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 True
14 True
15 True

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 True
3 
4 
5 True
6 True
7 True

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 True
3 True

Matches every index that is (one of the first three indices) OR (one of the last three indices).

Two-part pattern with logical AND:

>>> pattern = abjad.Pattern(
...     operator="and",
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...         ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...         ),
...     ],
... )

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 
1 
2 
3 
4 
5 
6 
7 

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 
1 True
2 True
3 

Matches every index that is (one of the first three indices) AND (one of the last three indices).

Two-part pattern with logical XOR:

>>> pattern = abjad.Pattern(
...     operator="xor",
...     patterns=[
...         abjad.Pattern(
...             indices=[0, 1, 2],
...         ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...         ),
...     ],
... )

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 True
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 True
14 True
15 True

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 True
3 
4 
5 True
6 True
7 True

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 
2 
3 True

Matches every index that is (one of the first three indices) XOR (one of the last three indices).

Two-part pattern with mixed periodic and inverted parts:

>>> pattern = abjad.Pattern(
...     operator="and",
...     patterns=[
...         abjad.Pattern(
...             indices=[0],
...             period=2,
...         ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...         ),
...     ],
... )

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 
2 True
3 
4 True
5 
6 True
7 
8 True
9 
10 True
11 
12 True
13 
14 
15 

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 
2 True
3 
4 True
5 
6 
7 

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 
2 
3 

Matches every index that is (equal to 0 % 2) AND (not one of the last three indices).

Complex pattern with compound and simple parts:

>>> pattern = abjad.Pattern(
...     operator="and",
...     patterns=[
...         abjad.Pattern(
...             indices=[0],
...             period=2,
...         ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...         ),
...     ],
... )
>>> pattern = abjad.Pattern(
...     operator="or",
...     patterns=[
...         pattern,
...         abjad.Pattern(
...             indices=[0, 1, 2],
...         ),
...     ],
... )
>>> pattern
Pattern(indices=None, inverted=None, operator='or', patterns=(Pattern(indices=None, inverted=None, operator='and', patterns=(Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=2), Pattern(indices=(-3, -2, -1), inverted=True, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None), Pattern(indices=(0, 1, 2), inverted=None, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)

Total length 16:

>>> total_length = 16
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 True
3 
4 True
5 
6 True
7 
8 True
9 
10 True
11 
12 True
13 
14 
15 

Total length 8:

>>> total_length = 8
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 True
3 
4 True
5 
6 
7 

Total length 4:

>>> total_length = 4
>>> for index in range(total_length):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 True
3 

Matches every index that is ((equal to 0 % 2) AND (not one of the last three indices)) OR is (one of the first three indices).

Returns true or false.

reverse()[source]

Reverses pattern.

Matches three indices out of every eight:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 
3 
4 
5 
6 
7 True
8 True
9 True
10 
11 
12 
13 
14 
15 True

Reverses pattern:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> pattern = pattern.reverse()
>>> pattern
Pattern(indices=(-1, -2, -8), inverted=None, operator=None, patterns=None, payload=None, period=8)
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 
2 
3 
4 
5 
6 True
7 True
8 True
9 
10 
11 
12 
13 
14 True
15 True

Matches every index that is (equal to 0 % 2) AND (not one of the last three indices):

>>> pattern = abjad.Pattern(
...     operator="and",
...     patterns=[
...         abjad.Pattern(
...             indices=[0],
...             period=2,
...         ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...         ),
...     ],
... )
>>> pattern
Pattern(indices=None, inverted=None, operator='and', patterns=(Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=2), Pattern(indices=(-3, -2, -1), inverted=True, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)

Reverses pattern:

>>> pattern = pattern.reverse()
>>> pattern
Pattern(indices=None, inverted=None, operator='and', patterns=(Pattern(indices=(-1,), inverted=None, operator=None, patterns=None, payload=None, period=2), Pattern(indices=(2, 1, 0), inverted=True, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)

New pattern matches every index that is (equal to -1 % 2) AND (not one of the first three indices).

Returns new pattern.

rotate(n=0)[source]

Rotates pattern by index n.

Matches three indices out of every eight:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 
3 
4 
5 
6 
7 True
8 True
9 True
10 
11 
12 
13 
14 
15 True

Rotates pattern two elements to the right:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> pattern = pattern.rotate(n=2)
>>> pattern
Pattern(indices=(2, 3, 9), inverted=None, operator=None, patterns=None, payload=None, period=8)
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 
1 True
2 True
3 True
4 
5 
6 
7 
8 
9 True
10 True
11 True
12 
13 
14 
15 

Matches three indices out of every eight with negative indices:

>>> pattern = abjad.Pattern(
...     indices=[-3, -2, -1],
...     period=8,
... )
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 
1 
2 
3 
4 
5 True
6 True
7 True
8 
9 
10 
11 
12 
13 True
14 True
15 True

Rotates pattern two elements to the right:

>>> pattern = abjad.Pattern(
...     indices=[-3, -2, -1],
...     period=8,
... )
>>> pattern = pattern.rotate(n=2)
>>> pattern
Pattern(indices=(-1, 0, 1), inverted=None, operator=None, patterns=None, payload=None, period=8)
>>> total_length = 16
>>> for index in range(16):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 True
2 
3 
4 
5 
6 
7 True
8 True
9 True
10 
11 
12 
13 
14 
15 True

Matches every index that is (equal to 0 % 2) AND (not one of the last three indices):

>>> pattern = abjad.Pattern(
...     operator="and",
...     patterns=[
...         abjad.Pattern(
...             indices=[0],
...             period=2,
...         ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...             inverted=True,
...         ),
...     ],
... )
>>> pattern
Pattern(indices=None, inverted=None, operator='and', patterns=(Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=2), Pattern(indices=(-3, -2, -1), inverted=True, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)

Rotates pattern two elements to the right:

>>> pattern = pattern.rotate(n=2)
>>> pattern
Pattern(indices=None, inverted=None, operator='and', patterns=(Pattern(indices=(2,), inverted=None, operator=None, patterns=None, payload=None, period=2), Pattern(indices=(-1, 0, 1), inverted=True, operator=None, patterns=None, payload=None, period=None)), payload=None, period=None)

New pattern matches every index that is (equal to 2 % 2) AND (not the first, second or last index in the pattern).

Returns new pattern.


Class & static methods

classmethod from_vector(vector)[source]

Makes pattern from boolean vector.

Matches three indices out of every five:

>>> pattern = [1, 0, 0, 1, 1]
>>> pattern = abjad.Pattern.from_vector(pattern)
>>> pattern
Pattern(indices=(0, 3, 4), inverted=None, operator=None, patterns=None, payload=None, period=5)
>>> total_length = 10
>>> for index in range(10):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 
2 
3 True
4 True
5 True
6 
7 
8 True
9 True

Matches three indices out of every six:

>>> pattern = [1, 0, 0, 1, 1, 0]
>>> pattern = abjad.Pattern.from_vector(pattern)
>>> pattern
Pattern(indices=(0, 3, 4), inverted=None, operator=None, patterns=None, payload=None, period=6)
>>> total_length = 12
>>> for index in range(12):
...     match = pattern.matches_index(index, total_length)
...     match = match or ""
...     print(index, match)
... 
0 True
1 
2 
3 True
4 True
5 
6 True
7 
8 
9 True
10 True
11 

Returns pattern.

static index(indices, period=None, inverted=None)[source]

Makes pattern that matches indices.

Indexes item 2:

>>> pattern = abjad.index([2])
>>> pattern
Pattern(indices=(2,), inverted=None, operator=None, patterns=None, payload=None, period=None)

Indexes items 2, 3 and 5:

>>> pattern = abjad.index([2, 3, 5])
>>> pattern
Pattern(indices=(2, 3, 5), inverted=None, operator=None, patterns=None, payload=None, period=None)

Returns pattern.

static index_all(inverted=None)[source]

Makes pattern that matches all indices.

Indexes all divisions for tie creation:

>>> pattern = abjad.index_all()
>>> pattern
Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=1)

Returns pattern.

static index_first(n, inverted=None)[source]

Makes pattern that matches the first n indices.

Indexes first item:

>>> pattern = abjad.index_first(1)
>>> pattern
Pattern(indices=(0,), inverted=None, operator=None, patterns=None, payload=None, period=None)

Indexes first two items:

>>> pattern = abjad.index_first(2)
>>> pattern
Pattern(indices=(0, 1), inverted=None, operator=None, patterns=None, payload=None, period=None)

Indexes nothing:

>>> pattern = abjad.index_first(0)
>>> pattern
Pattern(indices=None, inverted=None, operator=None, patterns=None, payload=None, period=None)

Returns pattern.

static index_last(n, inverted=None)[source]

Makes pattern that matches the last n indices.

Indexes last two items:

>>> pattern = abjad.index_last(2)
>>> pattern
Pattern(indices=(-2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)

Indexes nothing:

>>> pattern = abjad.index_last(0)
>>> pattern
Pattern(indices=None, inverted=None, operator=None, patterns=None, payload=None, period=None)

Returns pattern.


Read-only properties

weight

Gets weight of pattern.

Gets weight of cyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[0, 1, 7],
...     period=8,
... )
>>> pattern.weight
3

Gets weight of acyclic pattern:

>>> pattern = abjad.Pattern(
...     indices=[0, 2, 3],
... )
>>> pattern.weight
3

Weight defined equal to number of indices in pattern.

Returns nonnegative integer.

class abjad.pattern.PatternTuple(items=())[source]

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,
...         ),
...     ]
... )
>>> patterns
PatternTuple(items=(Pattern(indices=(0, 1, 7), inverted=None, operator=None, patterns=None, payload=None, period=10), Pattern(indices=(-2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None), Pattern(indices=(2,), inverted=None, operator=None, patterns=None, payload=None, period=3)))

Two patterns:

>>> patterns = abjad.PatternTuple(
...     [
...         abjad.Pattern(
...             indices=[1],
...             period=2,
...         ),
...         abjad.Pattern(
...             indices=[-3, -2, -1],
...         ),
...     ]
... )
>>> patterns
PatternTuple(items=(Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2), Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)))

Attributes Summary

__eq__

Return self==value.

__hash__

Return hash(self).

__post_init__

__repr__

Return repr(self).

get_matching_pattern

Gets pattern matching index.

get_matching_payload

Gets payload attached to pattern matching index.


Special methods

overridden __eq__(other)

Return self==value.

overridden __hash__()

Return hash(self).

__post_init__()[source]
overridden __repr__()

Return repr(self).


Methods

get_matching_pattern(index, total_length, rotation=None)[source]

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,), inverted=None, operator=None, patterns=None, payload=None, period=2)
2 None
3 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2)
4 None
5 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2)
6 None
7 Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)
8 Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)
9 Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)

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,), inverted=None, operator=None, patterns=None, payload=None, period=2)
12 None
13 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2)
14 None
15 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2)
16 None
17 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2)
18 None
19 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, 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,), inverted=None, operator=None, patterns=None, payload=None, period=2)
1 None
2 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2)
3 None
4 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2)
5 None
6 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2)
7 Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)
8 Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)
9 Pattern(indices=(-3, -2, -1), inverted=None, operator=None, patterns=None, payload=None, period=None)

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,), inverted=None, operator=None, patterns=None, payload=None, period=2)
11 None
12 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2)
13 None
14 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2)
15 None
16 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, period=2)
17 None
18 Pattern(indices=(1,), inverted=None, operator=None, patterns=None, payload=None, 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, operator=None, patterns=None, payload=None, period=None)
1 Pattern(indices=(-3,), inverted=True, operator=None, patterns=None, payload=None, period=None)
2 Pattern(indices=(-3,), inverted=True, operator=None, patterns=None, payload=None, period=None)
3 Pattern(indices=(-3,), inverted=True, operator=None, patterns=None, payload=None, period=None)
4 Pattern(indices=(-3,), inverted=True, operator=None, patterns=None, payload=None, period=None)
5 Pattern(indices=(-3,), inverted=True, operator=None, patterns=None, payload=None, period=None)
6 Pattern(indices=(-3,), inverted=True, operator=None, patterns=None, payload=None, period=None)
7 None
8 Pattern(indices=(-3,), inverted=True, operator=None, patterns=None, payload=None, period=None)
9 Pattern(indices=(-3,), inverted=True, operator=None, patterns=None, payload=None, period=None)

Returns pattern or none.

get_matching_payload(index, total_length, rotation=None)[source]

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