The dom.lily module

Elements needed for LilyPond expressions.

class Music(*children, **attrs)[source]

Bases: Element

Base class for all elements that contain music.

is_sequential()[source]

Return True if child music nodes should be played sequentially.

This is used to compute the time position of a child: if this returns False, every child starts at the same position; if True, preceding nodes must be traversed in order to get the time position.

transform()[source]

Can return a Transform that adjusts the duration of child nodes.

By default, None is returned.

properties()[source]

Can return a Properties object with values to keep in the context of this node.

By default, None is returned.

Inside the Music.time_length() method you can access and modify the accumulated properties of the current Music node via the properties attribute of a TimeContext object

time_length(context, end=None)[source]

Return the length of this expression, using a TimeContext handler.

If end is given it is the index to stop just before.

class HandleDuration(*children, **attrs)[source]

Bases: Element

Mixin class to manipulate a Duration child via attributes.

The duration, scaling and duration_scaling properties make it easy to manipulate the respective child and grandchild nodes. Floating point values are automatically converted to Fractions, with a limit on the denominator, so a lazy note.scaling = 1/3 works properly.

duration_required = False

Whether the Duration child is required (e.g. skip)

duration_sets_previous = False

Whether this Duration is stored as the previous duration for Durables without Duration

property duration

Read or set the duration.

The duration is the head value of the Duration child. The value is None if there is no Duration child. Delete or set to None to remove the child. (In that case the scaling also disappears.)

property scaling

Read or set the scaling.

The scaling is the value of the DurationScaling child of the Duration child. The value is None if there is no Duration child and 1 if there is no DurationScaling grand child. Delete or set to None to remove the DurationScaling grand child.

Setting the property while there is no duration child raises a ValueError. Setting it to None or 1 removes the DurationScaling grand child.

property duration_scaling

Access duration and scaling in one go.

This value is either a two-tuple (duration, scaling) or None.

class Durable(*children, **attrs)[source]

Bases: HandleDuration, Music

Base class for a single musical object that takes time and can have a Duration child.

Inherited by: Note, Rest, Chord, Space, Skip, LyricText etc.

duration_required = False

Whether the Duration child is required (e.g. skip)

duration_sets_previous = True

Whether this Duration is stored as the previous duration for Durables without Duration

time_length(context, end=None)[source]

Return the length of this Durable, using a TimeContext handler.

For Durable, end is ignored.

class Pitchable(head, *children, **attrs)[source]

Bases: TextElement, Music

Base class for a note or pitched rest.

The head value is the pitch name. To read, write and understand the pitch name, use a PitchProcessor.

This class provides convenient properties to manipulate the Octave, Accidental and/or OctCheck child nodes.

Inherited by: Note, Pitch (a pitch that is no durable music), PitchedRest.

property octave

Read or set the octave.

The octave is an integer value, indicating how many '-s or ,-s are displayed after the pitch name. Automatically creates an Octave child if needed. Delete this attribute or set it to 0 to remove the octave.

property accidental

Read or set the accidental.

The accidental is None, "cautionary" or "forced". Automatically creates an Accidental child if needed. Delete this attribute or set it to None to remove the accidental.

property oct_check

Read or set the octave check.

The octave check is an integer value, or None, when no octave check is there. Automatically creates an OctCheck child if set. Delete this attribute or set it tot None to remove the octave check.

class Reference(*children, **attrs)[source]

Bases: Element

Base class for an Element that (potentially) refers to another node, possibly in another DOM tree.

This is used te get the value of a variable, e.g. for the IdentifierRef and the MarkupCommand element types. The get_value() method returns the value. Here is an example of how it works:

>>> from quickly.dom import read
>>> m = read.lily_document(r'''
... titled = "blurk"
...
... \header {
...   title = "Wilbert"
...   composer = \title
... }
... ''', True)
>>> m.dump()
<lily.Document (2 children)>
 ├╴<lily.Assignment titled (3 children)>
 │  ├╴<lily.Identifier (1 child)>
 │  │  ╰╴<lily.Symbol 'titled' [1:7]>
 │  ├╴<lily.EqualSign [8:9]>
 │  ╰╴<lily.String 'blurk' [10:17]>
 ╰╴<lily.Header (2 children) [19:70]>
    ├╴<lily.Assignment title (3 children)>
    │  ├╴<lily.Identifier (1 child)>
    │  │  ╰╴<lily.Symbol 'title' [31:36]>
    │  ├╴<lily.EqualSign [37:38]>
    │  ╰╴<lily.String 'Wilbert' [39:48]>
    ╰╴<lily.Assignment composer (3 children)>
       ├╴<lily.Identifier (1 child)>
       │  ╰╴<lily.Symbol 'composer' [51:59]>
       ├╴<lily.EqualSign [60:61]>
       ╰╴<lily.IdentifierRef 'title' [62:68]>
>>> n = m[1].composer
>>> n
<lily.IdentifierRef 'title' [62:68]>
>>> n.get_value()
<lily.String 'Wilbert' [39:48]>
>>> n.head = "titled"
>>> n.get_value()
<lily.String 'blurk' [10:17]>

The composer field in the header is set to the value of the title field. When requesting the value, the value of the title assignment is returned. When we change the name of the variable reference to titled, it finds the “blurk” value in the toplevel document.

A reference can also point to another file. A Scope is used to define the context of a file and the desired path to look for \include files. Here is an example. First we create two LilyPond files:

>>> with open('file_a.ly', 'w') as f:
...     f.write("music = { c d e f g }\n")
...
22
>>> with open('file_b.ly', 'w') as f:
...     f.write('\\include "file_a.ly"\n\n{ \\music }\n')
...
33

Then we load file_b.ly into a parce document, and we try to find the value of the \music variable:

>>> import quickly
>>> d = quickly.load('file_b.ly')
>>> print(d.text())
\include "file_a.ly"

{ \music }

>>> m = d.get_transform(True)
>>> m.dump()
<lily.Document (2 children)>
 ├╴<lily.Include 'file_a.ly' (1 child) [0:8]>
 │  ╰╴<lily.String 'file_a.ly' [9:20]>
 ╰╴<lily.MusicList (1 child) [22:32]>
    ╰╴<lily.IdentifierRef 'music' [24:30]>
>>> m[1][0]
<lily.IdentifierRef 'music' [24:30]>
>>> print(m[1][0].get_value())
None

We see that the returned value is None, meaning that the definition of music was not found in file_b.ly. Now, we create a Scope to find included files, and try it again:

>>> from quickly.dom.scope import Scope
>>> s = Scope(d)
>>> m[1][0].get_value(s)
<lily.MusicList (5 children) [8:21]>
>>> m[1][0].get_value(s).dump()
<lily.MusicList (5 children) [8:21]>
 ├╴<lily.Note 'c' [10:11]>
 ├╴<lily.Note 'd' [12:13]>
 ├╴<lily.Note 'e' [14:15]>
 ├╴<lily.Note 'f' [16:17]>
 ╰╴<lily.Note 'g' [18:19]>
>>> m[1][0].get_value_with_scope(s)
(<lily.MusicList (5 children) [8:21]>, <Scope 'file_a.ly'>)

The music in file_a.ly is found. The get_value_with_scope() method also returns the scope the definition was found in, which can be used to recursively resolve Reference nodes in the returned node.

get_value(scope=None, wait=True)[source]

Find the value this variable refers to.

Returns the value if found, and None otherwise. For the arguments, see get_value_with_scope().

get_value_with_scope(scope=None, wait=True)[source]

Find the value this variable refers to.

Searches for Assignments. If found, returns a two-tuple (value, scope). Otherwise None. The scope is the scope the value was found in.

The scope, if given, is used to resolve include files. If no scope is given, only searches the current DOM document; the returned scope is then always None.

If a scope is given, include commands are followed and wait determines whether to wait for ongoing transformations of external DOM documents. If wait is False, and a transformation is not yet finished, a value found in an included document will not be returned.

get_name()[source]

Implement to return the name the get_value() methods search for.

class HandleAssignments(*children, **attrs)[source]

Bases: Element

Mixin class to handle Assignment children in a convenient way.

find_assignment(name)[source]

Find the Assignment with the specified name.

get_variable(name)[source]

Convenience method to find the value of the named variable.

Finds an Assignment child that assigns a value to a Identifier with the specified name. Returns the Element node representing the value, or None if no assignment with that name exists.

