LilyPondFile

class lilypondfiletools.LilyPondFile(comments=None, date_time_token=None, default_paper_size=None, global_staff_size=None, includes=None, items=None, lilypond_language_token=None, lilypond_version_token=None, use_relative_includes=None)

A LilyPond file.

>>> import abjad

Makes LilyPond file:

>>> staff = abjad.Staff("c'8 d'8 e'8 f'8")
>>> comments = [
...     'File construct as an example.',
...     'Parts shown here for positioning.',
...     ]
>>> includes = [
...     'external-settings-file-1.ly',
...     'external-settings-file-2.ly',
...     ]
>>> lilypond_file = abjad.LilyPondFile.new(
...     music=staff,
...     default_paper_size=('a5', 'portrait'),
...     comments=comments,
...     includes=includes,
...     global_staff_size=16,
...     )
>>> lilypond_file.header_block.composer = abjad.Markup('Josquin')
>>> lilypond_file.header_block.title = abjad.Markup('Missa sexti tonus')
>>> lilypond_file.layout_block.indent = 0
>>> lilypond_file.layout_block.left_margin = 15
>>> show(lilypond_file) 
>>> print(format(lilypond_file)) 
% 2017-08-02 22:01

% File construct as an example.
% Parts shown here for positioning.

\version "2.19.44"
\language "english"

\include "external-settings-file-1.ly"
\include "external-settings-file-2.ly"

#(set-default-paper-size "a5" 'portrait)
#(set-global-staff-size 16)

\header {
    composer = \markup { Josquin }
    title = \markup { "Missa sexti tonus" }
}

\layout {
    indent = #0
    left-margin = #15
}

\paper {}

