LilyPondFile¶
-
class
abjad.lilypondfile.LilyPondFile.
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.
>>> 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.ily', ... 'external-settings-file-2.ily', ... ] >>> 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 >>> abjad.show(lilypond_file)
>>> print(format(lilypond_file)) % File construct as an example. % Parts shown here for positioning. \version "2.19.82" \language "english" \include "external-settings-file-1.ily" \include "external-settings-file-2.ily" #(set-default-paper-size "a5" 'portrait) #(set-global-staff-size 16) \header { tagline = ##f 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 } }
Attributes Summary
__contains__
Is true when LilyPond file contains argument
.__format__
Formats LilyPond file. __getitem__
Gets item with name
.__illustrate__
Illustrates LilyPond file. __repr__
Gets interpreter representation of LilyPond file. comments
Gets comments of Lilypond file. date_time_token
Gets date-time token. default_paper_size
Gets default paper size of 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
Makes basic LilyPond file. paper_block
Gets paper block. rhythm
Makes rhythm-styled LilyPond file. score_block
Gets score block. use_relative_includes
Is true when LilyPond file should use relative includes. Special methods
-
__contains__
(argument)¶ Is true when LilyPond file contains
argument
.>>> staff = abjad.Staff("c'4 d' e' f'") >>> lilypond_file = abjad.LilyPondFile.new(staff)
>>> staff in lilypond_file True
>>> abjad.Staff in lilypond_file True
>>> 'Allegro' in lilypond_file False
>>> 0 in lilypond_file False
Return type: bool
-
__format__
(format_specification='')¶ Formats LilyPond file.
Gets format:
>>> lilypond_file = abjad.LilyPondFile.new()
>>> print(format(lilypond_file)) \version "2.19.82" \language "english" \header { tagline = ##f } \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)
>>> abjad.f(score_block) \score { \new Score << \new Staff { c'8 d'8 e'8 f'8 } >> \layout {} \midi {} }
>>> staff = abjad.Staff("c'8 d' e' f'") >>> abjad.attach(abjad.Articulation('.'), staff[0]) >>> abjad.attach(abjad.Markup('Allegro'), staff[0]) >>> score = abjad.Score([staff]) >>> lilypond_file = abjad.LilyPondFile.new([score]) >>> lilypond_file._lilypond_version_token = None
>>> abjad.f(lilypond_file) \language "english" \header { tagline = ##f } \layout {} \paper {} \score { { \new Score << \new Staff { c'8 -\staccato - \markup { Allegro } d'8 e'8 f'8 } >> } }
Returns string.
-
__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.LilyPondLiteral(r'\voiceOne'), voice_1) >>> voice_2 = abjad.Voice("c'4 d' e' f'", name='Custom Voice 2') >>> abjad.attach(abjad.LilyPondLiteral(r'\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) >>> abjad.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')
REGRESSION. Works when score block contains parallel container:
>>> include_container = abjad.Container() >>> string = r'\include "layout.ly"' >>> literal = abjad.LilyPondLiteral(string, 'opening') >>> abjad.attach(literal, include_container) >>> staff = abjad.Staff("c'4 d' e' f'", name='CustomStaff') >>> container = abjad.Container( ... [include_container, staff], ... is_simultaneous=True, ... ) >>> lilypond_file = abjad.LilyPondFile.new( ... container, ... lilypond_language_token=False, ... lilypond_version_token=False, ... ) >>> del(lilypond_file.items[:3])
>>> abjad.f(lilypond_file) \score { << { \include "layout.ly" } \context Staff = "CustomStaff" { c'4 d'4 e'4 f'4 } >> }
>>> lilypond_file[abjad.Staff] Staff("c'4 d'4 e'4 f'4", name='CustomStaff')
>>> lilypond_file['CustomStaff'] Staff("c'4 d'4 e'4 f'4", name='CustomStaff')
Returns item.
Raises key error when no item with
name
is found.
-
__illustrate__
()¶ Illustrates LilyPond file.
Returns LilyPond file unchanged.
-
__repr__
()¶ Gets interpreter representation of LilyPond file.
Gets interpreter representation:
>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file LilyPondFile(comments=[], 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.82'))
Returns string.
Class & static methods
-
classmethod
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
>>> abjad.f(lilypond_file) \version "2.19.82" \language "english" \header { tagline = ##f 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 } >> }
>>> abjad.show(lilypond_file)
Wraps
music
in LilyPond\score
block.Adds LilyPond
\header
,\layout
,\paper
and\score
blocks to LilyPond file.Returns LilyPond file.
-
classmethod
rhythm
(selections, divisions=None, attach_lilypond_voice_commands=None, implicit_scaling=None, pitched_staff=None, simultaneous_selections=None, time_signatures=None)¶ Makes rhythm-styled LilyPond file.
Makes rhythmic staff:
>>> divisions = [(3, 4), (4, 8), (1, 4)] >>> maker = abjad.NoteMaker() >>> selections = [ ... maker(6 * [0], [(1, 8)]), ... maker(8 * [0], [(1, 16)]), ... maker(2 * [0], [(1, 8)]), ... ] >>> for selection in selections: ... abjad.attach(abjad.Beam(), selection[:]) ... >>> lilypond_file = abjad.LilyPondFile.rhythm( ... selections, ... divisions, ... ) >>> abjad.show(lilypond_file)
Set time signatures explicitly:
>>> divisions = [(3, 4), (4, 8), (1, 4)] >>> maker = abjad.NoteMaker() >>> selections = [ ... maker(6 * [0], [(1, 8)]), ... maker(8 * [0], [(1, 16)]), ... maker(2 * [0], [(1, 8)]), ... ] >>> for selection in selections: ... abjad.attach(abjad.Beam(), selection[:]) ... >>> lilypond_file = abjad.LilyPondFile.rhythm( ... selections, ... [(6, 8), (4, 8), (2, 8)], ... ) >>> abjad.show(lilypond_file)
Makes pitched staff:
>>> divisions = [(3, 4), (4, 8), (1, 4)] >>> maker = abjad.NoteMaker() >>> selections = [ ... maker(6 * [0], [(1, 8)]), ... maker(8 * [0], [(1, 16)]), ... maker(2 * [0], [(1, 8)]), ... ] >>> for selection in selections: ... abjad.attach(abjad.Beam(), selection[:]) ... >>> lilypond_file = abjad.LilyPondFile.rhythm( ... selections, ... divisions, ... pitched_staff=True, ... ) >>> abjad.show(lilypond_file)
Makes simultaneous voices:
>>> divisions = [(3, 4), (4, 8), (1, 4)] >>> maker = abjad.NoteMaker() >>> selections = [ ... maker(6 * [0], [(1, 8)]), ... maker(8 * [0], [(1, 16)]), ... maker(2 * [0], [(1, 8)]), ... ] >>> for selection in selections: ... abjad.attach(abjad.Beam(), selection[:]) ... >>> for note in abjad.iterate(selections).components(abjad.Note): ... note.written_pitch = abjad.NamedPitch("e'") ... >>> selection_1 = selections[0] + selections[1] + selections[2] >>> selections = [ ... maker(12 * [0], [(1, 16)]), ... maker(16 * [0], [(1, 32)]), ... maker(4 * [0], [(1, 16)]), ... ] >>> for selection in selections: ... abjad.attach(abjad.Beam(), selection[:]) ... >>> selection_2 = selections[0] + selections[1] + selections[2] >>> 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.LilyPondLiteral(r'\voiceOne'), voice_1) >>> voice_2 = lilypond_file['Voice 2'] >>> abjad.attach(abjad.LilyPondLiteral(r'\voiceTwo'), voice_2) >>> abjad.show(lilypond_file)
Returns LilyPond file.
Read-only properties
-
comments
¶ Gets comments of Lilypond file.
Gets comments:
>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.comments []
Returns list.
-
date_time_token
¶ Gets date-time token.
Gets date-time token:
>>> lilypond_file = abjad.LilyPondFile.new(date_time_token=True)
>>> lilypond_file.date_time_token DateTimeToken()
Returns date-time token or none.
-
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.
-
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.
-
header_block
¶ Gets header block.
Gets header block:
>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.header_block <Block(name='header')>
Returns block or none.
-
includes
¶ Gets includes of LilyPond file.
Gets includes:
>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.includes []
Return list
-
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')>
Accepts strings:
>>> staff = abjad.Staff("c'4 d' e' f'") >>> score_block = abjad.Block(name='score') >>> score_block.items.append(staff) >>> lilypond_file = abjad.LilyPondFile( ... lilypond_language_token=False, ... lilypond_version_token=False, ... ) >>> string = r'\customCommand' >>> lilypond_file.items.append(string) >>> lilypond_file.items.append(score_block)
>>> abjad.f(lilypond_file) \customCommand \score { \new Staff { c'4 d'4 e'4 f'4 } }
Returns list:
>>> isinstance(lilypond_file.items, list) True
Returns list.
-
layout_block
¶ Gets layout block.
Gets layout block:
>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.layout_block <Block(name='layout')>
Returns block or none.
-
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.
-
lilypond_version_token
¶ Gets LilyPond version token.
Gets LilyPond version token:
>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.lilypond_version_token LilyPondVersionToken('2.19.82')
Returns LilyPond version token or none.
-
paper_block
¶ Gets paper block.
Gets paper block:
>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.paper_block <Block(name='paper')>
Returns block or none.
-
score_block
¶ Gets score block.
Gets score block:
>>> lilypond_file = abjad.LilyPondFile.new()
>>> lilypond_file.score_block <Block(name='score')>
Returns block or none.
-
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.
-