When the node is a String or an Int, its head value is returned. If no assignment with the name can be found, None is returned.

For the name, see Identifier.set_name().

set_variable(name, value)[source]

Convenience method to add or replace a variable assignment.

If an Assignment exists with the named variable, replaces its node value; otherwise appends a new Assignment.

If the value is an Element node, it is used directly. If it is an integer, an Int element is created; if it is a string, a String element is created. (If such element was already in use, only the head value is changed.)

unset_variable(name)[source]

Convenience method to delete a variable assignment.

If an Assignment exists with the named variable, it is removed from its parent.

variables()[source]

Convenience method to return a list of the available variable names.

class Document(*children, **attrs)[source]

Bases: HandleAssignments, Document

A full LilyPond source document.

property version

The LilyPond version number, as a tuple of ints (may be empty).

class Number(head, *children, **attrs)[source]

Bases: TextElement

Base class for numeric values.

write_head()[source]

Return the textual output that represents our head value.

The default implementation just returns the head attribute, assuming it is text.

classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

class Int(head, *children, **attrs)[source]

Bases: Number

An integer number.

classmethod check_head(head)[source]

Returns whether the proposed head value is valid.

classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Fraction(head, *children, **attrs)[source]

Bases: Number

A fraction, like 1/2.

The head value is a two-tuple of ints (numerator, denominator).

fraction()[source]

Return the head value as a fractions.Fraction.

classmethod check_head(head)[source]

Returns whether the proposed head value is valid.

repr_head()[source]

Return a repr value for our head value.

classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

write_head()[source]

Return the textual output that represents our head value.

The default implementation just returns the head attribute, assuming it is text.

class Float(head, *children, **attrs)[source]

Bases: Number

A floating point number.

classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

classmethod check_head(head)[source]

Returns whether the proposed head value is valid.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Symbol(head, *children, **attrs)[source]

Bases: TextElement

A symbol (unquoted text piece).

class String(head, *children, **attrs)[source]

Bases: String

A quoted string.

class Scheme(head, *children, **attrs)[source]

Bases: TextElement

A Scheme expression in LilyPond.

A Scheme expression can start with $, #, $@ or #@. The latter two are rarely used; they unroll a list in the surrounding expression.

A Scheme expression starting with a dollar sign is directly executed by LilyPond when encountered in a source file, it is then ignored when it is no valid expression; an expression starting with a hash sign is evaluated later, when evalating the music expression.

space_before = ' '

whitespace before this element

space_after = ' '

whitespace after this element

classmethod check_head(head)[source]

Returns whether the proposed head value is valid.

class Spanner(head, *children, **attrs)[source]

Bases: MappingElement

Base class for spanner elements, that start or stop.

Specify "start" or "stop" to the constructor, and put the texts that are displayed for either in the spanner_start and spanner_stop attribute.

spanner_start = '<start>'
spanner_stop = '<stop>'
find_parallel(limit=0)[source]

Try to find the other end of this spanner. May return None.

Does not look outside of the current New or Assignment node. The limit can be used to further restrict the number of nodes searched, e.g. to prevent slowness in text editors that do not need to highlight items far offscreen.

For example:

>>> from quickly.dom import lily, read
>>> n = read.lily(r"{ c\=1( d e f g\=2) a\=1) }", True)
>>> n.dump()
<lily.MusicList (6 children) [0:27]>
 ├╴<lily.Note 'c' (1 child) [2:3]>
 │  ╰╴<lily.Articulations (1 child)>
 │     ╰╴<lily.SpannerId (2 children) [3:5]>
 │        ├╴<lily.Int 1 [5:6]>
 │        ╰╴<lily.Slur 'start' [6:7]>
 ├╴<lily.Note 'd' [8:9]>
 ├╴<lily.Note 'e' [10:11]>
 ├╴<lily.Note 'f' [12:13]>
 ├╴<lily.Note 'g' (1 child) [14:15]>
 │  ╰╴<lily.Articulations (1 child)>
 │     ╰╴<lily.SpannerId (2 children) [15:17]>
 │        ├╴<lily.Int 2 [17:18]>
 │        ╰╴<lily.Slur 'stop' [18:19]>
 ╰╴<lily.Note 'a' (1 child) [20:21]>
    ╰╴<lily.Articulations (1 child)>
       ╰╴<lily.SpannerId (2 children) [21:23]>
          ├╴<lily.Int 1 [23:24]>
          ╰╴<lily.Slur 'stop' [24:25]>
>>> slur = n.find_descendant(6)
>>> slur
<lily.Slur 'start' [6:7]>
>>> slur.find_parallel()
<lily.Slur 'stop' [24:25]>
class Block(*children, **attrs)[source]

Bases: HandleAssignments, BlockElement

Base class for a block, e.g. score, paper, etc.

Newlines are placed by default between all child nodes. There are convenience methods to access variables inside a block.

space_before = '\n'

whitespace before this element

space_after = '\n'

whitespace after this element

space_after_head = '\n'

whitespace before first child

space_before_tail = '\n'

whitespace before tail

space_between = '\n'

whitespace between children

head = '<fill in> {'
tail = '}'
class Book(*children, **attrs)[source]

Bases: Block

A book { } block.

head = '\\book {'
class BookPart(*children, **attrs)[source]

Bases: Block

A bookpart { } block.

head = '\\bookpart {'
class Score(*children, **attrs)[source]

Bases: Block

A score { } block.

head = '\\score {'
class Header(*children, **attrs)[source]

Bases: Block

A header { } block.

The standard LilyPond header variables are accessible as attributes. When setting a value to a simple string, a String element is created automatically. When reading a value that is a single String element, the string contents is returned.

For example:

>>> from quickly.dom import lily
>>> h = lily.Header()
>>> h.title = "My title"
>>> h.composer = "Wilbert Berendsen"
>>> h.tagline = False
>>> print(h.write_indented())
\header {
  title = "My title"
  composer = "Wilbert Berendsen"
  tagline = ##f
}

>>> h.dump()
<lily.Header (2 children)>
 ├╴<lily.Assignment title (3 children)>
 │  ├╴<lily.Identifier (1 child)>
 │  │  ╰╴<lily.Symbol 'title'>
 │  ├╴<lily.EqualSign>
 │  ╰╴<lily.String 'My title'>
 ╰╴<lily.Assignment composer (3 children)>
    ├╴<lily.Identifier (1 child)>
    │  ╰╴<lily.Symbol 'composer'>
    ├╴<lily.EqualSign>
    ╰╴<lily.String 'Wilbert Berendsen'>

Header variables can also be specified as keyword arguments on construction (just like any attribute):

>>> h = lily.Header(composer="Johann Sebastian Bach")

When a variable is not present, None is returned. Other variable names can be set using set_variable() and read using get_variable(). The method variables() returns a list with the names of all assignments.

Deleting a variable can be done in two ways:

>>> h.title = None
>>> del h.title         # same as setting to None
head = '\\header {'
dedication

The dedication.

title

The title.

subtitle

The subtitle.

subsubtitle

The subsubtitle.

instrument

The instrument (shown on all pages).

poet

The poet.

composer

The composer.

meter

The meter (shown left).

arranger

The arranger (shown right).

tagline

The tagline (at the bottom of the last page).

copyright

The copyright (at the bottom of the first page).

class Paper(*children, **attrs)[source]

Bases: Block

A paper { } block.

The most used paper variables can be set using properties, which auto-convert string, int and boolean values. Where LilyPond uses hyphens in paper variables, these properties use underscores.

head = '\\paper {'
paper_height

Paper height.

top_margin

Top margin.

bottom_margin

Bottom margin.

ragged_bottom

Whether to have a ragged bottom (bool).

ragged_last_bottom

Whether to have a ragged bottom on the last page (bool).

markup_system_spacing

Spacing between markup and first system.

score_markup_spacing

Spacing between score and markup.

score_system_spacing

Spacing between two adjacent scores.

system_system_spacing

Spacing between systems of one score.

markup_markup_spacing

Spacing between two markups.

last_bottom_spacing

Spacing between the last system or markup and the page bottom.

top_system_spacing

Spacing between page top and first system.

top_markup_spacing

Spacing between page top and first markup.

paper_width

Paper width.

line_width

Line witdh.

left_margin

Left margin.

right_margin

Right margin.

check_consistency

Check whether all width settings fit.

ragged_right

Whether to fill out the systems to the right (bool).

ragged_last

Whether to fill out the last system to the right (bool).

