rhythmtrees

Tools for modeling IRCAM-style 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.parsers.base" { graph [label="abjad.parsers.base"]; node [color=1]; "abjad.parsers.base.Parser" [URL="../api/abjad/parsers/base.html#abjad.parsers.base.Parser", label=Parser, target=_top]; } subgraph "cluster_abjad.rhythmtrees" { graph [label="abjad.rhythmtrees"]; node [color=2]; "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", 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_builtins { graph [label=builtins]; node [color=3]; "builtins.object" [URL="https://docs.python.org/3.10/library/functions.html#object", label=object, target=_top]; } subgraph "cluster_uqbar.containers.unique_tree" { graph [label="uqbar.containers.unique_tree"]; node [color=4]; "uqbar.containers.unique_tree.UniqueTreeContainer" [URL="http://josiahwolfoberholtzer.com/uqbar/api/uqbar/containers/unique_tree.html#uqbar.containers.unique_tree.UniqueTreeContainer", label="Unique\nTree\nContainer", target=_top]; "uqbar.containers.unique_tree.UniqueTreeList" [URL="http://josiahwolfoberholtzer.com/uqbar/api/uqbar/containers/unique_tree.html#uqbar.containers.unique_tree.UniqueTreeList", label="Unique\nTree\nList", target=_top]; "uqbar.containers.unique_tree.UniqueTreeNode" [URL="http://josiahwolfoberholtzer.com/uqbar/api/uqbar/containers/unique_tree.html#uqbar.containers.unique_tree.UniqueTreeNode", label="Unique\nTree\nNode", target=_top]; "uqbar.containers.unique_tree.UniqueTreeContainer" -> "uqbar.containers.unique_tree.UniqueTreeList"; "uqbar.containers.unique_tree.UniqueTreeNode" -> "uqbar.containers.unique_tree.UniqueTreeContainer"; } "abjad.parsers.base.Parser" -> "abjad.rhythmtrees.RhythmTreeParser"; "builtins.object" -> "abjad.parsers.base.Parser"; "builtins.object" -> "abjad.rhythmtrees.RhythmTreeMixin"; "builtins.object" -> "uqbar.containers.unique_tree.UniqueTreeNode"; "uqbar.containers.unique_tree.UniqueTreeList" -> "abjad.rhythmtrees.RhythmTreeContainer"; "uqbar.containers.unique_tree.UniqueTreeNode" -> "abjad.rhythmtrees.RhythmTreeLeaf"; }


Classes

RhythmTreeContainer

Rhythm-tree container.

RhythmTreeLeaf

Rhythm-tree leaf.

RhythmTreeMixin

Abstract rhythm-tree node.

RhythmTreeParser

Rhythm-tree parser.

class abjad.rhythmtrees.RhythmTreeContainer(children=None, preprolated_duration=Duration(1, 1), name=None)[source]

Rhythm-tree container.

Initializes rhythm-tree container:

>>> container = abjad.rhythmtrees.RhythmTreeContainer(
...     preprolated_duration=abjad.Duration(1),
...     children=[],
... )
>>> container
RhythmTreeContainer((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=abjad.Duration(1)
... )
>>> leaf_b = abjad.rhythmtrees.RhythmTreeLeaf(
...     preprolated_duration=abjad.Duration(2)
... )
>>> container.extend([leaf_a, leaf_b])
>>> for _ in container:
...     _
... 
RhythmTreeLeaf(preprolated_duration=Duration(1, 1), is_pitched=True)
RhythmTreeLeaf(preprolated_duration=Duration(2, 1), is_pitched=True)
>>> another_container = abjad.rhythmtrees.RhythmTreeContainer(
...     preprolated_duration=abjad.Duration(2)
... )
>>> another_container.append(
...     abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=abjad.Duration(3))
... )
>>> another_container.append(container[1])
>>> container.append(another_container)
>>> for _ in container:
...     _
... 
RhythmTreeLeaf(preprolated_duration=Duration(1, 1), is_pitched=True)
RhythmTreeContainer((2, 3))

Call RhythmTreeContainer with a duration to make tuplets:

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

Attributes Summary

__add__

Concatenate containers self and argument.

__call__

Makes list of leaves and /or tuplets equal to pulse_duration.

__graph__

Graphs rhythm-tree container.

__radd__

Concatenates containers argument and self.

__repr__

Gets interpreter representation of rhythm-tree container.

rtm_format