\score {
    \new Staff {
        c'8
        d'8
        e'8
        f'8
    }
}

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_lilypondfiletools { graph [label=lilypondfiletools]; "abjad.tools.lilypondfiletools.LilyPondFile.LilyPondFile" [color=black, fontcolor=white, group=2, label=<<B>LilyPondFile</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.lilypondfiletools.LilyPondFile.LilyPondFile"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

comments Gets comments of Lilypond file.
date_time_token Gets date-time token.
default_paper_size Gets default paper size of LilyPond file.
floating([music]) Makes basic LilyPond file.
global_staff_size Gets global staff size of LilyPond file.
header_block Gets header block.
includes Gets includes of LilyPond file.
items Gets items in LilyPond file.
layout_block Gets layout block.
lilypond_language_token Gets LilyPond language token.
lilypond_version_token Gets LilyPond version token.
new([music, date_time_token, …]) Makes basic LilyPond file.
paper_block Gets paper block.
rhythm(selections[, divisions, …]) Makes rhythm-maker-style LilyPond file.
score_block Gets score block.
use_relative_includes Is true when LilyPond file should use relative includes.
__eq__(argument) Is true when ID of argument equals ID of Abjad object.
__format__([format_specification]) Formats LilyPond file.
__getitem__(name) Gets item with name.
__hash__() Hashes Abjad object.
__illustrate__() Illustrates LilyPond file.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets interpreter representation of LilyPond file.

Read-only properties

LilyPondFile.comments

Gets comments of Lilypond file.

Gets comments:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.comments
[]

Returns list.

LilyPondFile.date_time_token

Gets date-time token.

Gets date-time token:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.date_time_token
DateTimeToken()

Returns date-time token or none.

LilyPondFile.default_paper_size

Gets default paper size of LilyPond file.

Gets default paper size:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.default_paper_size is None
True

Set to pair or none.

Defaults to none.

Returns pair or none.

LilyPondFile.global_staff_size

Gets global staff size of LilyPond file.

Gets global staff size:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.global_staff_size is None
True

Set to number or none.

Defaults to none.

Returns number or none.

LilyPondFile.header_block

Gets header block.

Gets header block:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.header_block
<Block(name='header')>

Returns block or none.

LilyPondFile.includes

Gets includes of LilyPond file.

Gets includes:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.includes
[]

Returns list.

LilyPondFile.items

Gets items in LilyPond file.

Gets items:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> for item in lilypond_file.items:
...     item
...
<Block(name='header')>
<Block(name='layout')>
<Block(name='paper')>
<Block(name='score')>

Returns list:

>>> isinstance(lilypond_file.items, list)
True

Returns list.

LilyPondFile.layout_block

Gets layout block.

Gets layout block:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.layout_block
<Block(name='layout')>

Returns block or none.

LilyPondFile.lilypond_language_token

Gets LilyPond language token.

Gets LilyPond language token:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.lilypond_language_token
LilyPondLanguageToken()

Returns LilyPond language token or none.

LilyPondFile.lilypond_version_token

Gets LilyPond version token.

Gets LilyPond version token:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.lilypond_version_token 
LilyPondVersionToken('2.19.44')

Returns LilyPond version token or none.

LilyPondFile.paper_block

Gets paper block.

Gets paper block:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.paper_block
<Block(name='paper')>

Returns block or none.

LilyPondFile.score_block

Gets score block.

Gets score block:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.score_block
<Block(name='score')>

Returns block or none.

LilyPondFile.use_relative_includes

Is true when LilyPond file should use relative includes.

Gets relative include flag:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.use_relative_includes is None
True

Set to true, false or none.

Returns true, false or none.

Class & static methods

classmethod LilyPondFile.floating(music=None)

Makes basic LilyPond file.

>>> score = abjad.Score()
>>> time_signature_context = abjad.Context(
...     context_name='TimeSignatureContext',
...     )
>>> durations = [(2, 8), (3, 8), (4, 8)]
>>> maker = abjad.MeasureMaker()
>>> measures = maker(durations)
>>> time_signature_context.extend(measures)
>>> score.append(time_signature_context)
>>> staff = abjad.Staff()
>>> staff.append(abjad.Measure((2, 8), "c'8 ( d'8 )"))
>>> staff.append(abjad.Measure((3, 8), "e'8 ( f'8  g'8 )"))
>>> staff.append(abjad.Measure((4, 8), "fs'4 ( e'8 d'8 )"))
>>> score.append(staff)
>>> lilypond_file = abjad.LilyPondFile.floating(score)
>>> show(lilypond_file) 
>>> f(lilypond_file) 
% 2017-08-02 22:01

\version "2.19.44"
\language "english"

#(set-default-paper-size "letter" 'portrait)
#(set-global-staff-size 16)

\header {}

\layout {
    \accidentalStyle forget
    indent = #0
    ragged-right = ##t
    \context {
        \name TimeSignatureContext
        \type Engraver_group
        \consists Axis_group_engraver
        \consists Time_signature_engraver
        \override TimeSignature.X-extent = #'(0 . 0)
        \override TimeSignature.X-offset = #ly:self-alignment-interface::x-aligned-on-self
        \override TimeSignature.Y-extent = #'(0 . 0)
        \override TimeSignature.break-align-symbol = ##f
        \override TimeSignature.break-visibility = #end-of-line-invisible
        \override TimeSignature.font-size = #1
        \override TimeSignature.self-alignment-X = #center
        \override VerticalAxisGroup.default-staff-staff-spacing = #'((basic-distance . 0) (minimum-distance . 10) (padding . 6) (stretchability . 0))
    }
    \context {
        \Score
        \remove Bar_number_engraver
        \accepts TimeSignatureContext
        \override Beam.breakable = ##t
        \override SpacingSpanner.strict-grace-spacing = ##t
        \override SpacingSpanner.strict-note-spacing = ##t
        \override SpacingSpanner.uniform-stretching = ##t
        \override TupletBracket.bracket-visibility = ##t
        \override TupletBracket.minimum-length = #3
        \override TupletBracket.padding = #2
        \override TupletBracket.springs-and-rods = #ly:spanner::set-spacing-rods
        \override TupletNumber.text = #tuplet-number::calc-fraction-text
        autoBeaming = ##f
        proportionalNotationDuration = #(ly:make-moment 1 24)
        tupletFullLength = ##t
    }
    \context {
        \StaffGroup
    }
    \context {
        \Staff
        \remove Time_signature_engraver
    }
    \context {
        \RhythmicStaff
        \remove Time_signature_engraver
    }
}

\paper {
    left-margin = #20
    system-system-spacing = #'((basic-distance . 0) (minimum-distance . 0) (padding . 12) (stretchability . 0))
}

\score {
    \new Score <<
        \new TimeSignatureContext {
            {
                \time 2/8
                s1 * 1/4
            }
            {
                \time 3/8
                s1 * 3/8
            }
            {
                \time 4/8
                s1 * 1/2
            }
        }
        \new Staff {
            {
                \time 2/8
                c'8 (
                d'8 )
            }
            {
                \time 3/8
                e'8 (
                f'8
                g'8 )
            }
            {
                \time 4/8
                fs'4 (
                e'8
                d'8 )
            }
        }
    >>
}

Makes LilyPond file.

Wraps music in LilyPond \score block.

Adds LilyPond \header, \layout, \paper and \score blocks to LilyPond file.

Defines layout settings for custom \TimeSignatureContext.

(Note that you must create and populate an Abjad context with name equal to 'TimeSignatureContext' in order for \TimeSignatureContext layout settings to apply.)

Applies many file, layout and paper settings.

Returns LilyPond file.

classmethod LilyPondFile.new(music=None, date_time_token=None, default_paper_size=None, comments=None, includes=None, global_staff_size=None, lilypond_language_token=None, lilypond_version_token=None, use_relative_includes=None)

Makes basic LilyPond file.

Makes basic LilyPond file:

>>> score = abjad.Score([abjad.Staff("c'8 d'8 e'8 f'8")])
>>> lilypond_file = abjad.LilyPondFile.new(score)
>>> lilypond_file.header_block.title = abjad.Markup('Missa sexti tonus')
>>> lilypond_file.header_block.composer = abjad.Markup('Josquin')
>>> lilypond_file.layout_block.indent = 0
>>> lilypond_file.paper_block.top_margin = 15
>>> lilypond_file.paper_block.left_margin = 15
>>> f(lilypond_file) 
% 2017-08-02 22:01

\version "2.19.44"
\language "english"

\header {
    title = \markup { "Missa sexti tonus" }
    composer = \markup { Josquin }
}

\layout {
    indent = #0
}

\paper {
    top-margin = #15
    left-margin = #15
}

\score {
    \new Score <<
        \new Staff {
            c'8
            d'8
            e'8
            f'8
        }
    >>
}
>>> show(lilypond_file) 

Wraps music in LilyPond \score block.

Adds LilyPond \header, \layout, \paper and \score blocks to LilyPond file.

Returns LilyPond file.

classmethod LilyPondFile.rhythm(selections, divisions=None, attach_lilypond_voice_commands=None, implicit_scaling=None, pitched_staff=None, simultaneous_selections=None, time_signatures=None)

Makes rhythm-maker-style LilyPond file.

>>> import abjad
>>> from abjad.tools import rhythmmakertools

Makes rhythmic staff:

>>> maker = rhythmmakertools.EvenRunRhythmMaker(exponent=1)
>>> divisions = [(3, 4), (4, 8), (1, 4)]
>>> selections = maker(divisions)
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     selections,
...     divisions,
...     )
>>> show(lilypond_file) 

Set time signatures explicitly:

>>> maker = rhythmmakertools.EvenRunRhythmMaker(exponent=1)
>>> divisions = [(3, 4), (4, 8), (1, 4)]
>>> selections = maker(divisions)
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     selections,
...     [(6, 8), (4, 8), (2, 8)],
...     )
>>> show(lilypond_file) 