two_sided

Whether to have mirrored margins for left and right pages.

inner_margin

Margin at binding side.

outer_margin

Margin at outer side.

binding_offset

Extra offset for inner-margin.

horizontal_shift

Amount al systems and markups are shifted to the right.

indent

Indent distance for the first system.

short_indent

Indent distance for all other systems.

max_systems_per_page

The maximum number of systems on a page.

min_systems_per_page

The minimum number of systems on a page.

systems_per_page

How many systems to put on a page.

system_count

The number of systems to create.

page_breaking

Page-breaking algorithm to use.

page_breaking_system_system_spacing

Specially adjust spacing for page breaker.

page_count

The number of pages to be used.

blank_page_penalty

Penalty for having a blank page.

blank_last_page_penalty

Penalty for ending on a left page.

blank_after_score_page_penalty

Penalty for having a blank page before a score.

auto_first_page_number

Automatically choose whether to start with even or odd page number.

first_page_number

The page number for the first page.

print_first_page_number

Print the page number on the first page (bool).

print_page_number

Print page numbers anyway (bool).

page_spacing_weight

Relative importance of page and line spacing.

print_all_headers

Whether to print all headers in each score (bool).

system_separator_markup

Markup to use between systems.

class Layout(*children, **attrs)[source]

Bases: Block

A layout { } block.

The most used layout variables can be set using properties, which auto-convert string, int and boolean values. Where LilyPond uses hyphens in paper variables, these properties use underscores.

head = '\\layout {'
line_width

Line witdh.

ragged_right

Whether to fill out the systems to the right (bool).

ragged_last

Whether to fill out the last system to the right (bool).

indent

Indent distance for the first system.

short_indent

Indent distance for all other systems.

system_count

The number of systems to create.

class Midi(*children, **attrs)[source]

Bases: Block

A midi { } block.

head = '\\midi {'
class With(*children, **attrs)[source]

Bases: Block

A with { } block.

head = '\\with {'
space_before = ' '

whitespace before this element

space_after = ' '

whitespace after this element

class LayoutContext(*children, **attrs)[source]

Bases: Block

A context { } block within layout or midi.

head = '\\context {'
class EqualSign(*children, **attrs)[source]

Bases: HeadElement

An equal sign (=).

head = '='
space_before = ' '

whitespace before this element

space_after = ' '

whitespace after this element

class Separator(head, *children, **attrs)[source]

Bases: TextElement

A separator.

class List(*children, **attrs)[source]

Bases: Element

A list consisting of String, Scheme, Int or Symbol elements.

Separated by Separator elements; may also contain Comment nodes.

get_list()[source]

Convenience method to get a tuples with the contents of the list.

Comment and Scheme nodes are ignored; for Symbol and String elements Python strings are returned, and for Int elements integer values.

set_list(iterable)[source]

Replaces the contents of this List with nodes converted from the iterable.

Strings are converted to Symbol if possible, else String, and integers to Int nodes.

class Assignment(*children, **attrs)[source]

Bases: Element

A variable = value construct.

The first node is a Identifier element, then an EqualSign, and then the value.

space_before = '\n'

whitespace before this element

space_after = '\n'

whitespace after this element

classmethod with_name(name, node)[source]

Convenience constructor to create a complete Assignment.

Automatically creates a Identifier child node for the name, an EqualSign node, and appends the specified node as the value of the assignment. For the name, see Identifier.set_name().

repr_head()[source]

If available, show the name of our identifier.

get_name()[source]

Return the name of our identifier as a string or tuple.

get_value()[source]

Return the value after the equalsign.

class Identifier(*children, **attrs)[source]

Bases: List

A variable name, the first node is always a Symbol or String.

Further contains Symbol, String, Separator, Int or Scheme. This element is created when a List is encountered in an assignment by the transformer (see handle_assignments()).

classmethod with_name(name)[source]

Create a Identifier with specified name.

get_name()[source]

Convenience method to get the name of this variable.

This can be a plain string or a tuple. It is a tuple when the variable name consists of multiple parts, separated by dots. The first item in the tuple is always a string, but the other items might also be numbers.

set_name(name)[source]

Convenience method to set the name of this variable.

In most cases the name is an alphanumeric identifier, but it can be any string (in that case it is automatically quoted) or a tuple of names, strings and even numbers. The first item in the tuple always must be a name or string. An alphanumeric string is turned into a Symbol element, a string containing “illegal” characters into a String element, and an integer value into a Int element.

class IdentifierRef(head, *children, **attrs)[source]

Bases: BackslashCommand, Reference

A \variable name.

The first symbol part is in the head of this element. Additional nodes can be Symbol, String, Separator, Int or Scheme.

For the \"name", construct, head is the empty string, and the first child is a String. Otherwise, if there are child nodes, the first child is a Separator.

For the constructor, the backslash is not needed:

>>> from quickly.dom.lily import *
>>> var = IdentifierRef('music')
>>> var.write()
'\\music'
>>> var = IdentifierRef.with_name(('music', 1))
>>> var.write()
'\\music.1'
classmethod with_name(name)[source]

Convenience method to create a IdentifierRef with specified name.

This is especially useful with complicated names that are not a simple symbol.

get_name()[source]

Convenience method to get the name of this variable.

The backslash is not returned. The name can be a plain string or a tuple. It is a tuple when the variable name consists of multiple parts, separated by dots. The first item in the tuple is always a string, but the other items might also be numbers.

set_name(name)[source]

Convenience method to set the name of this variable.

In most cases the name is an alphanumeric identifier, but it can be any string (in that case it is automatically quoted) or a tuple of names, strings and even numbers. The first item in the tuple always must be a name or string. An alphanumeric string is turned into a Symbol element, a string containing “illegal” characters into a String element, and an integer value into a Int element.

A backslash need not to be prepended.

class MusicFunction(head, *children, **attrs)[source]

Bases: BackslashCommand, Music

A generic music function with a backslash, like \stemUp

To be used if there is no special Element type for the music function. When manually constructing this element, the initial backslash need not to be given. Example:

>>> from quickly.dom.lily import MusicFunction
>>> MusicFunction('stemUp').write()
'\\stemUp'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Context(*children, **attrs)[source]

Bases: HeadElement, Music

\context ....

space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

head = '\\context'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class New(*children, **attrs)[source]

Bases: Context

\new ....

head = '\\new'
class Change(*children, **attrs)[source]

Bases: HeadElement, Music

\change ....

space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

head = '\\change'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class AddQuote(*children, **attrs)[source]

Bases: HeadElement

An \addQuote command, at toplevel.

space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

head = '\\addQuote'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class QuoteDuring(*children, **attrs)[source]

Bases: HeadElement, Music

A \quoteDuring command.

space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

head = '\\quoteDuring'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class ApplyContext(*children, **attrs)[source]

Bases: HeadElement

The \applyContext command.

space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

head = '\\applyContext'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class ApplyMusic(*children, **attrs)[source]

Bases: HeadElement

The \applyMusic function.

space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

head = '\\applyMusic'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class ApplyOutput(*children, **attrs)[source]

Bases: HeadElement

The \applyOutput command.

space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

head = '\\applyOutput'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Relative(*children, **attrs)[source]

Bases: HeadElement, Music

Relative music.

head = '\\relative'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

add_argument(node)[source]

Reimplemented to turn an added Note argument into a Pitch.

class Absolute(*children, **attrs)[source]

Bases: HeadElement, Music

Absolute music.

head = '\\absolute'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Fixed(*children, **attrs)[source]

Bases: HeadElement, Music

Fixed music.

head = '\\fixed'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

add_argument(node)[source]

Reimplemented to turn an added Note argument into a Pitch.

class Transpose(*children, **attrs)[source]

Bases: HeadElement, Music

Transposed music.

head = '\\transpose'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

add_argument(node)[source]

Reimplemented to turn 2 added Note arguments into Pitch arguments.

class Repeat(*children, **attrs)[source]

Bases: HeadElement, Music

Repeated music.

head = '\\repeat'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Alternative(*children, **attrs)[source]

Bases: HeadElement, Music

Alternative music for repeats.

head = '\\alternative'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class UnfoldRepeats(*children, **attrs)[source]

Bases: HeadElement, Music

The \unfoldRepeats command.

space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

head = '\\unfoldRepeats'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Unfolded(*children, **attrs)[source]

Bases: HeadElement, Music

The \unfolded command.