Gets rhythm-tree container RTM format.


Special methods

__add__(argument)[source]

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)
>>> for _ in c:
...     _
... 
RhythmTreeLeaf(preprolated_duration=Duration(1, 1), is_pitched=True)
RhythmTreeLeaf(preprolated_duration=Duration(1, 1), is_pitched=True)
RhythmTreeLeaf(preprolated_duration=Duration(1, 1), is_pitched=True)
RhythmTreeLeaf(preprolated_duration=Duration(3, 1), is_pitched=True)
RhythmTreeLeaf(preprolated_duration=Duration(4, 1), is_pitched=True)
Return type:

RhythmTreeContainer

overridden __call__(pulse_duration)[source]

Makes list of leaves and /or tuplets equal to pulse_duration.

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

list[Leaf | Tuplet]

(UniqueTreeContainer).__contains__(expr)
(UniqueTreeList).__delitem__(i)
(UniqueTreeList).__getitem__(expr)
__graph__(**keywords)[source]

Graphs rhythm-tree container.

>>> string = "(1 (1 (2 (1 1 1)) 2))"
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]
>>> graph = tree.__graph__()
>>> print(format(graph, "graphviz"))
digraph G {
    graph [bgcolor=transparent,
        truecolor=true];
    node_0 [label="1",
        shape=triangle];
    node_1 [label="1",
        shape=box];
    node_2 [label="2",
        shape=triangle];
    node_3 [label="1",
        shape=box];
    node_4 [label="1",
        shape=box];
    node_5 [label="1",
        shape=box];
    node_6 [label="2",
        shape=box];
    node_0 -> node_1;
    node_0 -> node_2;
    node_0 -> node_6;
    node_2 -> node_3;
    node_2 -> node_4;
    node_2 -> node_5;
}
>>> abjad.graph(graph)  
Return type:

Graph

(UniqueTreeContainer).__iter__()
(UniqueTreeContainer).__len__()
__radd__(argument)[source]

Concatenates containers argument and self.

Return type:

RhythmTreeContainer

overridden __repr__()[source]

Gets interpreter representation of rhythm-tree container.

Return type:

str

(UniqueTreeList).__setitem__(i, new_items)

Methods

(UniqueTreeList).append(expr)
(UniqueTreeContainer).depth_first(top_down=True, prototype=None)
(UniqueTreeList).extend(expr)
(UniqueTreeList).index(expr)
(UniqueTreeList).insert(i, expr)
(UniqueTreeList).pop(i=-1)
(UniqueTreeContainer).recurse(prototype=None)
(UniqueTreeList).remove(node)

Read/write properties

(RhythmTreeMixin).preprolated_duration

Gets node duration in pulses.

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

Read-only properties

(RhythmTreeMixin).duration

Gets node duration.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]
>>> tree.duration
Duration(1, 1)
>>> tree[1].duration
Duration(1, 2)
>>> tree[1][1].duration
Duration(1, 4)
(UniqueTreeNode).graph_order

Get graph-order tuple for node.

>>> from uqbar.containers import UniqueTreeList, UniqueTreeNode
>>> root_container = UniqueTreeList(name="root")
>>> outer_container = UniqueTreeList(name="outer")
>>> inner_container = UniqueTreeList(name="inner")
>>> node_a = UniqueTreeNode(name="a")
>>> node_b = UniqueTreeNode(name="b")
>>> node_c = UniqueTreeNode(name="c")
>>> node_d = UniqueTreeNode(name="d")
>>> root_container.extend([node_a, outer_container])
>>> outer_container.extend([inner_container, node_d])
>>> inner_container.extend([node_b, node_c])
>>> for node in root_container.depth_first():
...     print(node.name, node.graph_order)
... 
a (0,)
outer (1,)
inner (1, 0)
b (1, 0, 0)
c (1, 0, 1)
d (1, 1)
(RhythmTreeMixin).pair

Gets preprolated duration as pair.

(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=abjad.Duration(1)
... )
>>> b = abjad.rhythmtrees.RhythmTreeContainer(
...     preprolated_duration=abjad.Duration(2)
... )
>>> c = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=abjad.Duration(3))
>>> d = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=abjad.Duration(4))
>>> e = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=abjad.Duration(5))
>>> a.extend([b, c])
>>> b.extend([d, e])
>>> a.parentage_ratios
(Duration(1, 1),)
>>> for item in b.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(2, 1), Duration(5, 1))
>>> for item in c.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(3, 1), Duration(5, 1))
>>> for item in d.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(2, 1), Duration(5, 1))
(Duration(4, 1), Duration(9, 1))
>>> for item in e.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(2, 1), Duration(5, 1))
(Duration(5, 1), Duration(9, 1))

