abjad.obgc

abjad.obgc.on_beat_grace_container(...[, ...])

Wraps grace_leaves in on-beat grace container; wraps nongrace_leaves in voice ("nongrace voice"); wraps on-beat grace container and nongrace voice in container ("polyphony container").

abjad.obgc.OnBeatGraceContainer([...])

On-beat grace container.

abjad.obgc.on_beat_grace_container(grace_leaves: str | Sequence[Leaf], nongrace_leaves: Sequence[Leaf], *, do_not_attach_one_voice_command: bool = False, do_not_beam: bool = False, do_not_slash: bool = False, do_not_slur: bool = False, grace_font_size: int = -3, grace_leaf_duration: Duration | None = None, grace_polyphony_command: VoiceNumber = VoiceNumber(n=1, leak=False), nongrace_polyphony_command: VoiceNumber = VoiceNumber(n=2, leak=False), tag: Tag = Tag(string='')) OnBeatGraceContainer[source]

Wraps grace_leaves in on-beat grace container; wraps nongrace_leaves in voice (“nongrace voice”); wraps on-beat grace container and nongrace voice in container (“polyphony container”).

>>> def make_lilypond_file(nongrace_leaves_string, obgc_string, *, below=False):
...     music_voice = abjad.Voice(nongrace_leaves_string, name="MusicVoice")
...     if below is False:
...         nongrace_polyphony_command = abjad.VoiceNumber(2)
...         grace_polyphony_command = abjad.VoiceNumber(1)
...     else:
...         nongrace_polyphony_command = abjad.VoiceNumber(1)
...         grace_polyphony_command = abjad.VoiceNumber(2)
...     obgc = abjad.on_beat_grace_container(
...         obgc_string,
...         music_voice[1:3],
...         grace_leaf_duration=abjad.Duration(1, 30),
...         grace_polyphony_command=grace_polyphony_command,
...         nongrace_polyphony_command=nongrace_polyphony_command,
...     )
...     staff = abjad.Staff([music_voice])
...     lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
...     return lilypond_file
... 

GRACE NOTES ABOVE.

Note-to-note anchor:

>>> lilypond_file = make_lilypond_file(
...     "c'4 d' e' f'",
...     "g'8 a' b' c'' d'' c'' b' a' b' c'' d''",
... )
>>> abjad.show(lilypond_file)  

Note-to-chord anchor:

>>> lilypond_file = make_lilypond_file(
...     "<a c'>4 <b d'> <c' e'> <d' f'>",
...     "g'8 a' b' c'' d'' c'' b' a' b' c'' d''",
... )
>>> abjad.show(lilypond_file)  

Chord-to-note anchor:

>>> lilypond_file = make_lilypond_file(
...     "c'4 d' e' f'",
...     "<g' b'>8 a' b' c'' d'' c'' b' a' b' c'' d''",
... )
>>> abjad.show(lilypond_file)  

Chord-to-chord anchor:

>>> lilypond_file = make_lilypond_file(
...     "<a c'>4 <b d'> <c' e'> <d' f'>",
...     "<g' b'>8 a' b' c'' d'' c'' b' a' b' c'' d''",
... )
>>> abjad.show(lilypond_file)  

GRACE NOTES BELOW.

Note-to-note anchor:

>>> lilypond_file = make_lilypond_file(
...     "c'4 d' e' f'",
...     "g8 a b c' d' c' b a b c' d'",
...     below=True,
... )
>>> abjad.show(lilypond_file)  

Note-to-chord anchor:

>>> lilypond_file = make_lilypond_file(
...     "<c' e'>4 <d' f'> <e' g'> <f' a'>",
...     "g8 a b c' d' c' b a b c' d'",
...     below=True,
... )
>>> abjad.show(lilypond_file)  

Chord-to-note anchor:

>>> lilypond_file = make_lilypond_file(
...     "c'4 d' e' f'",
...     "<e g>8 a b c' d' c' b a b c' d'",
...     below=True,
... )
>>> abjad.show(lilypond_file)  

Chord-to-chord anchor:

>>> lilypond_file = make_lilypond_file(
...     "<c' e'>4 <d' f'> <e' g'> <f' a'>",
...     "<e g>8 a b c' d' c' b a b c' d'",
...     below=True,
... )
>>> abjad.show(lilypond_file)  

Todo

Fix stem-alignment in two examples, above.

class abjad.obgc.OnBeatGraceContainer(components: str | Sequence[Leaf] = (), *, grace_leaf_duration: Duration | None = None, identifier: str | None = None, name: str | None = None, tag: Tag | None = None)[source]

On-beat grace container.

Note

On-beat grace containers must be included in a named voice.

On-beat grace containers implement custom formatting not available in LilyPond:

>>> music_voice = abjad.Voice("c'4 d'4 e'4 f'4", name="MusicVoice")
>>> string = "<d' g'>8 a' b' c'' d'' c'' b' a' b' c'' d''"
>>> obgc = abjad.on_beat_grace_container(
...     string, music_voice[1:3], grace_leaf_duration=(1, 24)
... )
>>> abjad.attach(abjad.Articulation(">"), obgc[0])
>>> staff = abjad.Staff([music_voice])
>>> lilypond_file = abjad.LilyPondFile([r'\include "abjad.ily"', staff])
>>> abjad.show(lilypond_file)  

attach_lilypond_one_voice()

Attaches LilyPond \oneVoice command.

get_first_nongrace_leaf()

Gets first nongrace leaf.

get_nongrace_voice()

Gets nongrace voice.

get_polyphony_container()

Gets polyphony container.

grace_leaf_duration

Gets grace leaf duration.

match_first_nongrace_leaf()

Matches first nongrace leaf.

set_grace_leaf_multipliers()

Sets grace leaf multipliers.

attach_lilypond_one_voice() None[source]

Attaches LilyPond \oneVoice command.

get_first_nongrace_leaf() Leaf[source]

Gets first nongrace leaf.

get_nongrace_voice() Voice[source]

Gets nongrace voice.

get_polyphony_container() Container[source]

Gets polyphony container.

grace_leaf_duration

Gets grace leaf duration.

match_first_nongrace_leaf() None[source]

Matches first nongrace leaf.

set_grace_leaf_multipliers() None[source]

Sets grace leaf multipliers.