head = '\\unfolded'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Volta(*children, **attrs)[source]

Bases: HeadElement, Music

The \volta command.

head = '\\volta'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Transposition(*children, **attrs)[source]

Bases: HeadElement, Music

A \tranposition command.

head = '\\transposition'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

add_argument(node)[source]

Reimplemented to turn an added Note argument into a Pitch.

class Ottava(*children, **attrs)[source]

Bases: _ConvertUnpitchedToInt, HeadElement, Music

An \ottava command.

space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

head = '\\ottava'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class MusicList(*children, **attrs)[source]

Bases: BlockElement, Music

A list of music items between {}.

space_after_head = ' '

whitespace before first child

space_before_tail = ' '

whitespace before tail

space_between = ' '

whitespace between children

head = '{'
tail = '}'
is_sequential()[source]

Return False when the parent is a Simultaneous command, True otherwise.

indent_align_indices()[source]

How to align child nodes if on the same line as an indenting char.

class SimultaneousMusicList(*children, **attrs)[source]

Bases: MusicList

A list of music items between <<>>.

head = '<<'
tail = '>>'
is_sequential()[source]

Return always False.

class Sequential(*children, **attrs)[source]

Bases: HeadElement, Music

The \sequential command, has one MusicList child.

head = '\\sequential'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Simultaneous(*children, **attrs)[source]

Bases: HeadElement, Music

The \simultaneous command, has one MusicList child.

head = '\\simultaneous'
space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class InputMode(*children, **attrs)[source]

Bases: Music

Base class for any input mode, such as \figures or \lyricmode.

The head value is the command without backslash prepended.

space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class LyricMode(head, *children, **attrs)[source]

Bases: BackslashCommand, InputMode

\lyricmode, \lyrics or \lyricsto.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class ChordMode(head, *children, **attrs)[source]

Bases: BackslashCommand, InputMode

\chordmode or \chords.

class DrumMode(head, *children, **attrs)[source]

Bases: BackslashCommand, InputMode

\drummode or \drums.

class NoteMode(*children, **attrs)[source]

Bases: HeadElement, InputMode

\notemode.

head = '\\notemode'
class FigureMode(head, *children, **attrs)[source]

Bases: BackslashCommand, InputMode

\figuremode or \figures.

class Chord(*children, **attrs)[source]

Bases: Durable

A chord. Must have a ChordBody element.

time_length(context, end=None)[source]

Return the length of this Durable, using a TimeContext handler.

For Chord, end is ignored; returns 0 if the chord is empty, in accordance with LilyPond’s behaviour.

child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

class ChordBody(*children, **attrs)[source]

Bases: BlockElement

The body of a chord <>.

Always the child of a Chord, which can have a duration and articulations. Contains Note elements.

space_between = ' '

whitespace between children

head = '<'
tail = '>'
indent_align_indices()[source]

How to align child nodes if on the same line as an indenting char.

class Note(head, *children, **attrs)[source]

Bases: Pitchable, Durable

A musical note.

child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

to_pitch()[source]

Convenience function to create a Pitch node from this note node.

This is used when this Note is added to a command where the note has not a musical meaning, but just a pitch is intended, e.g. \key or \transpose, etc.

class Pitch(head, *children, **attrs)[source]

Bases: Pitchable

A pitch name.

This is used as pitch argument for \transpose, \tranposition, \fixed, \relative, \key etc. The difference with Note is that a Pitch is not a Durable and can’t have a duration or articulations.

Note

Do not confuse this Pitch element type with the musical Pitch class from the pitch module!

child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

class Unpitched(*children, **attrs)[source]

Bases: Durable

An unpitched note, always has a Duration child.

duration_required = True

always needs a duration

child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

class RestType(*children, **attrs)[source]

Bases: Durable

Base class for Rest, PitchedRest and MultiMeasureRest.

child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

class Rest(*children, **attrs)[source]

Bases: HeadElement, RestType

head = 'r'

A normal rest (r).

class MultiMeasureRest(*children, **attrs)[source]

Bases: Rest

head = 'R'

A multi-measure rest (R).

class PitchedRest(head, *children, **attrs)[source]

Bases: Pitchable, RestType

A pitched rest.

This rest has a pitchname but also a RestModifier child, e.g. c\rest. It is a normal rest, but vertically positioned using a pitch name, which is the head value. This element can also have an Octave or OctCheck.

child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

class Space(*children, **attrs)[source]

Bases: HeadElement, Durable

A space (s).

head = 's'
child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

class Skip(*children, **attrs)[source]

Bases: HeadElement, Durable

A \skip.

For LilyPond version upto and including 2.22, must have a Duration child. For LilyPond version from 2.23.6, may have a Music argument instead, which then defines the length of the skip.

With a duration, LilyPond creates a SkipMusic event; with a music argument, LilyPond creates a SkippedMusic construct with music that’s just not printed and does not create outputs, but whose length is computed precisely.

We handle both; the duration_required means here that it may not be removed if it’s there. If there is no direct Duration child, the Skip is not to be regarded as a regular Durable, but rather as a music function.

head = '\\skip'
space_after_head = ' '

whitespace before first child

duration_required = True

always needs a duration

duration_sets_previous = False

the “previous” duration is not changed by skip

time_length(context, end=None)[source]

Return the length of this Durable, using a TimeContext handler.

Reimplemented to handle the case where \skip has a music argument instead of a Duration argument.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

class After(*children, **attrs)[source]

Bases: HeadElement, HandleDuration, Music

An \after. Must have a Duration child and an event.

head = '\\after'
class Q(*children, **attrs)[source]

Bases: HeadElement, Durable

A q, repeating the previous chord.

The repeated chord always has the same absolute pitch, Octave childs are not possible. LilyPond signals a warning if there is no previous chord in the current music expression, and the q becomes a skip.

Articulations attached to the repeated chord or to its individual notes are not copied, but internal tweaks to the noteheads are.

head = 'q'
child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

class Drum(head, *children, **attrs)[source]

Bases: TextElement, Durable

A drum note.

child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

class Accidental(head, *children, **attrs)[source]

Bases: MappingElement

The accidental after a note.

Can be cautionary or forced.

mapping = {'!': 'forced', '?': 'cautionary'}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class Octave(head, *children, **attrs)[source]

Bases: TextElement

The octave after a note.

The head value is the number of ' (if positive) or the number of ,, if negative.

classmethod read_head(origin)[source]

Read the octave from the token.

write_head()[source]

Write the octave, an empty string for octave 0.

class OctCheck(head, *children, **attrs)[source]

Bases: TextElement

The octavecheck after a note, e.g. like =,.

The head value is the number of ' (if positive) or the number of ,, if negative.

classmethod read_head(origin)[source]

Read the octave from the token.

write_head()[source]

Write the octave, an empty string for octave 0.

class OctaveCheck(*children, **attrs)[source]

Bases: HeadElement

The \octaveCheck command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\octaveCheck'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

add_argument(node)[source]

Reimplemented to turn an added Note argument into a Pitch.

class Duration(head, *children, **attrs)[source]

Bases: TextElement

A duration after a note.

To the constructor the duration is specified using a numerical value, which can be a Fraction. A whole note is 1, a breve 2, etc; a quarter note or crotchet 1/4, etc.

The value must be expressable (is that English?:-) in a length value and zero or more dots. Examples:

>>> from quickly.dom.lily import Duration
>>> Duration(2).write()
'\breve'
>>> Duration(3/2).write()
'1.'
>>> Duration(7/4).write()
'1..'
>>> Duration(7/16).write()
'4..'
classmethod from_string(text)[source]

Convenience constructor to make a Duration from a string.

Examples:

>>> lily.Duration.from_string('4')
<lily.Duration Fraction(1, 4)>
>>> lily.Duration.from_string('2.')
<lily.Duration Fraction(3, 4)>
>>> d = lily.Duration.from_string('1*1/3')
>>> d.dump()
<lily.Duration Fraction(1, 1) (1 child)>
 ╰╴<lily.DurationScaling Fraction(1, 3)>
>>> d.duration()
Fraction(1, 3)
classmethod from_duration(duration, scaling=1)[source]

Convenience constructor to make a Duration from a duration and scaling value.

An example:

>>> from quickly.dom.lily import Duration
>>> d = Duration.from_duration(1/4)
>>> d.write()
'4'
>>> d = Duration.from_duration(1/4, 1/3)
>>> d.write()
'4*1/3'
duration()[source]

