Skip to content

Commit

Permalink
Remove selector=None keyword from abjad.spanners.* functions.
Browse files Browse the repository at this point in the history
Closes #1589.
  • Loading branch information
trevorbaca committed Jan 1, 2025
1 parent 9435b5f commit eff6fc1
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 53 deletions.
2 changes: 1 addition & 1 deletion abjad/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4299,7 +4299,7 @@ class RepeatTie:
>>> wrapper = abjad.get.indicator(voice[1], abjad.RepeatTie, unwrap=False)
>>> wrapper.get_item()
Bundle(indicator=RepeatTie(), tweaks=(Tweak(string='- \\tweak color #blue', i=None, tag=None),))
Bundle(indicator=RepeatTie(), tweaks=(Tweak(string='- \\tweak color #blue', i=None, tag=None),), comment=None)
>>> for leaf in voice:
... leaf, abjad.get.logical_tie(leaf)
Expand Down
129 changes: 80 additions & 49 deletions abjad/spanners.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ def beam(
beam_rests: bool | None = True,
direction: _enums.Vertical | None = None,
durations: typing.Sequence[_duration.Duration] | None = None,
selector: typing.Callable = lambda _: _select.leaves(_),
span_beam_count: int | None = None,
start_beam: _indicators.StartBeam | None = None,
start_beam: _indicators.StartBeam | _tweaks.Bundle | None = None,
stemlet_length: int | float | None = None,
stop_beam: _indicators.StopBeam | None = None,
tag: _tag.Tag | None = None,
Expand Down Expand Up @@ -141,8 +140,6 @@ def beam(
}
"""
assert callable(selector)
argument = selector(argument)
original_leaves = list(_iterate.leaves(argument))
silent_prototype = (_score.MultimeasureRest, _score.Rest, _score.Skip)

Expand Down Expand Up @@ -320,7 +317,6 @@ def glissando(
allow_ties: bool = False,
hide_middle_note_heads: bool = False,
hide_middle_stems: bool = False,
hide_stem_selector: typing.Callable | None = None,
left_broken: bool = False,
parenthesize_repeats: bool = False,
right_broken: bool = False,
Expand Down Expand Up @@ -1073,10 +1069,6 @@ def _previous_leaf_changes_current_pitch(leaf):
return False
return True

should_hide_stem = []
if hide_stem_selector is not None:
should_hide_stem = hide_stem_selector(argument)

leaves = _select.leaves(argument)
total = len(leaves) - 1
for i, leaf in enumerate(leaves):
Expand Down Expand Up @@ -1105,13 +1097,6 @@ def _previous_leaf_changes_current_pitch(leaf):
if _next_leaf_changes_current_pitch(leaf):
if _is_last_in_tie_chain(leaf):
should_attach_glissando = True
if leaf in should_hide_stem:
strings = [
r"\once \override Dots.transparent = ##t",
r"\once \override Stem.transparent = ##t",
]
literal = _indicators.LilyPondLiteral(strings, site="before")
_bind.attach(literal, leaf, tag=tag.append(_tag.Tag("abjad.glissando(-1)")))
if hide_middle_note_heads and 3 <= len(leaves):
if leaf is not leaves[0]:
should_attach_glissando = False
Expand Down Expand Up @@ -1228,7 +1213,6 @@ def hairpin(
argument: _score.Component | typing.Sequence[_score.Component],
*,
direction: _enums.Vertical | None = None,
selector: typing.Callable = lambda _: _select.leaves(_),
tag: _tag.Tag | None = None,
) -> None:
r"""
Expand Down Expand Up @@ -1367,8 +1351,6 @@ def hairpin(
if start_dynamic is not None:
assert isinstance(start_dynamic, _indicators.Dynamic), repr(start_dynamic)

assert callable(selector)
argument = selector(argument)
leaves = _select.leaves(argument)
start_leaf = leaves[0]
stop_leaf = leaves[-1]
Expand All @@ -1384,8 +1366,7 @@ def hairpin(
def horizontal_bracket(
argument: _score.Component | typing.Sequence[_score.Component],
*,
selector: typing.Callable = lambda _: _select.leaves(_),
start_group: _indicators.StartGroup | None = None,
start_group: _indicators.StartGroup | _tweaks.Bundle | None = None,
stop_group: _indicators.StopGroup | None = None,
tag: _tag.Tag | None = None,
) -> None:
Expand All @@ -1395,6 +1376,7 @@ def horizontal_bracket(
.. container:: example
>>> voice = abjad.Voice("c'4 d' e' f'")
>>> voice.consists_commands.append("Horizontal_bracket_engraver")
>>> abjad.horizontal_bracket(voice[:])
>>> abjad.show(voice) # doctest: +SKIP
Expand All @@ -1403,6 +1385,10 @@ def horizontal_bracket(
>>> string = abjad.lilypond(voice)
>>> print(string)
\new Voice
\with
{
\consists Horizontal_bracket_engraver
}
{
c'4
\startGroup
Expand All @@ -1412,11 +1398,77 @@ def horizontal_bracket(
\stopGroup
}
.. container:: example
Bundle start-group indicators to tweak the padding and outside-staff priority
of nested analysis brackets:
>>> voice = abjad.Voice("c'4 d' e' f' c' d' e' f'")
>>> voice.consists_commands.append("Horizontal_bracket_engraver")
>>> bundle = abjad.bundle(
... abjad.StartGroup(),
... r"- \tweak color #red",
... r"- \tweak padding 1.5",
... comment="% lexical order 1"
... )
>>> abjad.horizontal_bracket(voice[:4], start_group=bundle)
>>> bundle = abjad.bundle(
... abjad.StartGroup(),
... r"- \tweak color #red",
... r"- \tweak padding 1.5",
... comment="% lexical order 1"
... )
>>> abjad.horizontal_bracket(voice[4:], start_group=bundle)
>>> bundle = abjad.bundle(
... abjad.StartGroup(),
... r"- \tweak color #blue",
... r"- \tweak outside-staff-priority 801",
... r"- \tweak padding 1.5",
... comment="% lexical order 0"
... )
>>> abjad.horizontal_bracket(voice[:], start_group=bundle)
>>> abjad.show(voice) # doctest: +SKIP
.. docs::
>>> string = abjad.lilypond(voice)
>>> print(string)
\new Voice
\with
{
\consists Horizontal_bracket_engraver
}
{
c'4
% lexical order 0
- \tweak color #blue
- \tweak outside-staff-priority 801
- \tweak padding 1.5
\startGroup
% lexical order 1
- \tweak color #red
- \tweak padding 1.5
\startGroup
d'4
e'4
f'4
\stopGroup
c'4
% lexical order 1
- \tweak color #red
- \tweak padding 1.5
\startGroup
d'4
e'4
f'4
\stopGroup
\stopGroup
}
"""
start_group = start_group or _indicators.StartGroup()
stop_group = stop_group or _indicators.StopGroup()
assert callable(selector)
argument = selector(argument)
leaves = _select.leaves(argument)
start_leaf = leaves[0]
stop_leaf = leaves[-1]
Expand All @@ -1427,7 +1479,6 @@ def horizontal_bracket(
def ottava(
argument: _score.Component | typing.Sequence[_score.Component],
*,
selector: typing.Callable = lambda _: _select.leaves(_),
start_ottava: _indicators.Ottava = _indicators.Ottava(n=1),
stop_ottava: _indicators.Ottava = _indicators.Ottava(n=0, site="after"),
tag: _tag.Tag | None = None,
Expand Down Expand Up @@ -1458,8 +1509,6 @@ def ottava(
"""
assert isinstance(start_ottava, _indicators.Ottava), repr(start_ottava)
assert isinstance(stop_ottava, _indicators.Ottava), repr(stop_ottava)
assert callable(selector)
argument = selector(argument)
leaves = _select.leaves(argument)
start_leaf = leaves[0]
stop_leaf = leaves[-1]
Expand All @@ -1471,8 +1520,7 @@ def phrasing_slur(
argument: _score.Component | typing.Sequence[_score.Component],
*,
direction: _enums.Vertical | None = None,
selector: typing.Callable = lambda _: _select.leaves(_),
start_phrasing_slur: _indicators.StartPhrasingSlur | None = None,
start_phrasing_slur: _indicators.StartPhrasingSlur | _tweaks.Bundle | None = None,
stop_phrasing_slur: _indicators.StopPhrasingSlur | None = None,
tag: _tag.Tag | None = None,
) -> None:
Expand Down Expand Up @@ -1503,8 +1551,6 @@ def phrasing_slur(
"""
start_phrasing_slur = _indicators.StartPhrasingSlur()
stop_phrasing_slur = _indicators.StopPhrasingSlur()
assert callable(selector)
argument = selector(argument)
leaves = _select.leaves(argument)
start_leaf = leaves[0]
stop_leaf = leaves[-1]
Expand All @@ -1518,8 +1564,7 @@ def piano_pedal(
argument: _score.Component | typing.Sequence[_score.Component],
*,
context: str | None = None,
selector: typing.Callable = lambda _: _select.leaves(_),
start_piano_pedal: _indicators.StartPianoPedal | None = None,
start_piano_pedal: _indicators.StartPianoPedal | _tweaks.Bundle | None = None,
stop_piano_pedal: _indicators.StopPianoPedal | None = None,
tag: _tag.Tag | None = None,
) -> None:
Expand Down Expand Up @@ -1556,8 +1601,6 @@ def piano_pedal(
"""
start_piano_pedal = start_piano_pedal or _indicators.StartPianoPedal()
stop_piano_pedal = stop_piano_pedal or _indicators.StopPianoPedal()
assert callable(selector)
argument = selector(argument)
leaves = _select.leaves(argument)
start_leaf = leaves[0]
stop_leaf = leaves[-1]
Expand All @@ -1569,8 +1612,7 @@ def slur(
argument: _score.Component | typing.Sequence[_score.Component],
*,
direction: _enums.Vertical | None = None,
selector: typing.Callable = lambda _: _select.leaves(_),
start_slur: _indicators.StartSlur | None = None,
start_slur: _indicators.StartSlur | _tweaks.Bundle | None = None,
stop_slur: _indicators.StopSlur | None = None,
tag: _tag.Tag | None = None,
) -> None:
Expand Down Expand Up @@ -1601,8 +1643,6 @@ def slur(
"""
start_slur = start_slur or _indicators.StartSlur()
stop_slur = stop_slur or _indicators.StopSlur()
assert callable(selector)
argument = selector(argument)
leaves = _select.leaves(argument)
start_leaf = leaves[0]
stop_leaf = leaves[-1]
Expand All @@ -1614,8 +1654,7 @@ def text_spanner(
argument: _score.Component | typing.Sequence[_score.Component],
*,
direction: _enums.Vertical | None = None,
selector: typing.Callable = lambda _: _select.leaves(_),
start_text_span: _indicators.StartTextSpan | None = None,
start_text_span: _indicators.StartTextSpan | _tweaks.Bundle | None = None,
stop_text_span: _indicators.StopTextSpan | None = None,
tag: _tag.Tag | None = None,
) -> None:
Expand Down Expand Up @@ -1746,8 +1785,6 @@ def text_spanner(
"""
start_text_span = start_text_span or _indicators.StartTextSpan()
stop_text_span = stop_text_span or _indicators.StopTextSpan()
assert callable(selector)
argument = selector(argument)
leaves = _select.leaves(argument)
start_leaf = leaves[0]
stop_leaf = leaves[-1]
Expand All @@ -1760,7 +1797,6 @@ def tie(
*,
direction: _enums.Vertical | None = None,
repeat: bool | tuple[int, int] | typing.Callable = False,
selector: typing.Callable = lambda _: _select.leaves(_),
tag: _tag.Tag | None = None,
) -> None:
r"""
Expand Down Expand Up @@ -1964,8 +2000,6 @@ def inequality(item):
def inequality(item):
return item >= _duration.Duration(repeat)

assert callable(selector)
argument = selector(argument)
leaves = _select.leaves(argument)
if len(leaves) < 2:
raise Exception(f"must be two or more notes (not {leaves!r}).")
Expand All @@ -1989,8 +2023,7 @@ def inequality(item):
def trill_spanner(
argument: _score.Component | typing.Sequence[_score.Component],
*,
selector: typing.Callable = lambda _: _select.leaves(_),
start_trill_span: _indicators.StartTrillSpan | None = None,
start_trill_span: _indicators.StartTrillSpan | _tweaks.Bundle | None = None,
stop_trill_span: _indicators.StopTrillSpan | None = None,
tag: _tag.Tag | None = None,
) -> None:
Expand Down Expand Up @@ -2020,8 +2053,6 @@ def trill_spanner(
"""
start_trill_span = start_trill_span or _indicators.StartTrillSpan()
stop_trill_span = stop_trill_span or _indicators.StopTrillSpan()
assert callable(selector)
argument = selector(argument)
leaves = _select.leaves(argument)
start_leaf = leaves[0]
stop_leaf = leaves[-1]
Expand Down
11 changes: 8 additions & 3 deletions abjad/tweaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Bundle:

indicator: typing.Any
tweaks: tuple[Tweak, ...] = ()
comment: str | None = None

def __post_init__(self):
assert not isinstance(self.indicator, Bundle), repr(self.indicator)
Expand All @@ -90,6 +91,7 @@ def __post_init__(self):
for attribute in attributes:
if 1 < attributes.count(attribute):
raise Exception(f"duplicate {attribute!r} attribute.")
assert isinstance(self.comment, str | None), repr(self.comment)

def _get_contributions(self, *, component=None, wrapper=None):
try:
Expand All @@ -107,6 +109,8 @@ def _get_contributions(self, *, component=None, wrapper=None):
assert len(lists) == 1, repr(lists)
list_ = lists[0]
strings = []
if self.comment is not None:
strings.append(self.comment)
for tweak in sorted(self.tweaks):
strings.extend(tweak._list_contributions())
if 2 <= len(list_) and list_[-2] in ("^", "_", "-"):
Expand Down Expand Up @@ -153,7 +157,7 @@ def remove(self, tweak: Tweak) -> "Bundle":
>>> bundle_2 = bundle_1.remove(tweak)
>>> bundle_2
Bundle(indicator=Markup(string='\\markup Allegro'), tweaks=())
Bundle(indicator=Markup(string='\\markup Allegro'), tweaks=(), comment=None)
>>> bundle_3 = abjad.bundle(bundle_2, r"- \tweak color #blue")
>>> bundle_3.tweaks
Expand All @@ -170,8 +174,9 @@ def remove(self, tweak: Tweak) -> "Bundle":
def bundle(
indicator: typing.Any,
*tweaks: str | Tweak,
tag: _tag.Tag | None = None,
comment: str | None = None,
overwrite: bool = False,
tag: _tag.Tag | None = None,
) -> Bundle:
r"""
Bundles ``indicator`` with ``tweaks``.
Expand Down Expand Up @@ -321,7 +326,7 @@ def bundle(
indicator = indicator.indicator
input_tweaks = bundle_tweaks
input_tweaks.sort()
return Bundle(indicator, tweaks=tuple(input_tweaks))
return Bundle(indicator, tweaks=tuple(input_tweaks), comment=comment)


def tweak(
Expand Down

0 comments on commit eff6fc1

Please sign in to comment.