BeatwiseQSchema

class quantizationtools.BeatwiseQSchema(*arguments, **keywords)

Beatwise q-schema.

Treats beats as timestep unit.

>>> import abjad
>>> from abjad.tools import quantizationtools
>>> q_schema = quantizationtools.BeatwiseQSchema()

Without arguments, it uses smart defaults:

>>> f(q_schema)
quantizationtools.BeatwiseQSchema(
    beatspan=abjad.Duration(1, 4),
    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,
            },
        ),
    tempo=abjad.MetronomeMark(
        reference_duration=abjad.Duration(1, 4),
        units_per_minute=60,
        ),
    )

Each time-step in a BeatwiseQSchema is composed of three settings:

  • beatspan
  • search_tree
  • tempo

These settings can be applied as global defaults for the schema via keyword arguments, which persist until overridden:

>>> beatspan = abjad.Duration(5, 16)
>>> search_tree = quantizationtools.UnweightedSearchTree({7: None})
>>> tempo = abjad.MetronomeMark((1, 4), 54)
>>> q_schema = quantizationtools.BeatwiseQSchema(
...     beatspan=beatspan,
...     search_tree=search_tree,
...     tempo=tempo,
...     )

The computed value at any non-negative time-step can be found by subscripting:

>>> index = 0
>>> for key, value in sorted(q_schema[index].items()):
...     print('{}:'.format(key), value)
...
beatspan: 5/16
search_tree: UnweightedSearchTree(definition={7: None})
tempo: 4=54
>>> index = 1000
>>> for key, value in sorted(q_schema[index].items()):
...     print('{}:'.format(key), value)
...
beatspan: 5/16
search_tree: UnweightedSearchTree(definition={7: None})
tempo: 4=54

Per-time-step settings can be applied in a variety of ways.

Instantiating the schema via *arguments with a series of either BeatwiseQSchemaItem instances, or dictionaries which could be used to instantiate BeatwiseQSchemaItem instances, will apply those settings sequentially, starting from time-step 0:

>>> a = {'beatspan': abjad.Duration(5, 32)}
>>> b = {'beatspan': abjad.Duration(3, 16)}
>>> c = {'beatspan': abjad.Duration(1, 8)}
>>> q_schema = quantizationtools.BeatwiseQSchema(a, b, c)
>>> q_schema[0]['beatspan']
Duration(5, 32)
>>> q_schema[1]['beatspan']
Duration(3, 16)
>>> q_schema[2]['beatspan']
Duration(1, 8)
>>> q_schema[3]['beatspan']
Duration(1, 8)

Similarly, instantiating the schema from a single dictionary, consisting of integer:specification pairs, or a sequence via *arguments of (integer, specification) pairs, allows for applying settings to non-sequential time-steps:

>>> a = {'search_tree': quantizationtools.UnweightedSearchTree({2: None})}
>>> b = {'search_tree': quantizationtools.UnweightedSearchTree({3: None})}
>>> settings = {
...     2: a,
...     4: b,
... }
>>> q_schema = quantizationtools.MeasurewiseQSchema(settings)
>>> f(q_schema[0]['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,
        },
    )
>>> print(format(q_schema[1]['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,
        },
    )
>>> q_schema[2]['search_tree']
UnweightedSearchTree(definition={2: None})
>>> q_schema[3]['search_tree']
UnweightedSearchTree(definition={2: None})
>>> q_schema[4]['search_tree']
UnweightedSearchTree(definition={3: None})
>>> q_schema[1000]['search_tree']
UnweightedSearchTree(definition={3: None})

The following is equivalent to the above schema definition:

>>> q_schema = quantizationtools.MeasurewiseQSchema(
...     (2, {'search_tree': quantizationtools.UnweightedSearchTree({2: None})}),
...     (4, {'search_tree': quantizationtools.UnweightedSearchTree({3: None})}),
...     )

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

Bases

Attribute summary

beatspan Default beatspan of beatwise q-schema.
item_class The schema’s item class.
items The item dictionary.
search_tree The default search tree.
target_class Target class of beatwise q-schema.
target_item_class Target item class of beatwise q-schema.
tempo The default tempo.
__call__(duration) Calls QSchema on duration.
__eq__(argument) Is true when ID of argument equals ID of Abjad object.
__format__([format_specification]) Formats q-event.
__getitem__(argument) Gets item or slice identified by argument.
__hash__() Hashes Abjad object.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets interpreter representation of Abjad object.

Read-only properties

BeatwiseQSchema.beatspan

Default beatspan of beatwise q-schema.

BeatwiseQSchema.item_class

The schema’s item class.

Returns beatwise q-schema item.

(QSchema).items

The item dictionary.

(QSchema).search_tree

The default search tree.

BeatwiseQSchema.target_class

Target class of beatwise q-schema.

Returns beatwise q-target.

BeatwiseQSchema.target_item_class

Target item class of beatwise q-schema.

Returns q-target beat.

(QSchema).tempo

The default tempo.

Special methods

(QSchema).__call__(duration)

Calls QSchema on duration.

(AbjadObject).__eq__(argument)

Is true when ID of argument equals ID of Abjad object. Otherwise false.

Returns true or false.

(QSchema).__format__(format_specification='')

Formats q-event.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

(QSchema).__getitem__(argument)

Gets item or slice identified by argument.

(AbjadObject).__hash__()

Hashes Abjad object.

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

Returns integer.

(AbjadObject).__ne__(argument)

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

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.