Return the two-tuple(duration, scaling).

The duration is simply our head value, the scaling is computed from a DurationScaling child if present, or 1.

classmethod read_head(origin)[source]

Read the duration value from the origin tokens.

write_head()[source]

Write back the duration fraction to a string like 4.

class DurationScaling(head, *children, **attrs)[source]

Bases: TextElement

An optional scaling after a Duration.

E.g. *1/2. May be read from multiple *n/m parts, but always outputs a single *n/d value, or *n when the denominator is 1. To the constructor any numerical value may be given, but the value is always represented as a fraction (omitting the denominator if 1).

classmethod read_head(origin)[source]

Read the scaling from the origin tokens.

write_head()[source]

Write back the scaling to a string like *1/2.

class LyricItem(*children, **attrs)[source]

Bases: Durable

Wrap a Scheme, String, Symbol or Markup in lyricmode.

If it has no Scherm, String, Symbol or Markup child, a duration is required.

child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

property duration_required

Duration is required if no visible child.

class LyricText(head, *children, **attrs)[source]

Bases: TextElement, Durable

A word in lyric mode.

child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

class LyricExtender(*children, **attrs)[source]

Bases: HeadElement

A lyric extender __.

head = '__'
class LyricHyphen(*children, **attrs)[source]

Bases: HeadElement

A lyric hyphen --.

head = '--'
class LyricSkip(*children, **attrs)[source]

Bases: HeadElement, Durable

A lyric skip _.

head = '_'
child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

class ChordModifiers(*children, **attrs)[source]

Bases: Element

A list of elements attachted to a note in chord mode.

class AddSteps(*children, **attrs)[source]

Bases: HeadElement

Contains the steps to be added in chordmode.

head = ':'
class RemoveSteps(*children, **attrs)[source]

Bases: HeadElement

Contains the steps to be added in chordmode.

head = '^'
class Qualifier(head, *children, **attrs)[source]

Bases: TextElement

A qualifier like maj in chord mode.

class Inversion(*children, **attrs)[source]

Bases: HeadElement

Inversion (/) in chordmode.

head = '/'
class AddInversion(*children, **attrs)[source]

Bases: HeadElement

Inversion adding the bass note (/+) in chordmode.

head = '/+'
class Step(head, *children, **attrs)[source]

Bases: Int

Contains the steps to be added in chordmode.

class Alteration(head, *children, **attrs)[source]

Bases: TextElement

The alteration of a step (+ or -).

class Articulations(*children, **attrs)[source]

Bases: Element

A list of elements that are attached to a note or chord.

class Direction(head, *children, **attrs)[source]

Bases: MappingElement

A -, _ or ^.

The value is -1 for _, 0 for - or 1 for ^

mapping = {'-': 0, '^': 1, '_': -1}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class Articulation(head, *children, **attrs)[source]

Bases: TextElement

An ArticulationEvent.

class Modifier(head, *children, **attrs)[source]

Bases: BackslashCommand

A generic modifier that is not an articulation but added to the Articulations after a note.

For example \noBeam.

The backslash is not in the head value.

class RestModifier(*children, **attrs)[source]

Bases: HeadElement

A \rest command after a note.

Is a child of a Rest element that has a pitch name and possibly octave information instead of plain “r”.

head = '\\rest'
class Fingering(head, *children, **attrs)[source]

Bases: TextElement

A FingeringEvent.

class Dynamic(head, *children, **attrs)[source]

Bases: BackslashCommand

A dynamic symbol, like pp.

class Slur(head, *children, **attrs)[source]

Bases: Spanner

A slur ( or ).

spanner_start = '('
spanner_stop = ')'
mapping = {'(': 'start', ')': 'stop'}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class PhrasingSlur(head, *children, **attrs)[source]

Bases: Spanner

A phrasing slur \( or \).

spanner_start = '\\('
spanner_stop = '\\)'
mapping = {'\\(': 'start', '\\)': 'stop'}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class Tie(*children, **attrs)[source]

Bases: HeadElement

A tie.

head = '~'
class LaissezVibrer(*children, **attrs)[source]

Bases: Tie

A \laissezVibrer tie.

head = '\\laissezVibrer'
class RepeatTie(*children, **attrs)[source]

Bases: Tie

A \repeatTie tie.

head = '\\repeatTie'
class Beam(head, *children, **attrs)[source]

Bases: Spanner

A beam [ or ].

spanner_start = '['
spanner_stop = ']'
mapping = {'[': 'start', ']': 'stop'}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class Ligature(head, *children, **attrs)[source]

Bases: Spanner

A ligature \[ or \].

spanner_start = '\\['
spanner_stop = '\\]'
mapping = {'\\[': 'start', '\\]': 'stop'}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class TextSpanner(head, *children, **attrs)[source]

Bases: Spanner

A text spanner.

spanner_start = '\\startTextSpan'
spanner_stop = '\\stopTextSpan'
mapping = {'\\startTextSpan': 'start', '\\stopTextSpan': 'stop'}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class TrillSpanner(head, *children, **attrs)[source]

Bases: Spanner

A trill spanner.

spanner_start = '\\startTrillSpan'
spanner_stop = '\\stopTrillSpan'
mapping = {'\\startTrillSpan': 'start', '\\stopTrillSpan': 'stop'}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class Melisma(head, *children, **attrs)[source]

Bases: Spanner

A melisma spanner.

spanner_start = '\\melisma'
spanner_stop = '\\melismaEnd'
mapping = {'\\melisma': 'start', '\\melismaEnd': 'stop'}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class Arpeggio(*children, **attrs)[source]

Bases: HeadElement, Music

An \arpeggio.

head = '\\arpeggio'
class Glissando(*children, **attrs)[source]

Bases: HeadElement, Music

A \glissando.

head = '\\glissando'
class Bar(*children, **attrs)[source]

Bases: HeadElement, Music

A \bar. Has a String child.

space_after_head = ' '

whitespace before first child

head = '\\bar'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Breathe(*children, **attrs)[source]

Bases: HeadElement, Music

A \breathe.

head = '\\breathe'
class Break(head, *children, **attrs)[source]

Bases: ToggleElement

A \break or \noBreak.

toggle_on = '\\break'
toggle_off = '\\noBreak'
mapping = {'\\break': True, '\\noBreak': False}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class PageBreak(head, *children, **attrs)[source]

Bases: ToggleElement

A \pageBreak or \noPageBreak.

toggle_on = '\\pageBreak'
toggle_off = '\\noPageBreak'
mapping = {'\\noPageBreak': False, '\\pageBreak': True}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class PageTurn(head, *children, **attrs)[source]

Bases: MappingElement

A \pageTurn, \allowPageTurn or \noPageTurn.

mapping = {'\\allowPageTurn': 'allow', '\\noPageTurn': 'no', '\\pageTurn': 'yes'}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class InStaffSegno(*children, **attrs)[source]

Bases: HeadElement, Music

An \inStaffSegno command.

head = '\\inStaffSegno'
class PipeSymbol(*children, **attrs)[source]

Bases: HeadElement

A PipeSymbol, most times used as bar check.

head = '|'
class VoiceSeparator(*children, **attrs)[source]

Bases: HeadElement

A voice separator.

head = '\\\\'
class Label(*children, **attrs)[source]

Bases: HeadElement, Music

A \label command. Has one scheme expression child.

head = '\\label'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Mark(*children, **attrs)[source]

Bases: HeadElement, Music

A \mark command. Has one child.

head = '\\mark'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Default(*children, **attrs)[source]

Bases: HeadElement

The \default mark argument.

head = '\\default'
class Tempo(*children, **attrs)[source]

Bases: _ConvertUnpitchedToDuration, HandleDuration, HeadElement, Music

A \tempo command.

Can have text (symbol, string, markup) child and/or duration, EqualSign and numeric value childs.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\tempo'
child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class SpannerId(*children, **attrs)[source]

Bases: HeadElement

A spanner id (\=).

The first child is the id (Int, Symbol, String or Scheme). The second child the attached slur, phrasing slur or other object. (LilyPond only supports slurs).

head = '\\='
class PesOrFlexa(*children, **attrs)[source]

Bases: HeadElement

A pes-or-flexa event (\~).

head = '\\~'
class Tweak(*children, **attrs)[source]

Bases: HeadElement

A \tweak command.

On the music level, this node has two children, a Symbol and an argument. As an event after a note, this node has three children, the symbol, the argument and the object to tweak.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