Makes pitched staff:

>>> maker = rhythmmakertools.EvenRunRhythmMaker(exponent=1)
>>> divisions = [(3, 4), (4, 8), (1, 4)]
>>> selections = maker(divisions)
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     selections,
...     divisions,
...     pitched_staff=True,
...     )
>>> show(lilypond_file) 

Makes simultaneous voices:

>>> maker_1 = rhythmmakertools.EvenRunRhythmMaker(exponent=1)
>>> divisions = [(3, 4), (4, 8), (1, 4)]
>>> selection_1 = abjad.select(maker_1(divisions))
>>> for note in abjad.iterate(selection_1).by_class(abjad.Note):
...     note.written_pitch = abjad.NamedPitch("e'")
... 
>>> maker_2 = rhythmmakertools.EvenRunRhythmMaker(exponent=2)
>>> selection_2 = abjad.select(maker_2(divisions))
>>> selections = {
...     'Voice 1': selection_1,
...     'Voice 2': selection_2,
... }
>>> lilypond_file = abjad.LilyPondFile.rhythm(
...     selections,
...     divisions,
...     )
>>> voice_1 = lilypond_file['Voice 1']
>>> abjad.attach(abjad.LilyPondCommand('voiceOne'), voice_1)
>>> voice_2 = lilypond_file['Voice 2']
>>> abjad.attach(abjad.LilyPondCommand('voiceTwo'), voice_2)
>>> show(lilypond_file) 

