rhythmtrees

Tools for modeling “rhythm-trees”.

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.rhythmtrees" { graph [label="abjad.rhythmtrees"]; node [color=1]; "abjad.rhythmtrees.RhythmTreeContainer" [URL="../api/abjad/rhythmtrees.html#abjad.rhythmtrees.RhythmTreeContainer", color=black, fontcolor=white, label="Rhythm\nTree\nContainer", target=_top]; "abjad.rhythmtrees.RhythmTreeLeaf" [URL="../api/abjad/rhythmtrees.html#abjad.rhythmtrees.RhythmTreeLeaf", color=black, fontcolor=white, label="Rhythm\nTree\nLeaf", target=_top]; "abjad.rhythmtrees.RhythmTreeMixin" [URL="../api/abjad/rhythmtrees.html#abjad.rhythmtrees.RhythmTreeMixin", color=black, fontcolor=white, label="Rhythm\nTree\nMixin", shape=oval, style="bold, filled", target=_top]; "abjad.rhythmtrees.RhythmTreeParser" [URL="../api/abjad/rhythmtrees.html#abjad.rhythmtrees.RhythmTreeParser", color=black, fontcolor=white, label="Rhythm\nTree\nParser", target=_top]; "abjad.rhythmtrees.RhythmTreeMixin" -> "abjad.rhythmtrees.RhythmTreeContainer"; "abjad.rhythmtrees.RhythmTreeMixin" -> "abjad.rhythmtrees.RhythmTreeLeaf"; } subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=2]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjad/system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", label="Abjad\nObject", target=_top]; "abjad.system.Parser.Parser" [URL="../api/abjad/system/Parser.html#abjad.system.Parser.Parser", label=Parser, shape=oval, style=bold, target=_top]; "abjad.system.AbjadObject.AbjadObject" -> "abjad.system.Parser.Parser"; } subgraph cluster_builtins { graph [label=builtins]; node [color=3]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } subgraph "cluster_uqbar.containers" { graph [label="uqbar.containers"]; node [color=4]; "uqbar.containers.UniqueTreeContainer.UniqueTreeContainer" [label="Unique\nTree\nContainer"]; "uqbar.containers.UniqueTreeNode.UniqueTreeNode" [label="Unique\nTree\nNode"]; "uqbar.containers.UniqueTreeNode.UniqueTreeNode" -> "uqbar.containers.UniqueTreeContainer.UniqueTreeContainer"; } "abjad.system.AbjadObject.AbjadObject" -> "abjad.rhythmtrees.RhythmTreeMixin"; "abjad.system.Parser.Parser" -> "abjad.rhythmtrees.RhythmTreeParser"; "builtins.object" -> "abjad.system.AbjadObject.AbjadObject"; "builtins.object" -> "uqbar.containers.UniqueTreeNode.UniqueTreeNode"; "uqbar.containers.UniqueTreeContainer.UniqueTreeContainer" -> "abjad.rhythmtrees.RhythmTreeContainer"; "uqbar.containers.UniqueTreeNode.UniqueTreeNode" -> "abjad.rhythmtrees.RhythmTreeLeaf"; }


Abstract Classes

RhythmTreeMixin Abstract rhythm-tree node.
abstract class abjad.rhythmtrees.RhythmTreeMixin(preprolated_duration=1)

Abstract rhythm-tree node.


Attributes Summary

__call__ Calls rhythm tree node on pulse_duration.
duration The preprolated_duration of the node:
parentage_ratios A sequence describing the relative durations of the nodes in a node’s improper parentage.
preprolated_duration The node’s preprolated_duration in pulses:
pretty_rtm_format The node’s pretty-printed RTM format:
prolation Prolation of rhythm tree node.
prolations Prolations of rhythm tree node.
rtm_format The node’s RTM format:
start_offset The starting offset of a node in a rhythm-tree relative the root.
stop_offset The stopping offset of a node in a rhythm-tree relative the root.

Special methods

abstract __call__(pulse_duration)

Calls rhythm tree node on pulse_duration.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to '' or 'storage'. Interprets '' equal to 'storage'.

