# ly.music package

## Module contents

An api to read music from the tokens of a ly.document.Document into a tree structure.

This is meant to quickly read music from a document, to perform modifications on the document, and to interpret music and markup and to convert or export it to other formats.

All nodes are a subclass of items.Item, (which inherits from node.WeakNode).

Tree structures are created from nested LilyPond structures, markup and scheme code. Some Item types have special methods to query information. The Music type, for example, has a length() method that returns the duration of the music fragment.

Using the Music.events() method and the events module, it is possible to iterate in musical time over the music tree, e.g. to convert music to another format.

This package is not yet capable to construct documents entirely from scratch. This needs to be developed. Until that time, the ly.dom module can be used instead.

Some Item types can have a list of child items, but the tree structure is as linear as possible.

A convenience function is available to create a ly.music.items.Document instance for the specified ly.document.Document.

Here is an example:

    >>> import ly.document
    >>> import ly.music
    >>> d=ly.document.Document(r'''
    \version "2.18.0"

    music = \relative {
      \time 4/4
      \key d \minor
      d4 e f g
      a g f e
      d2
    }

    \score {
      \new Staff <<
        \music
      >>
    }
    ''')
    >>> m=ly.music.document(d)
    >>> print m.dump()
    <Document>
      <Version u'\\version'>
        <String u'"'>
      <Assignment u'music'>
        <Relative u'\\relative'>
          <MusicList u'{'>
            <TimeSignature u'\\time'>
            <KeySignature u'\\key'>
              <Note u'd'>
              <Command u'\\minor'>
            <Note u'd'>
            <Note u'e'>
            <Note u'f'>
            <Note u'g'>
            <Note u'a'>
            <Note u'g'>
            <Note u'f'>
            <Note u'e'>
            <Note u'd'>
      <Score u'\\score'>
        <Context u'\\new'>
          <MusicList u'<<'>
            <UserCommand u'\\music'>
    >>> m[2][0][0]
    <MusicList u'<<'>
    >>> m[2][0][0].length()
    Fraction(5, 2)
    >>>

ly.music.document(doc)

  Return a music.items.Document instance for the ly.document.Document.

## Submodules

## ly.music.event module

Translates a music.items.Document tree into lists of events.

class ly.music.event.Events

  Bases: `object`

  Traverses a music tree and records music events from it.

  read(node, time=0, scaling=1)

    Read events from the node and all its child nodes; return time.

  traverse(node, time, scaling)

    Traverse node and call event handlers; record and return the time.

  unfold_repeats = False

## ly.music.items module

The items a music expression is constructed with in a tree structure.

Whitespace and comments are left out.

All nodes (instances of Item) have a ‘position’ attribute that indicates where the item starts in the source text. Almost all items have the token that starts the expression in the ‘token’ attribute and possibly other tokens in the ‘tokens’ attribute, as a tuple.

The ‘end_position()’ method returns the position where the node (including its child nodes) ends.

You can get the whole tree structure of a LilyPond document by instantiating a Document with the ly.document.Document instance. (It will read all the tokens from the document using the Reader from the read module.) As a convenience, the ly.music.document(doc) function does this.

If you want to add new Item types, you should also add a method to read.Reader to construct those items.

class ly.music.items.Absolute(parent=None)

  Bases: `ly.music.items.Music`

  An absolute music expression. Has one child (normally Music).

class ly.music.items.AfterGrace(parent=None)

  Bases: `ly.music.items.Music`

  The afterGrace function with its two arguments.

  Only the duration of the first is counted.

class ly.music.items.Alternative(parent=None)

  Bases: `ly.music.items.Music`

  An alternative expression.

class ly.music.items.Articulation(parent=None)

  Bases: `ly.music.items.Item`

  An articulation, fingering, string number, or other symbol.

class ly.music.items.Assignment(parent=None)

  Bases: `ly.music.items.Item`

  A variable = value construct.

  name()

    The variable name.

  value()

    The assigned value.

class ly.music.items.Beam(parent=None)

  Bases: `ly.music.items.Item`

  A [ or ].

  event = None

class ly.music.items.Book(parent=None)

  Bases: `ly.music.items.Container`

  A book { … } construct.