space_after = ' '

whitespace after this element

head = '\\tweak'
class Tremolo(*children, **attrs)[source]

Bases: HeadElement

A Tremolo (:) with an optional Duration child.

head = ':'
class Mode(head, *children, **attrs)[source]

Bases: BackslashCommand

The mode subcommand of the \key statement.

class Key(*children, **attrs)[source]

Bases: HeadElement, Music

A key statement.

Must have a Pitch and a (Mode, IdentifierRef or Scheme) child.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\key'
key_signature(processor, scope=None, wait=True)[source]

Return a KeySignature object for this key signature.

The processor is a PitchProcessor, which interprets the pitch language. scope and wait help (when the mode argument is a variable) finding its value in another file.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

add_argument(node)[source]

Reimplemented to turn an added Note argument into a Pitch.

class Clef(*children, **attrs)[source]

Bases: HeadElement, Music

A \clef statement.

Must have a Symbol or String child indicating the clef type.

space_after_head = ' '

whitespace before first child

head = '\\clef'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Time(*children, **attrs)[source]

Bases: HeadElement, Music

A \time statement.

Has an optional List child and a Fraction child.

space_after_head = ' '

whitespace before first child

head = '\\time'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Partial(*children, **attrs)[source]

Bases: _ConvertUnpitchedToDuration, HandleDuration, HeadElement, Music

A \partial statement.

Has a Duration child.

space_after_head = ' '

whitespace before first child

head = '\\partial'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Times(*children, **attrs)[source]

Bases: HeadElement, Music

A \times statement.

Has a Fraction child and a Music child. The \times command is not documented anymore in LilyPond, but also not deprecated. Using \tuplet is recommended.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\times'
transform()[source]

Return a transform to scale durations of child nodes.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Tuplet(*children, **attrs)[source]

Bases: _ConvertUnpitchedToDuration, HandleDuration, HeadElement, Music

A \tuplet statement.

Has a Fraction child, an optional Duration child and a Music child.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\tuplet'
transform()[source]

Return a transform to scale durations of child nodes.

child_order()[source]

Return an iterable of tuples with element types.

This is almost the same as signatures() but used when a child node is inserted using add().

By default an empty iterable is returned.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class ScaleDurations(*children, **attrs)[source]

Bases: _ConvertUnpitchedToInt, HeadElement, Music

A \scaleDurations command.

Has a Fraction child and a Music child.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\scaleDurations'
transform()[source]

Return a transform to scale durations of child nodes.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class ShiftDurations(*children, **attrs)[source]

Bases: _ConvertUnpitchedToInt, HeadElement, Music

A \shiftDurations command.

Has two Scheme children and a Music child.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\shiftDurations'
transform()[source]

Return a transform to scale durations of child nodes.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Grace(*children, **attrs)[source]

Bases: HeadElement, Music

A \grace command.

Has a Music child.

space_after_head = ' '

whitespace before first child

head = '\\grace'
transform()[source]

Return a transform to scale durations of child nodes to 0.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Acciaccatura(*children, **attrs)[source]

Bases: Grace

An \acciaccatura command.

Has a Music child.

head = '\\acciaccatura'
class Appoggiatura(*children, **attrs)[source]

Bases: Grace

An \appoggiatura command.

Has a Music child.

head = '\\appoggiatura'
class SlashedGrace(*children, **attrs)[source]

Bases: Grace

A \slashedGrace command.

Has a Music child.

head = '\\slashedGrace'
class AfterGrace(*children, **attrs)[source]

Bases: HeadElement, Music

An \afterGrace command.

Has an optional Fraction and two Music children. The second music expression is the grace music and has length 0, the fraction is multiplied with the duration of the first music expression and determines the moment the grace music is displayed.

The default fraction (if not specified) is in the toplevel afterGraceFraction variable or 3/4.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\afterGrace'
time_length(context, end=None)[source]

Return the length of this expression, using a TimeContext handler.

Reimplemented to skip the second child music expression.

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class PartCombine(*children, **attrs)[source]

Bases: HeadElement, Music

The \partcombine command, with two Music arguments.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\partcombine'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class MultilineComment(head, *children, **attrs)[source]

Bases: MultilineComment

A multiline comment between %{ and %}.

classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

write_head()[source]

Return the textual output that represents our head value.

The default implementation just returns the head attribute, assuming it is text.

class SinglelineComment(head, *children, **attrs)[source]

Bases: SinglelineComment

A singleline comment after %.

space_after = '\n'

whitespace after this element

classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

write_head()[source]

Return the textual output that represents our head value.

The default implementation just returns the head attribute, assuming it is text.

class Markup(head, *children, **attrs)[source]

Bases: BackslashCommand

A \markup, \markuplines or \markuplist expression.

When manually constructing a Markup, the backslash is not needed.

space_before = ''

whitespace before this element

space_after = ' '

whitespace after this element

space_between = ' '

whitespace between children

space_after_head = ' '

whitespace before first child

class MarkupWord(head, *children, **attrs)[source]

Bases: TextElement

A word in markup mode.

space_before = ' '

whitespace before this element

space_after = ' '

whitespace after this element

class MarkupList(*children, **attrs)[source]

Bases: BlockElement

A bracketed markup expression, like {}.

space_after_head = ' '

whitespace before first child

space_before_tail = ' '

whitespace before tail

space_between = ' '

whitespace between children

head = '{'
tail = '}'
indent_align_indices()[source]

How to align child nodes if on the same line as an indenting char.

class MarkupCommand(head, *children, **attrs)[source]

Bases: BackslashCommand, Reference

A markup command, like \bold <arg>.

When manually constructing a MarkupCommand, the backslash is not needed.

space_after_head = ' '

whitespace before first child

space_before_tail = ' '

whitespace before tail

space_between = ' '

whitespace between children

get_name()[source]

The name of the markup command. This is used when looking up the definition of a custom markup command.

class MarkupScore(*children, **attrs)[source]

Bases: Score

A \score in Markup.

space_after_head = ' '

whitespace before first child

space_before_tail = ' '

whitespace before tail

space_between = ' '

whitespace between children

class MarkupScoreLines(*children, **attrs)[source]

Bases: MarkupScore

A \score-lines in Markup.

head = '\\score-lines {'
class Figure(*children, **attrs)[source]

Bases: Music

A bass figure in figure mode.

Always has one FigureBody child, which contains the numbers etc. Can also have a duration child.

class FigureBody(*children, **attrs)[source]

Bases: BlockElement

One <> figure “chord” in figuremode.

Always the child of a Figure element, which can have a duration.

space_between = ' '

whitespace between children

head = '<'
tail = '>'
class FigureBracket(*children, **attrs)[source]

Bases: BlockElement

One [] bracketed set of figures in figuremode.

space_between = ' '

whitespace between children

head = '['
tail = ']'
class FigureStep(head, *children, **attrs)[source]

Bases: Int

A step number in figure mode.

class FigureSkip(*children, **attrs)[source]

Bases: HeadElement

The invisible figure step _.

head = '_'
class FigureAccidental(head, *children, **attrs)[source]

Bases: MappingElement

An accidental in figure mode.

One of: -1, -0.5, 0, 0.5, 1, corresponding to:

'--', '-', '', '+' or '++'.

mapping = {'': 0, '+': 0.5, '++': 1, '-': -0.5, '--': -1}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class FigureAlteration(head, *children, **attrs)[source]

Bases: MappingElement

An alteration in figure mode.

One of: “augmented”, “diminished”, “raised” or “end-of-line”, corresponding to: +, /, \ or !.

mapping = {'/': 'diminished', '\\!': 'end-of-line', '\\+': 'augmented', '\\\\': 'raised'}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class Tag(*children, **attrs)[source]

Bases: HeadElement

A \tag command.

head = '\\tag'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class KeepWithTag(*children, **attrs)[source]

Bases: HeadElement

A \keepWithTag command.

head = '\\keepWithTag'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class RemoveWithTag(*children, **attrs)[source]

Bases: HeadElement

A \removeWithTag command.

head = '\\removeWithTag'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class TagGroup(*children, **attrs)[source]

Bases: HeadElement

A \tagGroup command.

head = '\\tagGroup'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class PushToTag(*children, **attrs)[source]

Bases: HeadElement

A \pushToTag command.

head = '\\pushToTag'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class AppendToTag(*children, **attrs)[source]

Bases: HeadElement

A \appendToTag command.