Returns string.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.


Read/write properties

preprolated_duration

The node’s preprolated_duration in pulses:

>>> node = abjad.rhythmtrees.RhythmTreeLeaf(
...     preprolated_duration=1)
>>> node.preprolated_duration
Duration(1, 1)
>>> node.preprolated_duration = 2
>>> node.preprolated_duration
Duration(2, 1)

Returns int.


Read-only properties

duration

The preprolated_duration of the node:

>>> rtm = '(1 ((1 (1 1)) (1 (1 1))))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> tree.duration
Duration(1, 1)
>>> tree[1].duration
Duration(1, 2)
>>> tree[1][1].duration
Duration(1, 4)

Return Duration instance.

parentage_ratios

A sequence describing the relative durations of the nodes in a node’s improper parentage.

The first item in the sequence is the preprolated_duration of the root node, and subsequent items are pairs of the preprolated duration of the next node in the parentage and the total preprolated_duration of that node and its siblings:

>>> a = abjad.rhythmtrees.RhythmTreeContainer(preprolated_duration=1)
>>> b = abjad.rhythmtrees.RhythmTreeContainer(preprolated_duration=2)
>>> c = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=3)
>>> d = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=4)
>>> e = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=5)
>>> a.extend([b, c])
>>> b.extend([d, e])
>>> a.parentage_ratios
(Duration(1, 1),)
>>> b.parentage_ratios
(Duration(1, 1), (Duration(2, 1), Duration(5, 1)))
>>> c.parentage_ratios
(Duration(1, 1), (Duration(3, 1), Duration(5, 1)))
>>> d.parentage_ratios
(Duration(1, 1), (Duration(2, 1), Duration(5, 1)), (Duration(4, 1), Duration(9, 1)))
>>> e.parentage_ratios
(Duration(1, 1), (Duration(2, 1), Duration(5, 1)), (Duration(5, 1), Duration(9, 1)))

Returns tuple.

pretty_rtm_format

The node’s pretty-printed RTM format:

>>> rtm = '(1 ((1 (1 1)) (1 (1 1))))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> print(tree.pretty_rtm_format)
(1 (
    (1 (
        1
        1))
    (1 (
        1
        1))))

Returns string.

prolation

Prolation of rhythm tree node.

Returns multiplier.

prolations

Prolations of rhythm tree node.

Returns tuple.

abstract rtm_format

The node’s RTM format:

>>> rtm = '(1 ((1 (1 1)) (1 (1 1))))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> tree.rtm_format
'(1 ((1 (1 1)) (1 (1 1))))'

Returns string.

start_offset

The starting offset of a node in a rhythm-tree relative the root.

>>> rtm = '(1 ((1 (1 1)) (1 (1 1))))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> tree.start_offset
Offset(0, 1)
>>> tree[1].start_offset
Offset(1, 2)
>>> tree[0][1].start_offset
Offset(1, 4)

Returns Offset instance.

stop_offset

The stopping offset of a node in a rhythm-tree relative the root.


Classes

RhythmTreeContainer Rhythm-tree container.
RhythmTreeLeaf Rhythm-tree leaf.
RhythmTreeParser Rhythm-tree parser.
class abjad.rhythmtrees.RhythmTreeContainer(children=None, preprolated_duration=1, name=None)

Rhythm-tree container.

Initializes rhythm-tree container:

>>> container = abjad.rhythmtrees.RhythmTreeContainer(
...     preprolated_duration=1,
...     children=[],
...     )
>>> abjad.f(container)
abjad.rhythmtrees.RhythmTreeContainer(
    children=(),
    preprolated_duration=abjad.Duration(1, 1),
    )

Similar to Abjad containers, RhythmTreeContainer supports a list interface, and can be appended, extended, indexed and so forth by other RhythmTreeMixin subclasses:

>>> leaf_a = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=1)
>>> leaf_b = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=2)
>>> container.extend([leaf_a, leaf_b])
>>> abjad.f(container)
abjad.rhythmtrees.RhythmTreeContainer(
    children=(
        abjad.rhythmtrees.RhythmTreeLeaf(
            preprolated_duration=abjad.Duration(1, 1),
            is_pitched=True,
            ),
        abjad.rhythmtrees.RhythmTreeLeaf(
            preprolated_duration=abjad.Duration(2, 1),
            is_pitched=True,
            ),
        ),
    preprolated_duration=abjad.Duration(1, 1),
    )
>>> another_container = abjad.rhythmtrees.RhythmTreeContainer(
...     preprolated_duration=2)
>>> another_container.append(
...     abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=3))
>>> another_container.append(container[1])
>>> container.append(another_container)
>>> abjad.f(container)
abjad.rhythmtrees.RhythmTreeContainer(
    children=(
        abjad.rhythmtrees.RhythmTreeLeaf(
            preprolated_duration=abjad.Duration(1, 1),
            is_pitched=True,
            ),
        abjad.rhythmtrees.RhythmTreeContainer(
            children=(
                abjad.rhythmtrees.RhythmTreeLeaf(
                    preprolated_duration=abjad.Duration(3, 1),
                    is_pitched=True,
                    ),
                abjad.rhythmtrees.RhythmTreeLeaf(
                    preprolated_duration=abjad.Duration(2, 1),
                    is_pitched=True,
                    ),
                ),
            preprolated_duration=abjad.Duration(2, 1),
            ),
        ),
    preprolated_duration=abjad.Duration(1, 1),
    )

Call RhythmTreeContainer with a preprolated_duration to generate a tuplet structure:

>>> components = container((1, 4))
>>> tuplet = components[0]
>>> abjad.show(tuplet) 

Returns RhythmTreeContainer instance.


Attributes Summary

__add__ Concatenate containers self and argument.
__call__ Generates Abjad score components.
__graph__ The Graph representation of the RhythmTreeContainer:
__radd__ Concatenates containers argument and self.
__repr__ Gets interpreter representation of rhythm tree container.
rtm_format The node’s RTM format:

Special methods

__add__(argument)

Concatenate containers self and argument. The operation c = a + b returns a new RhythmTreeContainer c with the content of both a and b, and a preprolated_duration equal to the sum of the durations of a and b. The operation is non-commutative: the content of the first operand will be placed before the content of the second operand:

>>> a = abjad.rhythmtrees.RhythmTreeParser()('(1 (1 1 1))')[0]
>>> b = abjad.rhythmtrees.RhythmTreeParser()('(2 (3 4))')[0]
>>> c = a + b
>>> c.preprolated_duration
Duration(3, 1)
>>> abjad.f(c)
abjad.rhythmtrees.RhythmTreeContainer(
    children=(
        abjad.rhythmtrees.RhythmTreeLeaf(
            preprolated_duration=abjad.Duration(1, 1),
            is_pitched=True,
            ),
        abjad.rhythmtrees.RhythmTreeLeaf(
            preprolated_duration=abjad.Duration(1, 1),
            is_pitched=True,
            ),
        abjad.rhythmtrees.RhythmTreeLeaf(
            preprolated_duration=abjad.Duration(1, 1),
            is_pitched=True,
            ),
        abjad.rhythmtrees.RhythmTreeLeaf(
            preprolated_duration=abjad.Duration(3, 1),
            is_pitched=True,
            ),
        abjad.rhythmtrees.RhythmTreeLeaf(
            preprolated_duration=abjad.Duration(4, 1),
            is_pitched=True,
            ),
        ),
    preprolated_duration=abjad.Duration(3, 1),
    )

Returns new RhythmTreeContainer.

__call__(pulse_duration)

Generates Abjad score components.

>>> rtm = '(1 (1 (2 (1 1 1)) 2))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> tree((1, 4))
[Tuplet(Multiplier(4, 5), "c'16 { 2/3 c'16 c'16 c'16 } c'8")]
>>> staff = abjad.Staff(tree((1, 4)))
>>> abjad.show(staff) 

Returns list of components.

