lilypondfile

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true ]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0 ]; edge [color=lightslategrey, penwidth=1 ]; subgraph "cluster_abjad.lilypondfile" { graph [label="abjad.lilypondfile"]; node [color=1]; "abjad.lilypondfile.Block" [URL="../api/abjad/lilypondfile.html#abjad.lilypondfile.Block", color=black, fontcolor=white, label=Block, target=_top]; "abjad.lilypondfile.LilyPondFile" [URL="../api/abjad/lilypondfile.html#abjad.lilypondfile.LilyPondFile", color=black, fontcolor=white, label="Lily\nPond\nFile", target=_top]; } subgraph cluster_builtins { graph [label=builtins]; node [color=2]; "builtins.object" [URL="https://docs.python.org/3.10/library/functions.html#object", label=object, target=_top]; } "builtins.object" -> "abjad.lilypondfile.Block" [minlen=1]; "builtins.object" -> "abjad.lilypondfile.LilyPondFile" [minlen=2]; }


Classes

Block

LilyPond file block.

LilyPondFile

LilyPond file.

class abjad.lilypondfile.Block(name=None, items=<factory>)[source]

LilyPond file block.

Use strings to add contents to a block:

>>> string = r"""right-margin = 2\cm
...     left-margin = 2\cm"""
>>> block = abjad.Block("paper", items=[string])
>>> string = abjad.lilypond(block)
>>> print(string)
\paper
{
    right-margin = 2\cm
    left-margin = 2\cm
}

Define a context block like this:

>>> string = r"""\Staff
...     \name FluteStaff
...     \type Engraver_group
...     \alias Staff
...     \remove Forbid_line_break_engraver
...     \consists Horizontal_bracket_engraver
...     \accepts FluteUpperVoice
...     \accepts FluteLowerVoice
...     \override Beam.positions = #'(-4 . -4)
...     \override Stem.stem-end-position = -6
...     autoBeaming = ##f
...     tupletFullLength = ##t
...     \accidentalStyle dodecaphonic"""
>>> block = abjad.Block("context", items=[string])
>>> string = abjad.lilypond(block)
>>> print(string)
\context
{
    \Staff
    \name FluteStaff
    \type Engraver_group
    \alias Staff
    \remove Forbid_line_break_engraver
    \consists Horizontal_bracket_engraver
    \accepts FluteUpperVoice
    \accepts FluteLowerVoice
    \override Beam.positions = #'(-4 . -4)
    \override Stem.stem-end-position = -6
    autoBeaming = ##f
    tupletFullLength = ##t
    \accidentalStyle dodecaphonic
}

Define an anonymous block like this:

>>> string = r"""command-1
...     command-2
...     command-3"""
>>> block = abjad.Block("", items=[string])
>>> string = abjad.lilypond(block)
>>> print(string)
{
    command-1
    command-2
    command-3
}

Markup formats like this:

>>> block = abjad.Block("score", items=[abjad.Markup(r"\markup foo")])
>>> string = abjad.lilypond(block)
>>> print(string)
\score
{
    \markup foo
}
>>> staff = abjad.Staff("c'4 d' e' f'")
>>> block = abjad.Block("score")
>>> block.items.append("<<")
>>> block.items.append(r'{ \include "layout.ly" }')
>>> block.items.append(staff)
>>> block.items.append(">>")
>>> lilypond_file = abjad.LilyPondFile(
...     lilypond_language_token=False,
...     lilypond_version_token=False,
... )
>>> lilypond_file.items.append(block)
>>> string = abjad.lilypond(lilypond_file)
>>> print(string)
\score
{
    <<
    { \include "layout.ly" }
    \new Staff
    {
        c'4
        d'4
        e'4
        f'4
    }
    >>
}

Attributes Summary

__eq__

Return self==value.

__post_init__

__repr__

Return repr(self).

name


Special methods

overridden __eq__(other)

Return self==value.

__post_init__()[source]
overridden __repr__()

Return repr(self).

class abjad.lilypondfile.LilyPondFile(items=<factory>, lilypond_language_token=True, lilypond_version_token=True, tag=None)[source]

LilyPond file.

>>> staff = abjad.Staff("c'8 d'8 e'8 f'8")
>>> lilypond_file = abjad.LilyPondFile(
...     items=[
...         r'\include "abjad.ily"',
...         """#(set-default-paper-size "a5" 'portrait)""",
...         "#(set-global-staff-size 16)",
...         staff,
...     ],
... )
>>> abjad.show(lilypond_file)  
>>> string = abjad.lilypond(lilypond_file)
>>> print(string)
\version "2.25.7"
\language "english"
\include "abjad.ily"
#(set-default-paper-size "a5" 'portrait)
#(set-global-staff-size 16)
\new Staff
{
    c'8
    d'8
    e'8
    f'8
}

Attributes Summary

__contains__

Is true when LilyPond file contains argument.

__eq__

Return self==value.

__getitem__

Gets item identified by argument.

__repr__

Return repr(self).

get_tag

Gets tag.


Special methods

__contains__(argument)[source]

