Skip to content

Commit

Permalink
Added abjad.TextMark indicator.
Browse files Browse the repository at this point in the history
Tag #1572.
  • Loading branch information
trevorbaca committed Dec 8, 2023
1 parent 7669df8 commit 522dd99
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
2 changes: 2 additions & 0 deletions abjad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
StopSlur,
StopTextSpan,
StopTrillSpan,
TextMark,
Tie,
TimeSignature,
VoiceNumber,
Expand Down Expand Up @@ -466,6 +467,7 @@
"TenorSaxophone",
"TenorTrombone",
"TenorVoice",
"TextMark",
"Tie",
"TimeSignature",
"Timer",
Expand Down
1 change: 1 addition & 0 deletions abjad/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ def list_all_classes(modules="abjad", ignored_classes=None):
<class 'abjad.indicators.StopSlur'>
<class 'abjad.indicators.StopTextSpan'>
<class 'abjad.indicators.StopTrillSpan'>
<class 'abjad.indicators.TextMark'>
<class 'abjad.indicators.Tie'>
<class 'abjad.indicators.TimeSignature'>
<class 'abjad.indicators.VoiceNumber'>
Expand Down
108 changes: 107 additions & 1 deletion abjad/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2987,7 +2987,7 @@ def _get_contributions(self, component=None):
@dataclasses.dataclass(frozen=True, order=True, slots=True, unsafe_hash=True)
class RehearsalMark:
r"""
Rehearsal mark.
LilyPond ``\mark`` command.
.. container:: example
Expand Down Expand Up @@ -5872,6 +5872,112 @@ def _get_contributions(self, component=None):
return contributions


@dataclasses.dataclass(frozen=True, order=True, slots=True, unsafe_hash=True)
class TextMark:
r"""
LilyPond ``\textMark``, ``\textEndMark`` commands.
Text mark:
.. container:: example
>>> staff = abjad.Staff("c'4 d' e' f'")
>>> score = abjad.Score([staff])
>>> mark = abjad.TextMark(r'\textMark \markup \italic "V.S."')
>>> abjad.attach(mark, staff[-1])
>>> abjad.show(score) # doctest: +SKIP
.. docs::
>>> string = abjad.lilypond(score)
>>> print(string)
\new Score
<<
\new Staff
{
c'4
d'4
e'4
\textMark \markup \italic "V.S."
f'4
}
>>
Tweaks:
>>> staff = abjad.Staff("c'4 d' e' f'")
>>> score = abjad.Score([staff])
>>> mark = abjad.TextMark(r'\textMark \markup \italic "V.S."')
>>> bundle = abjad.bundle(mark, r"\tweak color #blue")
>>> abjad.attach(bundle, staff[-1])
>>> abjad.show(score) # doctest: +SKIP
.. docs::
>>> string = abjad.lilypond(score)
>>> print(string)
\new Score
<<
\new Staff
{
c'4
d'4
e'4
\tweak color #blue
\textMark \markup \italic "V.S."
f'4
}
>>
.. container:: example
Text end mark:
>>> staff = abjad.Staff("c'4 d' e' f'")
>>> score = abjad.Score([staff])
>>> mark = abjad.TextMark(r'\textEndMark \markup \italic "V.S."', site="after")
>>> abjad.attach(mark, staff[-1])
>>> abjad.show(score) # doctest: +SKIP
.. docs::
>>> string = abjad.lilypond(score)
>>> print(string)
\new Score
<<
\new Staff
{
c'4
d'4
e'4
f'4
\textEndMark \markup \italic "V.S."
}
>>
"""

string: str
_: dataclasses.KW_ONLY
site: str = "before"

# find_context_on_attach: typing.ClassVar[bool] = True
context: typing.ClassVar[str] = "Score"

def __post_init__(self):
assert isinstance(self.string, str), repr(self.string)

def _get_lilypond_format(self):
return self.string

def _get_contributions(self, component=None):
contributions = _contributions.ContributionsBySite()
site = getattr(contributions, self.site)
string = self._get_lilypond_format()
site.commands.append(string)
return contributions


@dataclasses.dataclass(frozen=True, order=True, slots=True, unsafe_hash=True)
class Tie:
r"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_class_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
abjad.Markup: (r"\markup Allegro",),
abjad.MetricModulation: (abjad.Note("c'4"), abjad.Note("c'4.")),
abjad.MetronomeMark: (abjad.Duration(1, 4), 90),
abjad.TextMark: (r'\textMark \markup \italic "V.S."',),
abjad.ShortInstrumentName: (r"\markup Vc.",),
abjad.StaffChange: ("RH_Staff",),
abjad.TimeSignature: ((4, 4),),
Expand Down

0 comments on commit 522dd99

Please sign in to comment.