lilypondfile¶
Classes
LilyPond file block. |
|
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
Return self==value.
Return repr(self).
name
Special methods
- overridden __eq__(other)¶
Return self==value.
- 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
Is true when LilyPond file contains
argument
.Return self==value.
Gets item identified by
argument
.Return repr(self).
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:
- 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