UnweightedSearchTree

class quantizationtools.UnweightedSearchTree(definition=None)

Concrete SearchTree subclass, based on Paul Nauert’s search tree model:

>>> search_tree = quantizationtools.UnweightedSearchTree()
>>> print(format(search_tree))
quantizationtools.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 contain QEvents (or, in actuality, QEventProxy instances which reference QEvents, but rescale their offsets between 0 and 1).

In the default definition, the root node of the QGrid may be subdivided into 2, 3, 5, 7, 11 or 13 equal parts. If divided into 2 parts, the divisions of the root node may be divided again into 2, 3, 5 or 7, 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 a QGrid instance will generate all permissable subdivided QGrids, according to the definition of the called search tree:

>>> q_event_a = quantizationtools.PitchedQEvent(130, [0, 1, 4])
>>> q_event_b = quantizationtools.PitchedQEvent(150, [2, 3, 5])
>>> proxy_a = quantizationtools.QEventProxy(q_event_a, 0.5)
>>> proxy_b = quantizationtools.QEventProxy(q_event_b, 0.667)
>>> q_grid = quantizationtools.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 into 2s and 3s, and if divided into 2, a node may be divided once more into 2 parts:

>>> definition = {2: {2: None}, 3: None}
>>> search_tree = quantizationtools.UnweightedSearchTree(definition)
>>> q_grids = search_tree(q_grid)
>>> for grid in q_grids:
...     print(grid.rtm_format)
(1 (1 1))
(1 (1 1 1))

Return UnweightedSearchTree instance.

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_quantizationtools { graph [label=quantizationtools]; "abjad.tools.quantizationtools.SearchTree.SearchTree" [color=3, group=2, label=SearchTree, shape=oval, style=bold]; "abjad.tools.quantizationtools.UnweightedSearchTree.UnweightedSearchTree" [color=black, fontcolor=white, group=2, label=<<B>UnweightedSearchTree</B>>, shape=box, style="filled, rounded"]; "abjad.tools.quantizationtools.SearchTree.SearchTree" -> "abjad.tools.quantizationtools.UnweightedSearchTree.UnweightedSearchTree"; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.quantizationtools.SearchTree.SearchTree"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

default_definition The default search tree definition, based on the search tree given
definition The search tree definition.
__call__(q_grid) Calls search tree.
__eq__(expr) Is true when expr is a search tree with definition equal to that of this search tree.
__format__([format_specification]) Formats Abjad object.
__hash__() Hashes search tree.
__ne__(expr) Is true when Abjad object does not equal expr.
__repr__() Gets interpreter representation of Abjad object.

Read-only properties

UnweightedSearchTree.default_definition

The default search tree definition, based on the search tree given by Paul Nauert:

>>> import pprint
>>> search_tree = quantizationtools.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}

Returns dictionary.

(SearchTree).definition

The search tree definition.

Returns dictionary.

Special methods

(SearchTree).__call__(q_grid)

Calls search tree.

(SearchTree).__eq__(expr)

Is true when expr is a search tree with definition equal to that of this search tree. 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.

(SearchTree).__hash__()

Hashes search tree.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(AbjadObject).__ne__(expr)

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

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.