Returns tuple.

(RhythmTreeMixin).pretty_rtm_format

Gets pretty-printed RTM format of node.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]
>>> print(tree.pretty_rtm_format)
(1 (
    (1 (
        1
        1))
    (1 (
        1
        1))))

Returns string.

(RhythmTreeMixin).prolation

Gets node prolation.

(RhythmTreeMixin).prolations

Prolations of rhythm tree node.

rtm_format

Gets rhythm-tree container RTM format.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]
>>> tree.rtm_format
'(1 ((1 (1 1)) (1 (1 1))))'
(RhythmTreeMixin).start_offset

Gets node start offset.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]
>>> tree.start_offset
Offset((0, 1))
>>> tree[1].start_offset
Offset((1, 2))
>>> tree[0][1].start_offset
Offset((1, 4))
(RhythmTreeMixin).stop_offset

Gets node stop offset.

class abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=Duration(1, 1), is_pitched=True, name=None)[source]

Rhythm-tree leaf.

Pitched rhythm-tree leaf makes notes:

>>> leaf = abjad.rhythmtrees.RhythmTreeLeaf(
...     preprolated_duration=abjad.Duration(5), is_pitched=True
... )
>>> leaf((1, 8))
[Note("c'2"), Note("c'8")]

Unpitched rhythm-tree leaf makes rests:

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

Attributes Summary

__call__

Makes list of leaves and / or tuplets equal to pulse_duration.

__graph__

Gets Graphviz graph of rhythm tree leaf.

__repr__

Gets interpreter representation of rhythm-tree leaf.

is_pitched

Is true when rhythm-tree leaf is pitched.

rtm_format

Gets RTM format of rhythm tree leaf.


Special methods

overridden __call__(pulse_duration)[source]

Makes list of leaves and / or tuplets equal to pulse_duration.

Return type:

list[Leaf | Tuplet]

__graph__(**keywords)[source]

Gets Graphviz graph of rhythm tree leaf.

Return type:

Graph

overridden __repr__()[source]

Gets interpreter representation of rhythm-tree leaf.

Return type:

str


Read/write properties

is_pitched

Is true when rhythm-tree leaf is pitched.

(RhythmTreeMixin).preprolated_duration

Gets node duration in pulses.

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

Read-only properties

(RhythmTreeMixin).duration

Gets node duration.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]
>>> tree.duration
Duration(1, 1)
>>> tree[1].duration
Duration(1, 2)
>>> tree[1][1].duration
Duration(1, 4)
(UniqueTreeNode).graph_order

Get graph-order tuple for node.

>>> from uqbar.containers import UniqueTreeList, UniqueTreeNode
>>> root_container = UniqueTreeList(name="root")
>>> outer_container = UniqueTreeList(name="outer")
>>> inner_container = UniqueTreeList(name="inner")
>>> node_a = UniqueTreeNode(name="a")
>>> node_b = UniqueTreeNode(name="b")
>>> node_c = UniqueTreeNode(name="c")
>>> node_d = UniqueTreeNode(name="d")
>>> root_container.extend([node_a, outer_container])
>>> outer_container.extend([inner_container, node_d])
>>> inner_container.extend([node_b, node_c])
>>> for node in root_container.depth_first():
...     print(node.name, node.graph_order)
... 
a (0,)
outer (1,)
inner (1, 0)
b (1, 0, 0)
c (1, 0, 1)
d (1, 1)
(RhythmTreeMixin).pair

Gets preprolated duration as pair.

(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=abjad.Duration(1)
... )
>>> b = abjad.rhythmtrees.RhythmTreeContainer(
...     preprolated_duration=abjad.Duration(2)
... )
>>> c = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=abjad.Duration(3))
>>> d = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=abjad.Duration(4))
>>> e = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=abjad.Duration(5))
>>> a.extend([b, c])
>>> b.extend([d, e])
>>> a.parentage_ratios
(Duration(1, 1),)
>>> for item in b.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(2, 1), Duration(5, 1))
>>> for item in c.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(3, 1), Duration(5, 1))
>>> for item in d.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(2, 1), Duration(5, 1))
(Duration(4, 1), Duration(9, 1))
>>> for item in e.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(2, 1), Duration(5, 1))
(Duration(5, 1), Duration(9, 1))