class ly.music.items.BookPart(parent=None)

  Bases: `ly.music.items.Container`

  A bookpart { … } construct.

class ly.music.items.Change(parent=None)

  Bases: `ly.music.items.Translator`

  A change music expression.

class ly.music.items.Chord(parent=None)

  Bases: `ly.music.items.Durable`, `ly.music.items.Container`

class ly.music.items.ChordItem(parent=None)

  Bases: `ly.music.items.Item`

  An item inside a ChordSpecifier, e.g. a number or modifier.

class ly.music.items.ChordMode(parent=None)

  Bases: `ly.music.items.InputMode`

  A chordmode or chords expression.

class ly.music.items.ChordSpecifier(parent=None)

  Bases: `ly.music.items.Item`

  Chord specifications after a note in chord mode.

  Has children of Note or ChordItem class.

class ly.music.items.Clef(parent=None)

  Bases: `ly.music.items.Item`

  A clef item.

  specifier()

class ly.music.items.Command(parent=None)

  Bases: `ly.music.items.Item`

  A LilyPond command.

class ly.music.items.Container(parent=None)

  Bases: `ly.music.items.Item`

  An item having a list of child items.

class ly.music.items.Context(parent=None)

  Bases: `ly.music.items.Translator`, `ly.music.items.Music`

  A new or context music expression.

class ly.music.items.Document(doc)

  Bases: `ly.music.items.Item`

  A toplevel item representing a ly.document.Document.

  get_included_document_node(node)

    Return a Document for the Include node. May return None.

  get_music(filename)

    Return the music Document for the specified filename.

    This implementation loads a ly.document.Document using utf-8 encoding. Inherit from this class to implement other loading mechanisms or caching.

  iter_music(node=None)

    Iter over the music, following references to other assignments.

  music_events_til_position(position)

    Return a list of tuples.

    Every tuple is a (parent, nodes, scaling). If an empty list is returned, there is no music expression at this position.

  node(position, depth=- 1)

    Return the node at or just before the specified position.

  resolve_filename(filename)

    Resolve filename against our document and include_path.

  substitute_for_node(node)

    Returns a node that replaces the specified node (e.g. in music).

    For example: a variable reference returns its value. Returns nothing if the node is not substitutable. Returns the node itself if it was substitutable, but the substitution failed.

  time_length(start, end)

    Return the length of the music between start and end positions.

    Returns None if start and end are not in the same expression.

  time_position(position)

    Return the time position in the music at the specified cursor position.

    The value is a fraction. If None is returned, we are not in a music expression.

class ly.music.items.DrumMode(parent=None)

  Bases: `ly.music.items.InputMode`

  A drummode or drums expression.

class ly.music.items.DrumNote(parent=None)

  Bases: `ly.music.items.Durable`

class ly.music.items.Durable(parent=None)

  Bases: `ly.music.items.Item`

  An Item that has a musical duration, in the duration attribute.

  duration = (0, 1)
  events(e, time, scaling)

    Let the event.Events instance handle the events. Return the time.

  length()

    Return the musical duration (our base * our scaling).

class ly.music.items.Duration(parent=None)

  Bases: `ly.music.items.Item`

  A written duration

class ly.music.items.Dynamic(parent=None)

  Bases: `ly.music.items.Item`

  Any dynamic symbol.

class ly.music.items.FigureMode(parent=None)

  Bases: `ly.music.items.InputMode`

  A figuremode or figures expression.

class ly.music.items.Grace(parent=None)

  Bases: `ly.music.items.Music`

  Music that has grace timing, i.e. 0 as far as computation is concerned.

  events(e, time, scaling)

    Let the event.Events instance handle the events. Return the time.

  preceding(node=None)

    Return a two-tuple (nodes, scaling).

    The nodes are the nodes in time before the node (which must be a child), and the scaling is 0 for (because we have grace notes).

    If node is None, all nodes that would precede a fictive node at the end are returned.

class ly.music.items.Header(parent=None)

  Bases: `ly.music.items.Container`

  A header { … } construct.

class ly.music.items.Include(parent=None)

  Bases: `ly.music.items.Item`

  An include command (not changing the language).

  filename()

    Returns the filename.

class ly.music.items.InputMode(parent=None)

  Bases: `ly.music.items.Music`

  Base class for inputmode-changing commands.