Is true when LilyPond file contains argument.

>>> staff = abjad.Staff("c'4 d' e' f'", name="Staff")
>>> lilypond_file = abjad.LilyPondFile([staff])
>>> "Staff" in lilypond_file
True
>>> "Allegro" in lilypond_file
False
>>> 0 in lilypond_file
False
Return type:

bool

overridden __eq__(other)

Return self==value.

__getitem__(argument)[source]

Gets item identified by argument.

Searches score:

>>> voice_1 = abjad.Voice("c''4 b' a' g'", name="Voice_1")
>>> command = abjad.VoiceNumber(1)
>>> abjad.attach(command, voice_1[0])
>>> voice_2 = abjad.Voice("c'4 d' e' f'", name="Voice_2")
>>> command = abjad.VoiceNumber(2)
>>> abjad.attach(command, voice_2[0])
>>> staff = abjad.Staff(
...     [voice_1, voice_2],
...     simultaneous=True,
...     name="Staff",
... )
>>> score = abjad.Score([staff], name="Score")
>>> block = abjad.Block("score")
>>> block.items.append(score)
>>> lilypond_file = abjad.LilyPondFile([block])
>>> abjad.show(score)  
>>> lilypond_file["score"]
Block(name='score', items=[Score("{ { c''4 b'4 a'4 g'4 } { c'4 d'4 e'4 f'4 } }", name='Score', simultaneous=True)])
>>> lilypond_file["Score"]
Score("{ { c''4 b'4 a'4 g'4 } { c'4 d'4 e'4 f'4 } }", name='Score', simultaneous=True)
>>> lilypond_file["Staff"]
Staff("{ c''4 b'4 a'4 g'4 } { c'4 d'4 e'4 f'4 }", name='Staff', simultaneous=True)
>>> lilypond_file["Voice_1"]
Voice("c''4 b'4 a'4 g'4", name='Voice_1')
>>> lilypond_file["Voice_2"]
Voice("c'4 d'4 e'4 f'4", name='Voice_2')

Searches score:

>>> voice_1 = abjad.Voice("c''4 b' a' g'", name="Voice_1")
>>> command = abjad.VoiceNumber(1)
>>> abjad.attach(command, voice_1[0])
>>> voice_2 = abjad.Voice("c'4 d' e' f'", name="Voice_2")
>>> command = abjad.VoiceNumber(2)
>>> abjad.attach(command, voice_2[0])
>>> staff = abjad.Staff(
...     [voice_1, voice_2],
...     simultaneous=True,
...     name="Staff",
... )
>>> score = abjad.Score([staff], name="Score")
>>> lilypond_file = abjad.LilyPondFile([score])
>>> abjad.show(score)  
>>> lilypond_file["Score"]
Score("{ { c''4 b'4 a'4 g'4 } { c'4 d'4 e'4 f'4 } }", name='Score', simultaneous=True)
>>> lilypond_file["Staff"]
Staff("{ c''4 b'4 a'4 g'4 } { c'4 d'4 e'4 f'4 }", name='Staff', simultaneous=True)
>>> lilypond_file["Voice_1"]
Voice("c''4 b'4 a'4 g'4", name='Voice_1')
>>> lilypond_file["Voice_2"]
Voice("c'4 d'4 e'4 f'4", name='Voice_2')

REGRESSION. Works when score block contains parallel container:

>>> include_container = abjad.Container()
>>> string = r'\include "layout.ly"'
>>> literal = abjad.LilyPondLiteral(string, site="opening")
>>> abjad.attach(literal, include_container)
>>> staff = abjad.Staff("c'4 d' e' f'", name="Staff")
>>> container = abjad.Container(
...     [include_container, staff],
...     simultaneous=True,
... )
>>> block = abjad.Block("score")
>>> block.items.append(container)
>>> lilypond_file = abjad.LilyPondFile(
...     items=[block],
...     lilypond_language_token=False,
...     lilypond_version_token=False,
... )
>>> string = abjad.lilypond(lilypond_file)
>>> print(string)
\score
{
    <<
        {
            \include "layout.ly"
        }
        \context Staff = "Staff"
        {
            c'4
            d'4
            e'4
            f'4
        }
    >>
}
>>> lilypond_file["Staff"]
Staff("c'4 d'4 e'4 f'4", name='Staff')

Finds blocks by name:

>>> blocks = [abjad.Block("header"), abjad.Block("score")]
>>> lilypond_file = abjad.LilyPondFile(items=blocks)
>>> lilypond_file["score"]
Block(name='score', items=[])
>>> score = abjad.Score([abjad.Staff("c'4 d' e' f'")], name="Score")
>>> lilypond_file["score"].items.append(score)
>>> string = abjad.lilypond(lilypond_file)
>>> print(string)
\version "2.25.7"
\language "english"
\header {}
\score
{
    \context Score = "Score"
    <<
        \new Staff
        {
            c'4
            d'4
            e'4
            f'4
        }
    >>
}

Returns block or component.

overridden __repr__()

Return repr(self).


Methods

get_tag(site=None)[source]

Gets tag.