(UniqueTreeContainer).__contains__(expr)
(UniqueTreeContainer).__delitem__(i)
(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to '' or 'storage'. Interprets '' equal to 'storage'.

Returns string.

(UniqueTreeContainer).__getitem__(expr)
__graph__(**keywords)

The Graph representation of the RhythmTreeContainer:

>>> rtm = '(1 (1 (2 (1 1 1)) 2))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> graph = tree.__graph__()
>>> print(format(graph, 'graphviz'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported format string passed to method.__format__
>>> abjad.graph(graph) 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/josiah/Source/github.com/Abjad/abjad-ext-book/abjadext/book/CodeBlock.py", line 442, in graph
    raise TypeError('Cannot graph {!r}'.format(type(argument)))
TypeError: Cannot graph <class 'method'>

Return Graph instance.

(UniqueTreeContainer).__iter__()
(UniqueTreeContainer).__len__()
__radd__(argument)

Concatenates containers argument and self.

Returns new RhythmTreeContainer.

__repr__()

Gets interpreter representation of rhythm tree container.

Returns string.

(UniqueTreeContainer).__setitem__(i, expr)

Methods

(UniqueTreeContainer).append(expr)
(UniqueTreeContainer).depth_first(top_down=True)
(UniqueTreeContainer).extend(expr)
(UniqueTreeContainer).index(expr)
(UniqueTreeContainer).insert(i, expr)
(UniqueTreeContainer).pop(i=-1)
(UniqueTreeNode).precede_by(expr)
(UniqueTreeContainer).recurse()
(UniqueTreeContainer).remove(node)
(UniqueTreeNode).replace_with(expr)
(UniqueTreeNode).succeed_by(expr)

Read/write properties

(UniqueTreeNode).name
(RhythmTreeMixin).preprolated_duration

The node’s preprolated_duration in pulses:

>>> node = abjad.rhythmtrees.RhythmTreeLeaf(
...     preprolated_duration=1)
>>> node.preprolated_duration
Duration(1, 1)
>>> node.preprolated_duration = 2
>>> node.preprolated_duration
Duration(2, 1)

Returns int.


Read-only properties

(UniqueTreeContainer).children
(UniqueTreeNode).depth
(RhythmTreeMixin).duration

The preprolated_duration of the node:

>>> rtm = '(1 ((1 (1 1)) (1 (1 1))))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> tree.duration
Duration(1, 1)
>>> tree[1].duration
Duration(1, 2)
>>> tree[1][1].duration
Duration(1, 4)

Return Duration instance.

(UniqueTreeNode).graph_order
(UniqueTreeNode).parent
(UniqueTreeNode).parentage
(RhythmTreeMixin).parentage_ratios

A sequence describing the relative durations of the nodes in a node’s improper parentage.

The first item in the sequence is the preprolated_duration of the root node, and subsequent items are pairs of the preprolated duration of the next node in the parentage and the total preprolated_duration of that node and its siblings:

>>> a = abjad.rhythmtrees.RhythmTreeContainer(preprolated_duration=1)
>>> b = abjad.rhythmtrees.RhythmTreeContainer(preprolated_duration=2)
>>> c = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=3)
>>> d = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=4)
>>> e = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=5)
>>> a.extend([b, c])
>>> b.extend([d, e])
>>> a.parentage_ratios
(Duration(1, 1),)
>>> b.parentage_ratios
(Duration(1, 1), (Duration(2, 1), Duration(5, 1)))
>>> c.parentage_ratios
(Duration(1, 1), (Duration(3, 1), Duration(5, 1)))
>>> d.parentage_ratios
(Duration(1, 1), (Duration(2, 1), Duration(5, 1)), (Duration(4, 1), Duration(9, 1)))
>>> e.parentage_ratios
(Duration(1, 1), (Duration(2, 1), Duration(5, 1)), (Duration(5, 1), Duration(9, 1)))

Returns tuple.

(RhythmTreeMixin).pretty_rtm_format

The node’s pretty-printed RTM format:

>>> rtm = '(1 ((1 (1 1)) (1 (1 1))))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> print(tree.pretty_rtm_format)
(1 (
    (1 (
        1
        1))
    (1 (
        1
        1))))