class ly.music.items.Item(parent=None)

  Bases: `ly.node.WeakNode`

  Represents any item in the music of a document.

  This can be just a token, or an interpreted construct such as a note, rest or sequential or simultaneous construct , etc.

  Some Item instances just have one responsible token, but others have a list or tuple to tokens.

  An Item also has a pointer to the Document it originates from.

  document = None
  end_position()

    Return the end position of this node.

  events(e, time, scaling)

    Let the event.Events instance handle the events. Return the time.

  has_output(_seen_docs=None)

    Return True if this node has toplevel music, markup, book etc.

    I.e. returns True when LilyPond would likely generate output. Usually you’ll call this method on a Document, Score, BookPart or Book node.

    You should not supply the _seen_docs argument; it is used internally to avoid traversing recursively nested include files.

  iter_toplevel_items()

    Yield the toplevel items of our Document node in backward direction.

    Iteration starts with the node just before the node “self” is a descendant of.

  iter_toplevel_items_include()

    Same as iter_toplevel_items(), but follows include commands.

  length()

    Return the musical duration.

  music_children(depth=- 1)

    Yield all the children that are new music expressions

    (i.e. that are inside other constructions).

  music_parent()

    Walk up the parent tree until Music is found; return the outermost Music node.

    Returns None is the node does not belong to any music expression (e.g. a toplevel Markup or Scheme object).

  plaintext()

    Return a plaintext value for this node.

    This only makes sense for items like Markup or String. For other types, an empty string is returned

  position = -1
  token = None
  tokens = ()

class ly.music.items.KeySignature(parent=None)

  Bases: `ly.music.items.Item`

  A key pitch mode command.

  mode()

    The mode, e.g. “major”, “minor”, etc.

  pitch()

    The ly.pitch.Pitch that denotes the pitch.

class ly.music.items.Keyword(parent=None)

  Bases: `ly.music.items.Item`

  A LilyPond keyword.

class ly.music.items.Language(parent=None)

  Bases: `ly.music.items.Item`

  A command (language or certain include commands) that changes the pitch language.

  language = None

class ly.music.items.Layout(parent=None)

  Bases: `ly.music.items.Container`

  A layout { … } construct.

class ly.music.items.LayoutContext(parent=None)

  Bases: `ly.music.items.Container`

  A context { … } construct within Layout or Midi.

class ly.music.items.LyricItem(parent=None)

  Bases: `ly.music.items.Item`

  Another lyric item (skip, extender, hyphen or tie).

class ly.music.items.LyricMode(parent=None)

  Bases: `ly.music.items.InputMode`

  A lyricmode, lyrics or addlyrics expression.

class ly.music.items.LyricText(parent=None)

  Bases: `ly.music.items.Durable`

  A lyric text (word, markup or string), with a Duration.

class ly.music.items.LyricsTo(parent=None)

  Bases: `ly.music.items.InputMode`

  A lyricsto expression.

  context_id()

class ly.music.items.Markup(parent=None)

  Bases: `ly.music.items.Item`

  A command starting markup (markup, -lines and -list).

  plaintext()

    Return the plain text value of this node.

class ly.music.items.MarkupCommand(parent=None)

  Bases: `ly.music.items.Item`

  A markup command, such as italic etc.

  plaintext()

    Return the plain text value of this node.

class ly.music.items.MarkupList(parent=None)

  Bases: `ly.music.items.Item`

  The group of markup items inside { and }. NOTE: not a markuplist.

  plaintext()

    Return the plain text value of this node.

class ly.music.items.MarkupScore(parent=None)

  Bases: `ly.music.items.Item`

  A score inside Markup.

class ly.music.items.MarkupUserCommand(parent=None)

  Bases: `ly.music.items.Item`

  A user-defined markup command

  name()

    Return the name of this user command (without the leading backslash).

  value()

    Find the value assigned to this variable.

class ly.music.items.MarkupWord(parent=None)

  Bases: `ly.music.items.Item`

  A MarkupWord token.

  plaintext()

    Return a plaintext value for this node.

    This only makes sense for items like Markup or String. For other types, an empty string is returned

class ly.music.items.Midi(parent=None)

  Bases: `ly.music.items.Container`

  A midi { … } construct.