Returns tuple.

(RhythmTreeMixin).pretty_rtm_format

Gets pretty-printed RTM format of node.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]
>>> print(tree.pretty_rtm_format)
(1 (
    (1 (
        1
        1))
    (1 (
        1
        1))))

Returns string.

(RhythmTreeMixin).prolation

Gets node prolation.

(RhythmTreeMixin).prolations

Prolations of rhythm tree node.

rtm_format

Gets RTM format of rhythm tree leaf.

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

Gets node start offset.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]
>>> tree.start_offset
Offset((0, 1))
>>> tree[1].start_offset
Offset((1, 2))
>>> tree[0][1].start_offset
Offset((1, 4))
(RhythmTreeMixin).stop_offset

Gets node stop offset.

class abjad.rhythmtrees.RhythmTreeMixin(preprolated_duration=Duration(1, 1))[source]

Abstract rhythm-tree node.


Attributes Summary

duration

Gets node duration.

pair

Gets preprolated duration as pair.

parentage_ratios

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

preprolated_duration

Gets node duration in pulses.

pretty_rtm_format

Gets pretty-printed RTM format of node.

prolation

Gets node prolation.

prolations

Prolations of rhythm tree node.

start_offset

Gets node start offset.

stop_offset

Gets node stop offset.


Read/write properties

preprolated_duration

Gets node duration in pulses.

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

Read-only properties

duration

Gets node duration.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]
>>> tree.duration
Duration(1, 1)
>>> tree[1].duration
Duration(1, 2)
>>> tree[1][1].duration
Duration(1, 4)
pair

Gets preprolated duration as pair.

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=abjad.Duration(1)
... )
>>> b = abjad.rhythmtrees.RhythmTreeContainer(
...     preprolated_duration=abjad.Duration(2)
... )
>>> c = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=abjad.Duration(3))
>>> d = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=abjad.Duration(4))
>>> e = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=abjad.Duration(5))
>>> a.extend([b, c])
>>> b.extend([d, e])
>>> a.parentage_ratios
(Duration(1, 1),)
>>> for item in b.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(2, 1), Duration(5, 1))
>>> for item in c.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(3, 1), Duration(5, 1))
>>> for item in d.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(2, 1), Duration(5, 1))
(Duration(4, 1), Duration(9, 1))
>>> for item in e.parentage_ratios:
...     item
... 
Duration(1, 1)
(Duration(2, 1), Duration(5, 1))
(Duration(5, 1), Duration(9, 1))

Returns tuple.

pretty_rtm_format

Gets pretty-printed RTM format of node.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]
>>> print(tree.pretty_rtm_format)
(1 (
    (1 (
        1
        1))
    (1 (
        1
        1))))

Returns string.

prolation

Gets node prolation.

prolations

Prolations of rhythm tree node.

start_offset

Gets node start offset.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]
>>> tree.start_offset
Offset((0, 1))
>>> tree[1].start_offset
Offset((1, 2))
>>> tree[0][1].start_offset
Offset((1, 4))
stop_offset

Gets node stop offset.

class abjad.rhythmtrees.RhythmTreeParser(debug=False)[source]

Rhythm-tree parser.

Abjad’s rhythm-tree parser parses a micro-language resembling Ircam’s RTM Lisp syntax, and generates a sequence of rhythm-tree structures. Composers can maniuplate these structures and then convert them to Abjad score components.

>>> 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))))'
>>> for _ in rhythm_tree_container:
...     _
... 
RhythmTreeLeaf(preprolated_duration=Duration(1, 1), is_pitched=True)
RhythmTreeContainer((3, 2))
>>> base_duration = (1, 4)
>>> component_list = rhythm_tree_container(base_duration)
>>> tuplet = component_list[0]
>>> abjad.show(tuplet)  

Attributes Summary

lexer_rules_object

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

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.


Methods

p_container__LPAREN__DURATION__node_list_closed__RPAREN(p)[source]

container : LPAREN DURATION node_list_closed RPAREN

p_error(p)[source]
p_leaf__INTEGER(p)[source]

leaf : DURATION

p_node__container(p)[source]

node : container

p_node__leaf(p)[source]

node : leaf

p_node_list__node_list__node_list_item(p)[source]

node_list : node_list node_list_item

