abjad.rhythmtrees

abjad.rhythmtrees.call(nodes[, duration])

Calls each node in nodes with duration.

abjad.rhythmtrees.extract_trivial_tuplets(...)

Extracts trivial tuplets from argument.

abjad.rhythmtrees.parse(string)

Parses RTM string.

abjad.rhythmtrees.RhythmTreeContainer(pair)

Rhythm-tree container.

abjad.rhythmtrees.RhythmTreeLeaf(pair, *[, ...])

Rhythm-tree leaf.

abjad.rhythmtrees.RhythmTreeNode(pair)

Rhythm-tree node.

abjad.rhythmtrees.RhythmTreeParser([debug])

Rhythm-tree parser.

abjad.rhythmtrees.call(nodes, duration: Duration = Duration(1, 4)) list[Leaf | Tuplet][source]

Calls each node in nodes with duration.

abjad.rhythmtrees.extract_trivial_tuplets(argument) None[source]

Extracts trivial tuplets from argument.

abjad.rhythmtrees.parse(string: str) list[RhythmTreeContainer | RhythmTreeLeaf][source]

Parses RTM string.

Quarter note:

>>> nodes = abjad.rhythmtrees.parse("1")
>>> components = abjad.rhythmtrees.call(nodes)
>>> voice = abjad.Voice(components)
>>> abjad.setting(voice[0]).Score.proportionalNotationDuration = "#1/12"
>>> abjad.show(voice)  

Series of quarter notes:

>>> nodes = abjad.rhythmtrees.parse("1 1 1 1 1 1")
>>> components = abjad.rhythmtrees.call(nodes)
>>> voice = abjad.Voice(components)
>>> abjad.setting(voice[0]).Score.proportionalNotationDuration = "#1/12"
>>> abjad.show(voice)  

Half-note duration divided into 1 part:

>>> string = "(2 (1))"
>>> nodes = abjad.rhythmtrees.parse(string)
>>> components = abjad.rhythmtrees.call(nodes)
>>> voice = abjad.Voice(components)
>>> leaf = abjad.select.leaf(voice, 0)
>>> abjad.setting(leaf).Score.proportionalNotationDuration = "#1/12"
>>> abjad.show(voice)  
>>> abjad.rhythmtrees.extract_trivial_tuplets(voice)
>>> abjad.show(voice)  

Half-note duration divided 1:1:

>>> string = "(2 (1 1))"
>>> nodes = abjad.rhythmtrees.parse(string)
>>> components = abjad.rhythmtrees.call(nodes)
>>> voice = abjad.Voice(components)
>>> leaf = abjad.select.leaf(voice, 0)
>>> abjad.setting(leaf).Score.proportionalNotationDuration = "#1/12"
>>> abjad.show(voice)  
>>> abjad.rhythmtrees.extract_trivial_tuplets(voice)
>>> abjad.show(voice)  

Half-note duration divided 1:2:

>>> string = "(2 (1 2))"
>>> nodes = abjad.rhythmtrees.parse(string)
>>> components = abjad.rhythmtrees.call(nodes)
>>> voice = abjad.Voice(components)
>>> leaf = abjad.select.leaf(voice, 0)
>>> abjad.setting(leaf).Score.proportionalNotationDuration = "#1/12"
>>> abjad.show(voice)  

Successive quarter-note durations, divided 1, 1:1, 1:2:

>>> string = "(1 (1)) (1 (1 1)) (1 (1 2))"
>>> nodes = abjad.rhythmtrees.parse(string)
>>> components = abjad.rhythmtrees.call(nodes)
>>> voice = abjad.Voice(components)
>>> leaf = abjad.select.leaf(voice, 0)
>>> abjad.setting(leaf).Score.proportionalNotationDuration = "#1/12"
>>> abjad.show(voice)  
>>> abjad.rhythmtrees.extract_trivial_tuplets(voice)
>>> abjad.show(voice)  

Dyadic durations:

>>> nodes = abjad.rhythmtrees.parse("1 1/2 1/2 3/2 1/4")
>>> components = abjad.rhythmtrees.call(nodes)
>>> voice = abjad.Voice(components)
>>> abjad.setting(voice[0]).Score.proportionalNotationDuration = "#1/12"
>>> abjad.show(voice)  

Tuplets without dotted values:

>>> string = "(1 (1 (1 (1 1)) 1))"
>>> nodes = abjad.rhythmtrees.parse(string)
>>> components = abjad.rhythmtrees.call(nodes, abjad.Duration(1, 2))
>>> voice = abjad.Voice(components)
>>> leaf = abjad.select.leaf(voice, 0)
>>> abjad.setting(leaf).Score.proportionalNotationDuration = "#1/12"
>>> abjad.show(voice)  
>>> abjad.rhythmtrees.extract_trivial_tuplets(voice)
>>> abjad.show(voice)  
class abjad.rhythmtrees.RhythmTreeContainer(pair: tuple[int, int], children: Sequence[RhythmTreeNode] = (), *, name: str = '')[source]

Rhythm-tree container.

Extend rhythm-tree containers with rhythm-tree leaves or other rhythm-tree containers:

>>> rtc = abjad.rhythmtrees.RhythmTreeContainer((1, 1))
>>> rtc.append(abjad.rhythmtrees.RhythmTreeLeaf((1, 1)))
>>> rtc.append(abjad.rhythmtrees.RhythmTreeLeaf((2, 1)))
>>> rtc.append(abjad.rhythmtrees.RhythmTreeLeaf((2, 1)))

Use RTM format strings to view the structure of rhythm-tree containers:

>>> print(rtc.rtm_format)
(1 (1 2 2))
>>> print(rtc.pretty_rtm_format)
(1 (
    1
    2
    2))

Call rhythm-tree containers with a duration to make components:

>>> components = rtc(abjad.Duration(1, 1))
>>> voice = abjad.Voice(components)
>>> abjad.setting(voice[0]).Score.proportionalNotationDuration = "#1/12"
>>> abjad.show(voice)  

rtm_format

Gets RTM format of rhythm-tree container.

rtm_format

Gets RTM format of rhythm-tree container.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> rtc.rtm_format
'(1 ((1 (1 1)) (1 (1 1))))'
>>> rtc[0].rtm_format
'(1 (1 1))'
>>> rtc[0][0].rtm_format
'1'
class abjad.rhythmtrees.RhythmTreeLeaf(pair: tuple[int, int], *, is_unpitched: bool = False, name: str | None = None)[source]

Rhythm-tree leaf.

Pitched rhythm-tree leaves makes notes:

>>> rtl = abjad.rhythmtrees.RhythmTreeLeaf((5, 1), is_unpitched=False)
>>> components = rtl(abjad.Duration(1, 4))
>>> voice = abjad.Voice(components)
>>> abjad.setting(voice[0]).Score.proportionalNotationDuration = "#1/12"
>>> abjad.show(voice)  

Unpitched rhythm-tree leaves make rests:

>>> rtl = abjad.rhythmtrees.RhythmTreeLeaf((5, 1), is_unpitched=True)
>>> components = rtl(abjad.Duration(1, 4))
>>> voice = abjad.Voice(components)
>>> abjad.setting(voice[0]).Score.proportionalNotationDuration = "#1/12"
>>> abjad.show(voice)  

is_unpitched

Is true when rhythm-tree leaf is unpitched.

rtm_format

Gets RTM format of rhythm-tree leaf.

is_unpitched

Is true when rhythm-tree leaf is unpitched.

rtm_format

Gets RTM format of rhythm-tree leaf.

>>> abjad.rhythmtrees.RhythmTreeLeaf((5, 1), is_unpitched=False).rtm_format
'5'
>>> abjad.rhythmtrees.RhythmTreeLeaf((5, 1), is_unpitched=True).rtm_format
'-5'
class abjad.rhythmtrees.RhythmTreeNode(pair: tuple[int, int])[source]

Rhythm-tree node.

duration

Gets duration of rhythm-tree node.

pair

Gets pair of rhythm-tree node.

pretty_rtm_format

Gets pretty-printed RTM format of rhythm-tree node.

prolation

Gets prolation of rhythm-tree node.

prolations

Gets prolations of rhythm-tree node.

start_offset

Gets start offset of rhythm-tree node.

stop_offset

Gets stop offset of rhythm-tree node.

duration

Gets duration of rhythm-tree node.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> components = rtc(abjad.Duration(1, 1))
>>> voice = abjad.Voice(components)
>>> score = abjad.Score([voice])
>>> abjad.setting(score).proportionalNotationDuration = "#1/12"
>>> abjad.show(score)  
>>> rtc.duration
Duration(1, 1)
>>> rtc[1].duration
Duration(1, 2)
>>> rtc[1][1].duration
Duration(1, 4)
pair

Gets pair of rhythm-tree node.

>>> abjad.rhythmtrees.RhythmTreeLeaf((1, 1)).pair
(1, 1)
>>> abjad.rhythmtrees.RhythmTreeLeaf((2, 4)).pair
(2, 4)
pretty_rtm_format

Gets pretty-printed RTM format of rhythm-tree node.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> print(rtc.pretty_rtm_format)
(1 (
    (1 (
        1
        1))
    (1 (
        1
        1))))
>>> print(rtc[0].pretty_rtm_format)
(1 (
    1
    1))
>>> print(rtc[0][0].pretty_rtm_format)
1
prolation

Gets prolation of rhythm-tree node.

prolations

Gets prolations of rhythm-tree node.

start_offset

Gets start offset of rhythm-tree node.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> rtc.start_offset
Offset((0, 1))
>>> rtc[1].start_offset
Offset((1, 2))
>>> rtc[1][1].start_offset
Offset((3, 4))
stop_offset

Gets stop offset of rhythm-tree node.

>>> string = "(1 ((1 (1 1)) (1 (1 1))))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> rtc.stop_offset
Offset((1, 1))
>>> rtc[0].stop_offset
Offset((1, 2))
>>> rtc[0][0].stop_offset
Offset((1, 4))
class abjad.rhythmtrees.RhythmTreeParser(debug=False)[source]

Rhythm-tree parser.

Parses a microlanguage resembling Ircam’s Lisp-based RTM syntax. Generates a list of rhythm trees. Composers can manipulate rhythm trees and convert them to score components.

>>> parser = abjad.rhythmtrees.RhythmTreeParser()
>>> string = "(3 (1 (1 ((2 (1 1 1)) 2 2 1))))"
>>> rtc = parser(string)[0]
>>> print(rtc.pretty_rtm_format)
(3 (
    1
    (1 (
        (2 (
            1
            1
            1))
        2
        2
        1))))
>>> components = rtc(abjad.Duration(1, 2))
>>> abjad.tweak(components[0], r"\tweak text #tuplet-number::calc-fraction-text")
>>> voice = abjad.Voice(components)
>>> staff = abjad.Staff([voice])
>>> score = abjad.Score([staff])
>>> abjad.setting(score).proportionalNotationDuration = "#1/12"
>>> time_signature = abjad.TimeSignature((6, 4))
>>> leaf = abjad.select.leaf(voice, 0)
>>> abjad.attach(time_signature, leaf)
>>> abjad.show(score)  

lexer_rules_object

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

parser_rules_object

t_DURATION(t)

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

t_error(t)

t_newline(t)

n+

lexer_rules_object
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

parser_rules_object
t_DURATION(t)[source]

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

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

n+