class ly.music.items.Music(parent=None)

  Bases: `ly.music.items.Container`

  Any music expression, to be inherited of.

  events(e, time, scaling)

    Let the event.Events instance handle the events. Return the time.

  length()

    Return the musical duration.

  preceding(node=None)

    Return a two-tuple (nodes, scaling).

    The nodes are the nodes in time before the node (which must be a child), and the scaling is the scaling this node applies (normally 1).

    If node is None, all nodes that would precede a fictive node at the end are returned.

class ly.music.items.MusicList(parent=None)

  Bases: `ly.music.items.Music`

  A music expression, either << >> or { }.

  events(e, time, scaling)

    Let the event.Events instance handle the events. Return the time.

  preceding(node=None)

    Return a two-tuple (nodes, scaling).

    The nodes are the nodes in time before the node (which must be a child), and the scaling is the scaling this node applies (normally 1).

    If node is None, all nodes that would precede a fictive node at the end are returned.

  simultaneous = False

class ly.music.items.Note(parent=None)

  Bases: `ly.music.items.Durable`

  A Note that has a ly.pitch.Pitch

  accidental_token = None
  octave_token = None
  octavecheck_token = None
  pitch = None

class ly.music.items.NoteMode(parent=None)

  Bases: `ly.music.items.InputMode`

  A notemode or notes expression.

class ly.music.items.Number(parent=None)

  Bases: `ly.music.items.Item`

  A numerical value, directly entered.

  value()

class ly.music.items.Override(parent=None)

  Bases: `ly.music.items.Item`

  An override command.

  context()
  grob()

class ly.music.items.Paper(parent=None)

  Bases: `ly.music.items.Container`

  A paper { … } construct.

class ly.music.items.PartCombine(parent=None)

  Bases: `ly.music.items.Music`

  The partcombine command with 2 music arguments.

  events(e, time, scaling)

    Let the event.Events instance handle the events. Return the time.

  preceding(node=None)

    Return a two-tuple (nodes, scaling).

    The nodes are the nodes in time before the node (which must be a child), and the scaling is the scaling this node applies (normally 1).

    If node is None, all nodes that would precede a fictive node at the end are returned.

class ly.music.items.Partial(parent=None)

  Bases: `ly.music.items.Item`

  A partial command.

  duration = (0, 1)
  partial_length()

    Return the duration given as argument as a Fraction.

class ly.music.items.PathItem(parent=None)

  Bases: `ly.music.items.Item`

  An item in the path of an override or revert command.

class ly.music.items.PhrasingSlur(parent=None)

  Bases: `ly.music.items.Item`

  A ( or ).

  event = None

class ly.music.items.PipeSymbol(parent=None)

  Bases: `ly.music.items.Item`

  A pipe symbol: |

class ly.music.items.Postfix(parent=None)

  Bases: `ly.music.items.Item`

  Any item that is prefixed with a _, - or ^ direction token.

class ly.music.items.Q(parent=None)

  Bases: `ly.music.items.Durable`

class ly.music.items.Relative(parent=None)

  Bases: `ly.music.items.Music`

  A relative music expression. Has one or two children (Note, Music).

class ly.music.items.Repeat(parent=None)

  Bases: `ly.music.items.Music`

  A repeat expression.

  events(e, time, scaling)

    Let the event.Events instance handle the events. Return the time.

  repeat_count()
  specifier()

class ly.music.items.Rest(parent=None)

  Bases: `ly.music.items.Durable`

class ly.music.items.Revert(parent=None)

  Bases: `ly.music.items.Item`

  A revert command.

  context()
  grob()

class ly.music.items.Scaler(parent=None)

  Bases: `ly.music.items.Music`

  A music construct that scales the duration of its contents.

  In the numerator and denominator attributes the values specified for LilyPond are stored, e.g. with times 3/2 { c d e }, the numerator is integer 3 and the denominator is integer 2. Note that for tuplet and times the meaning of these numbers is reversed.

  The algebraic scaling is stored in the scaling attribute.

  denominator = 0
  events(e, time, scaling)

    Let the event.Events instance handle the events. Return the time.

  numerator = 0
  preceding(node=None)

    Return a two-tuple (nodes, scaling).

    The nodes are the nodes in time before the node (which must be a child), and the scaling is the scaling this node applies.

    If node is None, all nodes that would precede a fictive node at the end are returned.

  scaling = 1