Used in rhythm-maker docs.

Returns LilyPond file.

Special methods

(AbjadObject).__eq__(argument)

Is true when ID of argument equals ID of Abjad object. Otherwise false.

Returns true or false.

LilyPondFile.__format__(format_specification='')

Formats LilyPond file.

Gets format:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> print(format(lilypond_file)) 
% 2017-08-02 22:01

\version "2.19.44"
\language "english"

\header {}

\layout {}

\paper {}

Works with empty layout and MIDI blocks:

>>> score = abjad.Score([abjad.Staff("c'8 d'8 e'8 f'8")])
>>> score_block = abjad.Block(name='score')
>>> layout_block = abjad.Block(name='layout')
>>> midi_block = abjad.Block(name='midi')
>>> score_block.items.append(score)
>>> score_block.items.append(layout_block)
>>> score_block.items.append(midi_block)
>>> f(score_block)
\score {
    \new Score <<
        \new Staff {
            c'8
            d'8
            e'8
            f'8
        }
    >>
    \layout {}
    \midi {}
}

Returns string.

LilyPondFile.__getitem__(name)

Gets item with name.

Gets header block:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file['header']
<Block(name='header')>

Searches score:

>>> voice_1 = abjad.Voice("c''4 b' a' g'", name='Custom Voice 1')
>>> abjad.attach(abjad.LilyPondCommand('voiceOne'), voice_1)
>>> voice_2 = abjad.Voice("c'4 d' e' f'", name='Custom Voice 2')
>>> abjad.attach(abjad.LilyPondCommand('voiceTwo'), voice_2)
>>> staff = abjad.Staff(
...     [voice_1, voice_2],
...     is_simultaneous=True,
...     name='Custom Staff',
...     )
>>> score = abjad.Score([staff], name='Custom Score')
>>> lilypond_file = abjad.LilyPondFile.new(score)
>>> show(score) 
>>> lilypond_file['score']
<Block(name='score')>
>>> lilypond_file['Custom Score']
<Score-"Custom Score"<<1>>>
>>> lilypond_file[abjad.Score]
<Score-"Custom Score"<<1>>>
>>> lilypond_file['Custom Staff']
<Staff-"Custom Staff"<<2>>>
>>> lilypond_file[abjad.Staff]
<Staff-"Custom Staff"<<2>>>
>>> lilypond_file['Custom Voice 1']
Voice("c''4 b'4 a'4 g'4", name='Custom Voice 1')
>>> lilypond_file['Custom Voice 2']
Voice("c'4 d'4 e'4 f'4", name='Custom Voice 2')
>>> lilypond_file[abjad.Voice]
Voice("c''4 b'4 a'4 g'4", name='Custom Voice 1')

Returns item.

Raises key error when no item with name is found.

(AbjadObject).__hash__()

Hashes Abjad object.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

LilyPondFile.__illustrate__()

Illustrates LilyPond file.

Returns LilyPond file unchanged.

(AbjadObject).__ne__(argument)

Is true when Abjad object does not equal argument. Otherwise false.

Returns true or false.

LilyPondFile.__repr__()

Gets interpreter representation of LilyPond file.

Gets interpreter representation:

>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file
LilyPondFile(comments=[], date_time_token=DateTimeToken(date_string='2017-08-02 22:01'), includes=[], items=[<Block(name='header')>, <Block(name='layout')>, <Block(name='paper')>, <Block(name='score')>], lilypond_language_token=LilyPondLanguageToken(), lilypond_version_token=LilyPondVersionToken(version_string='2.19.44'))

Returns string.