head = '\\appendToTag'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Etc(*children, **attrs)[source]

Bases: HeadElement

The \etc placeholder.

head = '\\etc'
class Accepts(*children, **attrs)[source]

Bases: HeadElement

The \accepts command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\accepts'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Denies(*children, **attrs)[source]

Bases: HeadElement

The \denies command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\denies'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Name(*children, **attrs)[source]

Bases: HeadElement

The \name command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\name'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Alias(*children, **attrs)[source]

Bases: HeadElement

The \alias command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\alias'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Consists(*children, **attrs)[source]

Bases: HeadElement

The \consists command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\consists'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Remove(*children, **attrs)[source]

Bases: HeadElement

The \remove command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\remove'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class DefaultChild(*children, **attrs)[source]

Bases: HeadElement

The \defaultchild command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\defaultchild'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Omit(*children, **attrs)[source]

Bases: HeadElement, Music

The \omit command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\omit'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Hide(*children, **attrs)[source]

Bases: HeadElement, Music

The \hide command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\hide'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Undo(*children, **attrs)[source]

Bases: HeadElement, Music

The \undo command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\undo'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Once(*children, **attrs)[source]

Bases: HeadElement, Music

The \once command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\once'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Temporary(*children, **attrs)[source]

Bases: HeadElement, Music

The \temporary command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\temporary'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Override(*children, **attrs)[source]

Bases: _ConvertUnpitchedToInt, HeadElement, Music

The \override command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\override'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Revert(*children, **attrs)[source]

Bases: HeadElement, Music

The \revert command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\revert'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Set(*children, **attrs)[source]

Bases: _ConvertUnpitchedToInt, HeadElement, Music

The \set command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\set'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Unset(*children, **attrs)[source]

Bases: HeadElement, Music

The \unset command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\unset'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Version(*children, **attrs)[source]

Bases: HeadElement, Music

The \version command.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\version'
property version

The version number, as a tuple of ints (may be empty).

signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Language(*children, **attrs)[source]

Bases: HeadElement

The \language command.

Has a String child with the language name, which can be conveniently edited via the language attribute.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\language'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

repr_head()[source]

Return a representation for the head.

The default implementation returns None.

property language

The language.

class Include(*children, **attrs)[source]

Bases: HeadElement

The \include command.

You can use the :attr:language attribute, assuming that the included file is a language definition file. If the filename is not recognized as a language definition file, the property will return None.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\include'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

repr_head()[source]

Return a representation for the head.

The default implementation returns None.

property filename

The filename.

property language

The language, if the filename refers to a known language definition.

Setting the attribute appends the ".ly" automatically.

class VoiceN(head, *children, **attrs)[source]

Bases: MappingElement

Commands like \voiceOne, \voiceTwo, etc.

mapping = {'\\voiceFive': 5, '\\voiceFour': 4, '\\voiceOne': 1, '\\voiceSix': 6, '\\voiceThree': 3, '\\voiceTwo': 2}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class GrobDirection(head, *children, **attrs)[source]

Bases: MappingElement

A collection of commands concerning direction, like \slurUp.

To create a \slurUp command, use:

>>> node = lily.GrobDirection(("Slur", 1))
>>> node.write()
'\\slurUp'

Or:

>>> node = lily.GrobDirection.from_mapping(r'\slurUp')

When reading this node programmatically, the grob and direction attributes can be read and modified:

>>> node.grob
'Slur'
>>> node.direction
1
>>> node.write()
'\\slurUp'
>>> node.direction = -1
>>> node.write()
'\\slurDown'

The grobs class attribute is a dictionary mapping each available grob to a tuple of the directions it supports. (Technically not all named objects are grobs (graphical objects).) Most “grobs” support all three directions: Up (1), Neutral (0), Down (-1).

mapping = {'\\arpeggioArrowDown': ('ArpeggioArrow', -1), '\\arpeggioArrowUp': ('ArpeggioArrow', 1), '\\bassFigureStaffAlignmentDown': ('BassFigureStaffAlignment', -1), '\\bassFigureStaffAlignmentNeutral': ('BassFigureStaffAlignment', 0), '\\bassFigureStaffAlignmentUp': ('BassFigureStaffAlignment', 1), '\\dotsDown': ('Dots', -1), '\\dotsNeutral': ('Dots', 0), '\\dotsUp': ('Dots', 1), '\\dynamicDown': ('Dynamic', -1), '\\dynamicNeutral': ('Dynamic', 0), '\\dynamicUp': ('Dynamic', 1), '\\phrasingSlurDown': ('PhrasingSlur', -1), '\\phrasingSlurNeutral': ('PhrasingSlur', 0), '\\phrasingSlurUp': ('PhrasingSlur', 1), '\\slurDown': ('Slur', -1), '\\slurNeutral': ('Slur', 0), '\\slurUp': ('Slur', 1), '\\stemDown': ('Stem', -1), '\\stemNeutral': ('Stem', 0), '\\stemUp': ('Stem', 1), '\\textSpannerDown': ('TextSpanner', -1), '\\textSpannerNeutral': ('TextSpanner', 0), '\\textSpannerUp': ('TextSpanner', 1), '\\tieDown': ('Tie', -1), '\\tieNeutral': ('Tie', 0), '\\tieUp': ('Tie', 1), '\\tupletDown': ('Tuplet', -1), '\\tupletNeutral': ('Tuplet', 0), '\\tupletUp': ('Tuplet', 1)}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

grobs = {'ArpeggioArrow': (-1, 1), 'BassFigureStaffAlignment': (-1, 0, 1), 'Dots': (-1, 0, 1), 'Dynamic': (-1, 0, 1), 'PhrasingSlur': (-1, 0, 1), 'Slur': (-1, 0, 1), 'Stem': (-1, 0, 1), 'TextSpanner': (-1, 0, 1), 'Tie': (-1, 0, 1), 'Tuplet': (-1, 0, 1)}
property grob

The grob (graphical object), starting with a Capital.

property direction

The direction, 1 for up, 0 for neutral, -1 for down.

class GrobStyle(head, *children, **attrs)[source]

Bases: MappingElement

A collection of commands concerning direction, like \slurDashed.

To create a \slurDashed command, use:

>>> node = lily.GrobStyle(("Slur", "dashed"))
>>> node.write()
'\\slurDashed'

Or:

>>> node = lily.GrobStyle.from_mapping(r'\slurDashed')

When reading this node programmatically, the grob and style attributes can be read and modified:

>>> node.grob
'Slur'
>>> node.style
'dashed'
>>> node.write()
'\\slurDashed'
>>> node.style = "dotted"
>>> node.write()
'\\slurDotted'

The grobs class attribute is a dictionary mapping each available grob to a tuple of the styles it supports. All grobs support the styles "solid", "dashed", and "dotted".

mapping = {'\\phrasingSlurDashed': ('PhrasingSlur', 'dashed'), '\\phrasingSlurDotted': ('PhrasingSlur', 'dotted'), '\\phrasingSlurSolid': ('PhrasingSlur', 'solid'), '\\slurDashed': ('Slur', 'dashed'), '\\slurDotted': ('Slur', 'dotted'), '\\slurSolid': ('Slur', 'solid'), '\\tieDashed': ('Tie', 'dashed'), '\\tieDotted': ('Tie', 'dotted'), '\\tieSolid': ('Tie', 'solid')}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

grobs = {'PhrasingSlur': ('dashed', 'dotted', 'solid'), 'Slur': ('dashed', 'dotted', 'solid'), 'Tie': ('dashed', 'dotted', 'solid')}
property grob

The grob (graphical object), starting with a Capital.

property style

The style: "solid", "dashed", or "dotted".

class Toggle(head, *children, **attrs)[source]

Bases: MappingElement

A collection of commands that can be on/off, like \textLengthOn.

To create a \textLengthOn command, use:

>>> node = lily.Toggle(("textLength", True))
>>> node.write()
'\\textLengthOn'

Or:

>>> node = lily.Toggle.from_mapping(r'\textLengthOn')

When reading this node programmatically, the prop and value attributes can be read and modified:

>>> node.prop
'textLength'
>>> node.value
True
>>> node.write()
'\\textLengthOn'
>>> node.value = False
>>> node.write()
'\\textLengthOff'

The props class attribute is a tuple with all available prop names. All props support the values True and False.