class ly.music.items.Scheme(parent=None)

  Bases: `ly.music.items.Item`

  A Scheme expression inside LilyPond.

  get_fraction()

    A basic way to get one (may be fractional) numerical value.

  get_int()

    A basic way to get one integer value.

  get_list_ints()

    A basic way to get a list of integer values.

  get_ly_make_moment()

    A basic way to get a ly:make-moment fraction.

  get_pair_ints()

    Very basic way to get two integers specified as a pair.

  get_string()

    A basic way to get a quoted string value (without the quotes).

  plaintext()

    A crude way to get the plain text in this node.

class ly.music.items.SchemeItem(parent=None)

  Bases: `ly.music.items.Item`

  Any scheme token.

class ly.music.items.SchemeLily(parent=None)

  Bases: `ly.music.items.Container`

  A music expression inside #{ and #}.

class ly.music.items.SchemeList(parent=None)

  Bases: `ly.music.items.Container`

  A ( … ) expression.

class ly.music.items.SchemeQuote(parent=None)

  Bases: `ly.music.items.Item`

  A ‘ in scheme.

class ly.music.items.Score(parent=None)

  Bases: `ly.music.items.Container`

  A score { … } construct.

class ly.music.items.Set(parent=None)

  Bases: `ly.music.items.Item`

  A set command.

  context()

    The context, if specified.

  property()

    The property.

  value()

    The value, given as argument. This is simply the child element.

class ly.music.items.Skip(parent=None)

  Bases: `ly.music.items.Durable`

class ly.music.items.Slur(parent=None)

  Bases: `ly.music.items.Item`

  A ( or ).

  event = None

class ly.music.items.String(parent=None)

  Bases: `ly.music.items.Item`

  A double-quoted string.

  plaintext()

    Return the plaintext value of this string, without escapes and quotes.

  value()

class ly.music.items.StringTuning(parent=None)

  Bases: `ly.music.items.Item`

  A stringTuning command (with a chord as argument).

class ly.music.items.Tag(parent=None)

  Bases: `ly.music.items.Music`

  A tag, keepWithTag or removeWithTag command.

  events(e, time, scaling)

    Let the event.Events instance handle the events. Return the time.

  preceding(node=None)

    Return a two-tuple (nodes, scaling).

    The nodes are the nodes in time before the node (which must be a child), and the scaling is the scaling this node applies (normally 1).

    If node is None, all nodes that would precede a fictive node at the end are returned.

class ly.music.items.Tempo(parent=None)

  Bases: `ly.music.items.Item`

  duration = (0, 1)
  fraction()

    Return the note value as a fraction given before the equal sign.

  tempo()

    Return a list of integer values describing the tempo or range.

  text()

    Return the text, if set. Can be Markup, Scheme, or String.

class ly.music.items.Tie(parent=None)

  Bases: `ly.music.items.Item`

  A tie.

class ly.music.items.TimeSignature(parent=None)

  Bases: `ly.music.items.Item`

  A time command.

  beatstructure()

    The scheme expressions denoting the beat structure, if specified.

  fraction()

    The lower number as a Fraction (e.g. for 3/2 it returns 1/2).

  measure_length()

    The length of one measure in this time signature as a Fraction.

  numerator()

    The upper number (e.g. for 3/2 it returns 3).

class ly.music.items.Token(parent=None)

  Bases: `ly.music.items.Item`

  Any token that is not otherwise recognized

class ly.music.items.Translator(parent=None)

  Bases: `ly.music.items.Item`

  Base class for a change, new, or context music expression.

  context()
  context_id()

    The context id, if specified after an equal sign.

class ly.music.items.Transpose(parent=None)

  Bases: `ly.music.items.Music`

  A transpose music expression. Has normally three children (Note, Note, Music).

class ly.music.items.Tremolo(parent=None)

  Bases: `ly.music.items.Item`

  A tremolo item “:”. The duration attribute is a tuple (base, scaling).

  duration = (0, 1)

class ly.music.items.Tweak(parent=None)

  Bases: `ly.music.items.Item`

  A tweak command.

