searchtrees¶
Abstract Classes
Abstract search tree. |
- abstract class abjadext.nauert.searchtrees.SearchTree(definition=None)[source]¶
Abstract search tree.
SearchTrees
encapsulate strategies for generating collections ofQGrids
, given a set ofQEventProxy
instances as input.They allow composers to define the degree and quality of nested rhythmic subdivisions in the quantization output. That is to say, they allow composers to specify what sorts of tuplets and ratios of pulses may be contained within other tuplets, to arbitrary levels of nesting.
Attributes Summary
Calls search tree.
Is true when argument is a search tree with definition equal to that of this search tree.
Hashes search tree.
Gets interpreter representation.
Gets default search tree definition.
Gets search tree definition.
Special methods
- overridden __eq__(argument)[source]¶
Is true when argument is a search tree with definition equal to that of this search tree. Otherwise false.
- Return type:
- overridden __hash__()[source]¶
Hashes search tree.
Required to be explicitly redefined on Python 3 if __eq__ changes.
- Return type:
Read-only properties
- default_definition¶
Gets default search tree definition.
- definition¶
Gets search tree definition.
Classes
Unweighted search tree based on Paul Nauert's model. |
|
Weighted search tree. |
- class abjadext.nauert.searchtrees.UnweightedSearchTree(definition=None)[source]¶
Unweighted search tree based on Paul Nauert’s model.
>>> search_tree = nauert.UnweightedSearchTree() >>> search_tree UnweightedSearchTree(definition={2: {2: {2: {2: None}, 3: None}, 3: None, 5: None, 7: None}, 3: {2: {2: None}, 3: None, 5: None}, 5: {2: None, 3: None}, 7: {2: None}, 11: None, 13: None})
The search tree defines how nodes in a
QGrid
may be subdivided, if they happen to containQEvents
(or, in actuality,QEventProxy
instances which referenceQEvents
, but rescale their offsets between0
and1
).In the default definition, the root node of the
QGrid
may be subdivided into2
,3
,5
,7
,11
or13
equal parts. If divided into2
parts, the divisions of the root node may be divided again into2
,3
,5
or7
, and so forth.This definition is structured as a collection of nested dictionaries, whose keys are integers, and whose values are either the sentinel
None
indicating no further permissable divisions, or dictionaries obeying these same rules, which then indicate the possibilities for further division.Calling a
UnweightedSearchTree
with aQGrid
instance will generate all permissable subdividedQGrids
, according to the definition of the called search tree:>>> q_event_a = nauert.PitchedQEvent(130, [0, 1, 4]) >>> q_event_b = nauert.PitchedQEvent(150, [2, 3, 5]) >>> proxy_a = nauert.QEventProxy(q_event_a, 0.5) >>> proxy_b = nauert.QEventProxy(q_event_b, 0.667) >>> q_grid = nauert.QGrid() >>> q_grid.fit_q_events([proxy_a, proxy_b])
>>> q_grids = search_tree(q_grid) >>> for grid in q_grids: ... print(grid.rtm_format) ... (1 (1 1)) (1 (1 1 1)) (1 (1 1 1 1 1)) (1 (1 1 1 1 1 1 1)) (1 (1 1 1 1 1 1 1 1 1 1 1)) (1 (1 1 1 1 1 1 1 1 1 1 1 1 1))
A custom
UnweightedSearchTree
may be defined by passing in a dictionary, as described above. The following search tree only permits divisions of the root node into2s
and3s
, and if divided into2
, a node may be divided once more into2
parts:>>> definition = {2: {2: None}, 3: None} >>> search_tree = nauert.UnweightedSearchTree(definition)
>>> q_grids = search_tree(q_grid) >>> for grid in q_grids: ... print(grid.rtm_format) ... (1 (1 1)) (1 (1 1 1))
Attributes Summary
The default search tree definition, based on the search tree given by Paul Nauert:
Special methods
-
(
SearchTree
).__call__(q_grid)¶ Calls search tree.
-
(
SearchTree
).__eq__(argument)¶ Is true when argument is a search tree with definition equal to that of this search tree. Otherwise false.
- Return type:
-
(
SearchTree
).__hash__()¶ Hashes search tree.
Required to be explicitly redefined on Python 3 if __eq__ changes.
- Return type:
-
(
SearchTree
).__repr__()¶ Gets interpreter representation.
- Return type:
Read-only properties
- overridden default_definition¶
The default search tree definition, based on the search tree given by Paul Nauert:
>>> import pprint >>> search_tree = nauert.UnweightedSearchTree() >>> pprint.pprint(search_tree.default_definition) {2: {2: {2: {2: None}, 3: None}, 3: None, 5: None, 7: None}, 3: {2: {2: None}, 3: None, 5: None}, 5: {2: None, 3: None}, 7: {2: None}, 11: None, 13: None}
-
(
SearchTree
).definition¶ Gets search tree definition.
-
(
- class abjadext.nauert.searchtrees.WeightedSearchTree(definition=None)[source]¶
Weighted search tree.
Allows for dividing nodes in a q-grid into parts with unequal weights.
>>> search_tree = nauert.WeightedSearchTree() >>> search_tree WeightedSearchTree(definition={'divisors': (2, 3, 5, 7), 'max_depth': 3, 'max_divisions': 2})
In
WeightedSearchTree
’s definition:divisors
controls the sum of the parts of the ratio a nodemay be divided into,
max_depth
controls how many levels of tuplet nestingare permitted, and
max_divisions
controls the maximum permitted length of theweights in the ratio.
Thus, the default
WeightedSearchTree
permits the following ratios:>>> for composition in search_tree.all_compositions: ... composition ... (1, 1) (2, 1) (1, 2) (4, 1) (3, 2) (2, 3) (1, 4) (6, 1) (5, 2) (4, 3) (3, 4) (2, 5) (1, 6)
Attributes Summary
All compositions of weighted search tree.
Gets default definition of weighted search tree.
Special methods
-
(
SearchTree
).__call__(q_grid)¶ Calls search tree.
-
(
SearchTree
).__eq__(argument)¶ Is true when argument is a search tree with definition equal to that of this search tree. Otherwise false.
- Return type:
-
(
SearchTree
).__hash__()¶ Hashes search tree.
Required to be explicitly redefined on Python 3 if __eq__ changes.
- Return type:
-
(
SearchTree
).__repr__()¶ Gets interpreter representation.
- Return type:
Read-only properties
- all_compositions¶
All compositions of weighted search tree.
- overridden default_definition¶
Gets default definition of weighted search tree.
-
(
SearchTree
).definition¶ Gets search tree definition.