props = ('autoBeam', 'autoBreaks', 'autoLineBreaks', 'autoPageBreaks', 'balloonLength', 'bassFigureExtenders', 'cadenza', 'deadNotes', 'easyHeads', 'improvisation', 'harmonics', 'kievan', 'markLength', 'mergeDifferentlyDotted', 'mergeDifferentlyHeaded', 'pointAndClick', 'predefinedFretboards', 'sostenuto', 'sustain', 'textLength', 'xNotes')
mapping = {'\\autoBeamOff': ('autoBeam', False), '\\autoBeamOn': ('autoBeam', True), '\\autoBreaksOff': ('autoBreaks', False), '\\autoBreaksOn': ('autoBreaks', True), '\\autoLineBreaksOff': ('autoLineBreaks', False), '\\autoLineBreaksOn': ('autoLineBreaks', True), '\\autoPageBreaksOff': ('autoPageBreaks', False), '\\autoPageBreaksOn': ('autoPageBreaks', True), '\\balloonLengthOff': ('balloonLength', False), '\\balloonLengthOn': ('balloonLength', True), '\\bassFigureExtendersOff': ('bassFigureExtenders', False), '\\bassFigureExtendersOn': ('bassFigureExtenders', True), '\\cadenzaOff': ('cadenza', False), '\\cadenzaOn': ('cadenza', True), '\\deadNotesOff': ('deadNotes', False), '\\deadNotesOn': ('deadNotes', True), '\\easyHeadsOff': ('easyHeads', False), '\\easyHeadsOn': ('easyHeads', True), '\\harmonicsOff': ('harmonics', False), '\\harmonicsOn': ('harmonics', True), '\\improvisationOff': ('improvisation', False), '\\improvisationOn': ('improvisation', True), '\\kievanOff': ('kievan', False), '\\kievanOn': ('kievan', True), '\\markLengthOff': ('markLength', False), '\\markLengthOn': ('markLength', True), '\\mergeDifferentlyDottedOff': ('mergeDifferentlyDotted', False), '\\mergeDifferentlyDottedOn': ('mergeDifferentlyDotted', True), '\\mergeDifferentlyHeadedOff': ('mergeDifferentlyHeaded', False), '\\mergeDifferentlyHeadedOn': ('mergeDifferentlyHeaded', True), '\\pointAndClickOff': ('pointAndClick', False), '\\pointAndClickOn': ('pointAndClick', True), '\\predefinedFretboardsOff': ('predefinedFretboards', False), '\\predefinedFretboardsOn': ('predefinedFretboards', True), '\\sostenutoOff': ('sostenuto', False), '\\sostenutoOn': ('sostenuto', True), '\\sustainOff': ('sustain', False), '\\sustainOn': ('sustain', True), '\\textLengthOff': ('textLength', False), '\\textLengthOn': ('textLength', True), '\\xNotesOff': ('xNotes', False), '\\xNotesOn': ('xNotes', True)}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

property prop

The property that can be on or off.

property value

The value (True for "On", False for "Off").

class Shape(*children, **attrs)[source]

Bases: HeadElement

The \shape command.

Has a Scheme and a SYMBOL child. (As articulation, has only a Scheme child.)

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\shape'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class VShape(*children, **attrs)[source]

Bases: Shape

The \vshape command.

Like \shape but draws the control points.

head = '\\vshape'
class StringTuning(*children, **attrs)[source]

Bases: HeadElement

The \stringTuning command, with one Chord argument.

space_after_head = ' '

whitespace before first child

space_between = ' '

whitespace between children

head = '\\stringTuning'
signatures()[source]

Return an iterable of signature tuples.

A signature is a tuple. Every item in the tuple is an Element type, or a tuple of Element types; and is used with build_tree() to see whether an element can be a child of this element.

By default an empty iterable is returned.

class Unit(head, *children, **attrs)[source]

Bases: MappingElement

A unit: \mm, \cm, \pt or \in.

A Unit node can be attached to an Int or Float:

>>> from quickly.dom import lily
>>> lily.Int(10, lily.Unit("cm")).write()
'10\\cm'
mapping = {'\\cm': 'cm', '\\in': 'in', '\\mm': 'mm', '\\pt': 'pt'}

The mapping class attribute is a dictionay mapping unique head values to unique output values. Other head values can’t be used, they result in a TypeError.

class Lookup(node, scope=None, wait=True)[source]

Bases: object

Helper class to find definitions and other stuff in a lily.Document from the viewpoint of a node.

A Scope, if given using the scope parameter, is used to resolve include files. If no scope is given, only searches the current DOM document; the yielded scope is then always None.

If a scope is given, include commands are followed and wait determines whether to wait for ongoing transformations of external DOM documents. If wait is False, and a transformation is not yet finished the included document’s toplevel nodes will not be yielded.

ancestors()[source]

Yield the ancestors with index of node that should be searched for possible definitions.

The default implementation yields ancestors that inherit HandleAssignments and stops at the Document node.

preceding_nodes()[source]

Yield preceding nodes in ancestors and toplevel, in backward direction, as two-tuples (node, scope).

If a scope was given on instantiation, included files are followed.

When the beginning of the current scope (document) is reached, continues the search in parent scopes (if a scope was given), and if that parent scope has a node pointer, continues the search from there. This is useful when an included file refers to a variable that was set in the parent document before the \include command.

So when file_a.ly reads:

music = { c }
\include "file_b.ly"

And file_b.ly only contains:

\new Score { \music }

When traversing the musical contents of file a, the value of the \music Reference in file b is correctly found in file a.

find_assignment(name)[source]

Find an Assignment from here, with name name.

If found, return its value and the scope.

is_music(node)[source]

Return True if the node is an instance of Music.

is_symbol(text)[source]

Return True if text is a valid LilyPond symbol.

make_list_node(value)[source]

Return an element node corresponding to the value.

If value is a string, a Symbol is returned if it’s valid LilyPond identifier. otherwise String. If value is an integer, a Int is returned.

If no suitable node type could be returned, None is returned.

duration_getter()[source]

Return a callable that returns the (duration, scaling) tuple of a Durable.

If the durable does not have a Duration child, the callable searches backwards until a Durable is found that has a duration that LilyPond would use for the current durable. All found durables without duration are cached, so the next request only needs at most to search back one durable. If no durable with a value is found, (Fraction(1, 4), 1) is returned.

Use this getter if you are not sure you really iterate over all the durables in a node and cannot keep track of the previous durable yourself.

Get a new getter if you also modify durations.

previous_duration(node)[source]

Return a two-tuple(duration, scaling) of the closest preceding Durable that has a duration that LilyPond would use if the current node had no duration.

If no such node was found, returns (Fraction(1, 4), 1).

This function is potentially slow, as it searches backwards for a Durable node. Don’t use it if you have the opportunity to keep track of the previous duration yourself (from a Durable that has the duration_sets_previous attribute set to True).

You can also use a duration_getter(), which optimizes for adjacent notes without duration.

convert_duration_to_int(node)[source]

Return an Int element, created from the specified Duration element.

This can be used if a music function wants an integer number, while the origin token was seen as a duration by parce and the music builder.

create_element_from_value(value)[source]

Convert a regular Python value to a lilypond Element node.

This can be used to ease manually building a node structure. Converts:

  • bool to Scheme(‘#’, scm.Bool(value))

  • int to Int(value)

  • float to Float(value)

  • str to String(value)

  • tuple(int, “unit”) to Int(value, Unit(“unit”)) where unit in “mm”, “cm”, “in”, “pt”

  • tuple(float, “unit”) to Float(value, Unit(“unit”)) where unit in “mm”, “cm”, “in”, “pt”

  • an Element node is returned unchanged.

Raises ValueError when a value can’t be converted to an element.

create_value_from_element(node)[source]

Get the Python value from an Element node.

Returns:

  • bool, int, float etc for a Scheme(‘#’, scm.Bool(value) or scm.Number(value)) node

  • int for an Int node

  • float for a Float node

  • Fraction for a Fraction node

  • str for a String, Symbol or scm.String node

  • tuple(int, “unit”) for a Int(Unit()) node

  • tuple(float, “unit”) for a Float(Unit()) node

Returns None when this function cannot get a simple value from the node.

get_num_value(node)[source]

Get a numerical value from a node, if possible, else None.

get_int_value(node)[source]

Get a integer value from a node, if possible, else None.

filter_map(func, iterable)[source]

Call func on every item in iterable and yield the result value if not None.

Equivalent to:

filter(lambda r: r is not None, map(func, iterable))