Skip to content

Commit

Permalink
Added abjad.IndependentAfterGraceContainer. Tag #1125.
Browse files Browse the repository at this point in the history
CHANGED. Cleaned up abjad.spanners.glissando() overrides.

    OLD: abjad.glissando() included spurious blocks like this on
    length-2 glissandi; these settings did nothing:

        \hide NoteHead
        \override Accidental.stencil = ##f
        \override NoteColumn.glissando-skip = ##t
        \override NoteHead.no-ledgers = ##t
        \revert Accidental.stencil
        \revert NoteColumn.glissando-skip
        \revert NoteHead.no-ledgers
        \undo \hide NoteHead

    NEW: abjad.glissando() no longer includes these blocks on length-2
    glissandi.

    REMOVED. Removed abjad.spanners.glissando(..., style=None) keyword.

        OLD: abjad.spanners.glissand(..., style="trill")
        NEW: Use abjad.Tweak(r"- \tweak style #'trill")

Makefile update: changed "make pytest" to "pytest tests". Newer versions
of pytest (eg, 8.1.1) error on "pytest ." because of duplicate
conftest.py, conf.py files in the abjad/abjad and abjad/tests.

    OLD: "make pytest" defined equal to "pytest ."
    NEW: "make pytest" defined equal to "pytest tests"
  • Loading branch information
trevorbaca committed Mar 28, 2024
1 parent 1eb11b6 commit f2200b7
Show file tree
Hide file tree
Showing 12 changed files with 1,316 additions and 54 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ mypy:
project = abjad

pytest:
pytest .
pytest tests

pytest-coverage:
rm -Rf htmlcov/
pytest \
--cov-config=.coveragerc \
--cov-report=html \
--cov=${project} \
.
tests

pytest-x:
pytest -x .
pytest -x tests

reformat:
make black-reformat
Expand Down
2 changes: 2 additions & 0 deletions abjad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
Container,
Context,
DrumNoteHead,
IndependentAfterGraceContainer,
Leaf,
MultimeasureRest,
Note,
Expand Down Expand Up @@ -345,6 +346,7 @@
"Harpsichord",
"Horizontal",
"ImpreciseMetronomeMarkError",
"IndependentAfterGraceContainer",
"Infinity",
"Instrument",
"InstrumentName",
Expand Down
2 changes: 2 additions & 0 deletions abjad/_getlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def _get_effective(


def _get_grace_container(component):
# _score.IndependentAfterGraceContainer is excluded here;
# exclusion allows iteration to work correctly
prototype = (
_score.AfterGraceContainer,
_score.BeforeGraceContainer,
Expand Down
4 changes: 4 additions & 0 deletions abjad/_iterlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ def _get_sibling_with_graces(component, n):
candidate = component._parent[index]
if n == 1 and getattr(candidate, "_before_grace_container", None):
return candidate._before_grace_container[0]
if n == 1 and candidate.__class__.__name__ == "IndependentAfterGraceContainer":
return candidate[0]
if n == -1 and getattr(candidate, "_after_grace_container", None):
return candidate._after_grace_container[-1]
if n == -1 and candidate.__class__.__name__ == "IndependentAfterGraceContainer":
return candidate[-1]
return candidate


Expand Down
37 changes: 37 additions & 0 deletions abjad/_updatelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,35 @@ def _get_before_grace_leaf_offsets(leaf):
return start_offset, stop_offset


def _get_independent_after_grace_leaf_offsets(leaf):
container = leaf._parent
main_leaf = container._sibling(-1)
main_leaf_stop_offset = main_leaf._stop_offset
assert main_leaf_stop_offset is not None
displacement = -leaf._get_duration()
sibling = leaf._sibling(1)
while sibling is not None and sibling._parent is container:
displacement -= sibling._get_duration()
sibling = sibling._sibling(1)
"""
if leaf._parent is not None and leaf._parent._sibling(-1) is not None:
main_leaf = leaf._parent._sibling(-1)
sibling = main_leaf._sibling(1)
if (
sibling is not None
and hasattr(sibling, "_before_grace_container")
and sibling._before_grace_container is not None
):
before_grace_container = sibling._before_grace_container
duration = before_grace_container._get_duration()
displacement -= duration
"""
start_offset = _duration.Offset(main_leaf_stop_offset, displacement=displacement)
displacement += leaf._get_duration()
stop_offset = _duration.Offset(main_leaf_stop_offset, displacement=displacement)
return start_offset, stop_offset


def _get_measure_start_offsets(component):
wrappers = []
prototype = _indicators.TimeSignature
Expand Down Expand Up @@ -323,9 +352,17 @@ def _update_component_offsets(component):
start_offset = pair[0]
pair = _get_after_grace_leaf_offsets(component[-1])
stop_offset = pair[-1]
elif isinstance(component, _score.IndependentAfterGraceContainer):
pair = _get_independent_after_grace_leaf_offsets(component[0])
start_offset = pair[0]
pair = _get_independent_after_grace_leaf_offsets(component[-1])
stop_offset = pair[-1]
elif isinstance(component._parent, _score.AfterGraceContainer):
pair = _get_after_grace_leaf_offsets(component)
start_offset, stop_offset = pair
elif isinstance(component._parent, _score.IndependentAfterGraceContainer):
pair = _get_independent_after_grace_leaf_offsets(component)
start_offset, stop_offset = pair
else:
previous = component._sibling(-1)
if previous is not None:
Expand Down
1 change: 1 addition & 0 deletions abjad/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ def list_all_classes(modules="abjad", ignored_classes=None):
<class 'abjad.score.Container'>
<class 'abjad.score.Context'>
<class 'abjad.score.DrumNoteHead'>
<class 'abjad.score.IndependentAfterGraceContainer'>
<class 'abjad.score.Leaf'>
<class 'abjad.score.MultimeasureRest'>
<class 'abjad.score.Note'>
Expand Down
Loading

0 comments on commit f2200b7

Please sign in to comment.