class ly.music.items.Unpitched(parent=None)

  Bases: `ly.music.items.Durable`

  A “note” without pitch, just a standalone duration.

  pitch = None

class ly.music.items.Unset(parent=None)

  Bases: `ly.music.items.Item`

  An unset command.

  context()

    The context, if specified.

  property()

    The property.

class ly.music.items.UserCommand(parent=None)

  Bases: `ly.music.items.Music`

  A user command, most probably referring to music.

  events(e, time, scaling)

    Let the event.Events instance handle the events. Return the time.

  name()

    Return the name of this user command (without the leading backslash).

  value()

    Find the value assigned to this variable.

class ly.music.items.Version(parent=None)

  Bases: `ly.music.items.Item`

  A version command.

  version()

    The version as a tuple of ints.

  version_string()

    The version as a string.

class ly.music.items.VoiceSeparator(parent=None)

  Bases: `ly.music.items.Item`

  A voice separator: \

class ly.music.items.With(parent=None)

  Bases: `ly.music.items.Container`

  A with … construct.

## ly.music.read module

The Reader is used to construct a tree structure of (musical and other) items in a LilyPond document. The item types that are used are in the items module.

You instantiate a Reader with a ly.document.Source that reads tokens from any (part of a) ly.document.Document.

Whitespace and comments are left out.

All nodes (instances of Item) have a ‘position’ attribute that indicates where the item starts in the source text. Almost all items have the token that starts the expression in the ‘token’ attribute and possibly other tokens in the ‘tokens’ attribute, as a tuple.

The ‘end_position()’ method returns the position where the node (including its child nodes) ends.