Returns string.

(RhythmTreeMixin).prolation

Prolation of rhythm tree node.

Returns multiplier.

(RhythmTreeMixin).prolations

Prolations of rhythm tree node.

Returns tuple.

(UniqueTreeNode).root
rtm_format

The node’s RTM format:

>>> rtm = '(1 ((1 (1 1)) (1 (1 1))))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> tree.rtm_format
'(1 ((1 (1 1)) (1 (1 1))))'

Returns string.

(RhythmTreeMixin).start_offset

The starting offset of a node in a rhythm-tree relative the root.

>>> rtm = '(1 ((1 (1 1)) (1 (1 1))))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> tree.start_offset
Offset(0, 1)
>>> tree[1].start_offset
Offset(1, 2)
>>> tree[0][1].start_offset
Offset(1, 4)

Returns Offset instance.

(RhythmTreeMixin).stop_offset

The stopping offset of a node in a rhythm-tree relative the root.

class abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=1, is_pitched=True, name=None)

Rhythm-tree leaf.

>>> leaf = abjad.rhythmtrees.RhythmTreeLeaf(
...     preprolated_duration=5, is_pitched=True)
>>> leaf
RhythmTreeLeaf(preprolated_duration=Duration(5, 1), is_pitched=True)

Calls with a pulse preprolated duration to generate leaves:

>>> result = leaf((1, 8))
>>> result
Selection([Note("c'2"), Note("c'8")])

Generates rests when called if is_pitched is false:

>>> abjad.rhythmtrees.RhythmTreeLeaf(
...     preprolated_duration=7, is_pitched=False)((1, 16))
Selection([Rest('r4..')])

Attributes Summary

__call__ Generate Abjad score components:
__graph__ Graphviz graph of rhythm tree leaf.
is_pitched Gets and sets boolean equal to true if leaf is pitched.
rtm_format RTM format of rhythm tree leaf.

Special methods

__call__(pulse_duration)

Generate Abjad score components:

>>> leaf = abjad.rhythmtrees.RhythmTreeLeaf(5)
>>> leaf((1, 4))
Selection([Note("c'1"), Note("c'4")])

Returns sequence of components.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to '' or 'storage'. Interprets '' equal to 'storage'.

Returns string.

__graph__(**keywords)

Graphviz graph of rhythm tree leaf.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.


Methods

(UniqueTreeNode).precede_by(expr)
(UniqueTreeNode).replace_with(expr)
(UniqueTreeNode).succeed_by(expr)

Read/write properties

is_pitched

Gets and sets boolean equal to true if leaf is pitched.

>>> leaf = abjad.rhythmtrees.RhythmTreeLeaf()
>>> leaf.is_pitched
True
>>> leaf.is_pitched = False
>>> leaf.is_pitched
False

Returns true or false.

(UniqueTreeNode).name
(RhythmTreeMixin).preprolated_duration

The node’s preprolated_duration in pulses:

>>> node = abjad.rhythmtrees.RhythmTreeLeaf(
...     preprolated_duration=1)
>>> node.preprolated_duration
Duration(1, 1)
>>> node.preprolated_duration = 2
>>> node.preprolated_duration
Duration(2, 1)

Returns int.


Read-only properties

(UniqueTreeNode).depth
(RhythmTreeMixin).duration

The preprolated_duration of the node:

>>> rtm = '(1 ((1 (1 1)) (1 (1 1))))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> tree.duration
Duration(1, 1)
>>> tree[1].duration
Duration(1, 2)
>>> tree[1][1].duration
Duration(1, 4)

Return Duration instance.

(UniqueTreeNode).graph_order
(UniqueTreeNode).parent
(UniqueTreeNode).parentage
(RhythmTreeMixin).parentage_ratios

A sequence describing the relative durations of the nodes in a node’s improper parentage.

The first item in the sequence is the preprolated_duration of the root node, and subsequent items are pairs of the preprolated duration of the next node in the parentage and the total preprolated_duration of that node and its siblings:

>>> a = abjad.rhythmtrees.RhythmTreeContainer(preprolated_duration=1)
>>> b = abjad.rhythmtrees.RhythmTreeContainer(preprolated_duration=2)
>>> c = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=3)
>>> d = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=4)
>>> e = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=5)
>>> a.extend([b, c])
>>> b.extend([d, e])
>>> a.parentage_ratios
(Duration(1, 1),)
>>> b.parentage_ratios
(Duration(1, 1), (Duration(2, 1), Duration(5, 1)))
>>> c.parentage_ratios
(Duration(1, 1), (Duration(3, 1), Duration(5, 1)))
>>> d.parentage_ratios
(Duration(1, 1), (Duration(2, 1), Duration(5, 1)), (Duration(4, 1), Duration(9, 1)))
>>> e.parentage_ratios
(Duration(1, 1), (Duration(2, 1), Duration(5, 1)), (Duration(5, 1), Duration(9, 1)))

Returns tuple.

(RhythmTreeMixin).pretty_rtm_format

The node’s pretty-printed RTM format:

>>> rtm = '(1 ((1 (1 1)) (1 (1 1))))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> print(tree.pretty_rtm_format)
(1 (
    (1 (
        1
        1))
    (1 (
        1
        1))))

Returns string.

(RhythmTreeMixin).prolation

Prolation of rhythm tree node.

Returns multiplier.

(RhythmTreeMixin).prolations

Prolations of rhythm tree node.

Returns tuple.

(UniqueTreeNode).root
rtm_format

RTM format of rhythm tree leaf.

>>> abjad.rhythmtrees.RhythmTreeLeaf(1, is_pitched=True).rtm_format
'1'
>>> abjad.rhythmtrees.RhythmTreeLeaf(5, is_pitched=False).rtm_format
'-5'

Returns string.

(RhythmTreeMixin).start_offset

The starting offset of a node in a rhythm-tree relative the root.

>>> rtm = '(1 ((1 (1 1)) (1 (1 1))))'
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(rtm)[0]
>>> tree.start_offset
Offset(0, 1)
>>> tree[1].start_offset
Offset(1, 2)
>>> tree[0][1].start_offset
Offset(1, 4)

Returns Offset instance.

(RhythmTreeMixin).stop_offset

The stopping offset of a node in a rhythm-tree relative the root.

class abjad.rhythmtrees.RhythmTreeParser(debug=False)

Rhythm-tree parser.

Abjad’s rhythm-tree parser parses a micro-language resembling Ircam’s RTM Lisp syntax, and generates a sequence of RhythmTree structures, which can be furthered manipulated by composers, before being converted into an Abjad score object:

>>> parser = abjad.rhythmtrees.RhythmTreeParser()
>>> string = '(3 (1 (1 ((2 (1 1 1)) 2 2 1))))'
>>> rhythm_tree_list = parser(string)
>>> rhythm_tree_container = rhythm_tree_list[0]
>>> rhythm_tree_container.rtm_format
'(3 (1 (1 ((2 (1 1 1)) 2 2 1))))'
>>> abjad.f(rhythm_tree_container)
abjad.rhythmtrees.RhythmTreeContainer(
    children=(
        abjad.rhythmtrees.RhythmTreeLeaf(
            preprolated_duration=abjad.Duration(1, 1),
            is_pitched=True,
            ),
        abjad.rhythmtrees.RhythmTreeContainer(
            children=(
                abjad.rhythmtrees.RhythmTreeContainer(
                    children=(
                        abjad.rhythmtrees.RhythmTreeLeaf(
                            preprolated_duration=abjad.Duration(1, 1),
                            is_pitched=True,
                            ),
                        abjad.rhythmtrees.RhythmTreeLeaf(
                            preprolated_duration=abjad.Duration(1, 1),
                            is_pitched=True,
                            ),
                        abjad.rhythmtrees.RhythmTreeLeaf(
                            preprolated_duration=abjad.Duration(1, 1),
                            is_pitched=True,
                            ),
                        ),
                    preprolated_duration=abjad.Duration(2, 1),
                    ),
                abjad.rhythmtrees.RhythmTreeLeaf(
                    preprolated_duration=abjad.Duration(2, 1),
                    is_pitched=True,
                    ),
                abjad.rhythmtrees.RhythmTreeLeaf(
                    preprolated_duration=abjad.Duration(2, 1),
                    is_pitched=True,
                    ),
                abjad.rhythmtrees.RhythmTreeLeaf(
                    preprolated_duration=abjad.Duration(1, 1),
                    is_pitched=True,
                    ),
                ),
            preprolated_duration=abjad.Duration(1, 1),
            ),
        ),
    preprolated_duration=abjad.Duration(3, 1),
    )