p_node_list__node_list_item(p)[source]

node_list : node_list_item

p_node_list_closed__LPAREN__node_list__RPAREN(p)[source]

node_list_closed : LPAREN node_list RPAREN

p_node_list_item__node(p)[source]

node_list_item : node

p_toplevel__EMPTY(p)[source]

toplevel :

p_toplevel__toplevel__node(p)[source]

toplevel : toplevel node

t_DURATION(t)[source]

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

t_error(t)[source]
t_newline(t)[source]

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
(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
(Parser).pickle_path

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


Functions

parse_rtm_syntax

Creates rhythm tree from RTM string; then calls rhythm tree on quarter-note pulse duration.

abjad.rhythmtrees.parse_rtm_syntax(string)[source]

Creates rhythm tree from RTM string; then calls rhythm tree on quarter-note pulse duration.

A single quarter note:

>>> result = abjad.rhythmtrees.parse_rtm_syntax("1")
>>> result
Note("c'4")
>>> abjad.show(result)  

A series of quarter notes:

>>> result = abjad.rhythmtrees.parse_rtm_syntax("1 1 1 1 1 1")
>>> result
Container("c'4 c'4 c'4 c'4 c'4 c'4")
>>> abjad.show(result)  

Notes with durations of the form n * 1/4:

>>> result = abjad.rhythmtrees.parse_rtm_syntax("1 2 3 4 5")
>>> result
Container("c'4 c'2 c'2. c'1 c'1 c'4")
>>> abjad.show(result)  

Notes with durations of the form 1/n * 1/4:

>>> result = abjad.rhythmtrees.parse_rtm_syntax("1 1/2 1/3 1/4 1/5")
>>> result
Container("c'4 c'8 { 8/12 c'8 } c'16 { 16/20 c'16 }")
>>> abjad.show(result)  

With arbitrary multipliers:

>>> result = abjad.rhythmtrees.parse_rtm_syntax("1 2/3 3/5")
>>> result
Container("c'4 { 4/6 c'4 } { 16/20 c'8. }")
>>> abjad.show(result)  

Divides quarter-note duration into 1 part; results in a note:

>>> string = "(1 (1))"
>>> result = abjad.rhythmtrees.parse_rtm_syntax(string)
>>> result
Note("c'4")
>>> abjad.show(result)  

Divides quarter-note duration 1:1; results in a container:

>>> string = "(1 (1 1))"
>>> result = abjad.rhythmtrees.parse_rtm_syntax(string)
>>> result
Container("c'8 c'8")
>>> abjad.show(result)  

Divides quarter-note duration 1:2; results in a tuplet:

>>> string = "(1 (1 2))"
>>> result = abjad.rhythmtrees.parse_rtm_syntax(string)
>>> result
Tuplet('3:2', "c'8 c'4")
>>> abjad.show(result)  

Divides half-note duration into 1 part; results in a note:

>>> string = "(2 (1))"
>>> result = abjad.rhythmtrees.parse_rtm_syntax(string)
>>> result
Note("c'2")
>>> abjad.show(result)  

Divides half-note duration 1:1; results in a container:

>>> string = "(2 (1 1))"
>>> result = abjad.rhythmtrees.parse_rtm_syntax(string)
>>> result
Container("c'4 c'4")
>>> abjad.show(result)  

Divides half-note duration 1:2; results in a tuplet:

>>> string = "(2 (1 2))"
>>> result = abjad.rhythmtrees.parse_rtm_syntax(string)
>>> result
Tuplet('3:2', "c'4 c'2")
>>> abjad.show(result)  

Divides three successive quarter-note durations, according to ratios of 1, 1:1, 1:2:

>>> string = "(1 (1)) (1 (1 1)) (1 (1 2))"
>>> result = abjad.rhythmtrees.parse_rtm_syntax(string)
>>> result
Container("c'4 c'8 c'8 { 2/3 c'8 c'4 }")
>>> abjad.show(result)  

Another example:

>>> string = "(1 (1 (1 (1 1)) 1))"
>>> tuplet = abjad.rhythmtrees.parse_rtm_syntax(string)
>>> abjad.show(tuplet)  

Fractional durations are allowed:

>>> string = "(3/4 (1 1/2 (4/3 (1 -1/2 1))))"
>>> tuplet = abjad.rhythmtrees.parse_rtm_syntax(string)
>>> abjad.show(tuplet)  
Return type:

Container | Leaf | Tuplet