class ly.music.read.Reader(source)

  Bases: `object`

  Reads tokens from a Source and builds a meaningful tree structure.

  add_bracketed(item, source)

    Append the arguments between brackets to the item.

    Returns True if that succeeded, else False.

  add_duration(item, token=None, source=None)

    Add a duration attribute to the item.

    When there are tokens, a Duration item is also appended to the item.

  add_markup_arguments(item)

    Add markup arguments to the item.

  consume(last_token=None)

    Yield the tokens from our source until a parser is exit.

    If last_token is given, it is called with the last token that is read.

  factory(cls, token=None, consume=False, position=None)

    Create Item instance for token.

    If consume is True, consume()s the source into item.tokens. If you don’t specify a token, you must specify the position (>= 0).

  handle_absolute(t, source)

    handle absolute

  handle_after_grace(t, source)

    handle afterGrace

  handle_alternative(t, source)

    handle alternative

  handle_articulation(t, source=None)

    handle Articulation

  handle_beam(t, source=None)

    handle Beam

  handle_bracketed(t, source)

    handle header, score, bookpart, book, paper, layout, midi, with, context

  handle_chord_start(t, source)

    handle ChordStart

  handle_clef(t, source)

    handle clef

  handle_direct_items(t, source)

    Tokens that directly translate to an Item.

    handle VoiceSeparator, PipeSymbol, Dynamic, Tie

  handle_direction(t, source)

    handle Direction

  handle_grace(t, source)

    handle grace, acciaccatura, appoggiatura, slashedGrace

  handle_include(t, source)

    handle include

  handle_inputmode(t, source)

    handle notemode, notes, chordmode, chords, figuremode, figures, drummode, drums

  handle_key(t, source)

    handle key

  handle_language(t, source)

    handle language

  handle_length(t, source)

    handle Length

  handle_lyricmode(t, source)

    handle lyricmode, lyrics, oldaddlyrics, addlyrics, lyricsto

  handle_markup(t, source=None)

    handle markup, markuplist, markuplines

  handle_markup_command(t)

    handle MarkupCommand

  handle_markup_open_bracket(t)

    handle OpenBracketMarkup

  handle_markup_score(t)

    handle MarkupScore

  handle_markup_user_command(t)

    handle MarkupUserCommand

  handle_markup_word(t)

    handle MarkupWord

  handle_music_item(t, source)

    handle MusicItem

  handle_music_list(t, source)

    handle OpenBracket, OpenSimultaneous, SimultaneousOrSequentialCommand

  handle_name(t, source)

    handle Name, ContextProperty

  handle_number_class(t, source=None)

    handle DecimalValue, IntegerValue, Fraction

  handle_override(t, source)

    handle override

  handle_partcombine(t, source=None)

    handle partcombine

  handle_partial(t, source)

    handle partial

  handle_relative(t, source)

    handle relative

  handle_repeat(t, source)

    handle repeat

  handle_revert(t, source)

    handle revert

  handle_scaler(t, source)

    handle times, tuplet, scaleDurations

  handle_scheme_lilypond_start(t)

    handle LilyPondStart

  handle_scheme_open_parenthesis(t)

    handle OpenParen

  handle_scheme_quote(t)

    handle Quote

  handle_scheme_start(t, source=None)

    handle SchemeStart

    handle SchemeStart

  handle_scheme_token(t)

    handle Dot, Bool, Char, Word, Number, Fraction, Float

  handle_set(t, source)

    handle set

  handle_slurs(t, source=None)

    handle Slur

  handle_string_start(t, source=None)

    handle StringStart

    handle StringStart

    handle StringStart

  handle_string_tuning(t, source)

    handle stringTuning

  handle_tag(t, source)

    handle tag, keepWithTag, removeWithTag, appendToTag, pushToTag

  handle_tempo(t, source)

    handle tempo

  handle_time(t, source)

    handle time

  handle_translator(t, source)

    handle new, context, change

  handle_transpose(t, source)

    handle transpose

  handle_tweak(t, source)

    handle tweak

  handle_unset(t, source)

    handle unset

  handle_variable_assignment(t, source)

    handle PaperVariable, LayoutVariable, HeaderVariable, UserVariable

  handle_version(t, source)

    handle version

  read(source=None)

    Yield Item instances reading from source.

  read_assignment(t)

    Read an assignment from the variable name. May return None.

  read_chord_specifier(t, source=None)

    Read stuff behind notes in chordmode.

    handle ChordSeparator

  read_command(t, source)

    Read the rest of a command given in t from the source.

    handle Command

  read_item(t, source=None)

    Return one Item that starts with token t. May return None.

  read_keyword(t, source)

    Read the rest of a keyword given in t from the source.

    handle Keyword

  read_lyric_item(t)

    Read one lyric item. Returns None for tokens it does not handle.

  read_markup(t)

    Read LilyPond markup (recursively).

  read_music_item(t, source)

    Read one music item (note, rest, s, skip, or q) from t and source.

  read_scheme(t)

    Return a Scheme item from the token t.

  read_scheme_item(t)

    Reads a Scheme expression (just after the # in LilyPond mode).

  read_tremolo(t, source=None)

    Read a tremolo.

    handle TremoloColon

  read_user_command(t, source)

    Read a user command, this can be a variable reference.

    handle UserCommand

  set_language(lang)

    Changes the pitch name language to use.

    Called internally when language or include tokens are encountered with a valid language name/file.

    Sets the language attribute to the language name.

  test_music_list(t)

    Test whether a music list ({ … }, << … >>, starts here.

    Also handles simultaneous { … } and sequential { … } correctly. These obscure commands are not even highlighted by lex, but they exist in LilyPond… simultaneous { … } is like << … >> but sequential << … >> just behaves like << … >>

    Returns a two-tuple(item; iterable), both may be None. If item is not None, it can be either a UserCommand or a MusicList. If iterable is None, the item is a UserCommand (namely simultaneous or sequential, but not followed by a { or <<); else the item is a MusicList, and the iterable should be read fully to get all the tokens inside the MusicList. If item is None, there is no MusicList and no token is read.

    This way you can handle the { … } and << … >> transparently in every input mode.

class ly.music.read.dispatcher

  Bases: `object`

  Decorator creator to dispatch commands, keywords, etc. to a method.

  method(token)

    The registered method to call for the token. May return None.

  read_arg(a)

class ly.music.read.dispatcher_class

  Bases: `ly.music.read.dispatcher`

  Decorator creator to dispatch the class of a token to a method.

  method(token)

    The registered method to call for the token’s class. May return None.

  read_arg(a)

ly.music.read.skip(source, what=(<class 'ly.lex._token.Space'>, <class 'ly.lex._token.Comment'>))

  Yield tokens from source, skipping items of classes specified in what.

  By default, comments and whitespace are skipped.