>>> base_duration = (1, 4)
>>> component_list = rhythm_tree_container(base_duration)
>>> tuplet = component_list[0]
>>> abjad.show(tuplet) 

Attributes Summary

lexer_rules_object Gets object containing the parser’s lexical rule definitions.
p_container__LPAREN__DURATION__node_list_closed__RPAREN container : LPAREN DURATION node_list_closed RPAREN
p_error
p_leaf__INTEGER leaf : DURATION
p_node__container node : container
p_node__leaf node : leaf
p_node_list__node_list__node_list_item node_list : node_list node_list_item
p_node_list__node_list_item node_list : node_list_item
p_node_list_closed__LPAREN__node_list__RPAREN node_list_closed : LPAREN node_list RPAREN
p_node_list_item__node node_list_item : node
p_toplevel__EMPTY toplevel :
p_toplevel__toplevel__node toplevel : toplevel node
parser_rules_object Gets object containing the parser’s syntactical rule definitions.
start
t_DURATION -?[1-9]d*(/[1-9]d*)?
t_LPAREN
t_RPAREN
t_error
t_ignore
t_newline n+
tokens

Special methods

(Parser).__call__(string)

Parse string and return result.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to '' or 'storage'. Interprets '' equal to 'storage'.

Returns string.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.


Methods

p_container__LPAREN__DURATION__node_list_closed__RPAREN(p)

container : LPAREN DURATION node_list_closed RPAREN

p_error(p)
p_leaf__INTEGER(p)

leaf : DURATION

p_node__container(p)

node : container

p_node__leaf(p)

node : leaf

p_node_list__node_list__node_list_item(p)

node_list : node_list node_list_item

p_node_list__node_list_item(p)

node_list : node_list_item

p_node_list_closed__LPAREN__node_list__RPAREN(p)

node_list_closed : LPAREN node_list RPAREN

p_node_list_item__node(p)

node_list_item : node

p_toplevel__EMPTY(p)

toplevel :

p_toplevel__toplevel__node(p)

toplevel : toplevel node

t_DURATION(t)

-?[1-9]d*(/[1-9]d*)?

t_error(t)
t_newline(t)

n+

(Parser).tokenize(string)

Tokenize string and print results.


Read-only properties

(Parser).debug

Is true when parser runs in debugging mode.

(Parser).lexer

Gets parser’s PLY Lexer instance.

lexer_rules_object

Gets object containing the parser’s lexical rule definitions.

(Parser).logger

Gets parser’s logger.

(Parser).logger_path

Gets parser’s logfile output path.

(Parser).output_path

Gets output path for files associated with the parser.

(Parser).parser

Gets parser’s PLY LRParser instance.

parser_rules_object

Gets object containing the parser’s syntactical rule definitions.

(Parser).pickle_path

Gets output path for the parser’s pickled parsing tables.


Functions

parse_rtm_syntax Parses RTM syntax.
abjad.rhythmtrees.parse_rtm_syntax(rtm)

Parses RTM syntax.

Parses tuplet:

>>> rtm = '(1 (1 (1 (1 1)) 1))'
>>> tuplet = abjad.rhythmtrees.parse_rtm_syntax(rtm)
>>> abjad.show(tuplet) 

Also supports fractional durations:

>>> rtm = '(3/4 (1 1/2 (4/3 (1 -1/2 1))))'
>>> tuplet = abjad.rhythmtrees.parse_rtm_syntax(rtm)
>>> abjad.show(tuplet) 

Returns tuplet or container.