Skip to content

Commit

Permalink
Cleaned up indicator attachment.
Browse files Browse the repository at this point in the history
It's now possibly to (probably incorrectly) attach two identical
indicators to the same leaf.

This is an intermediate step in cleaning up indicator attachment.
  • Loading branch information
trevorbaca committed Apr 11, 2023
1 parent f0ae90f commit fdc4407
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
10 changes: 5 additions & 5 deletions abjad/_getlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _get_grace_container(component):


def _get_indicator(
component,
component: _score.Component,
prototype: _typings.Prototype | None = None,
*,
default: typing.Any | None = None,
Expand All @@ -214,10 +214,10 @@ def _get_indicator(
return list(indicators)[0]
else:
name = getattr(prototype, "__name__", "")
strings = "\n".join([str(_) for _ in indicators])
raise Exception(
f"{len(indicators)} {name} indicators attached to component:\n{strings}"
)
strings = "\n".join([" " + str(_) for _ in indicators])
string = f"{len(indicators)} {name} indicators attached to {component}:"
string += f"\n{strings}"
raise Exception(string)


def _get_leaf_from_leaf(leaf, n):
Expand Down
12 changes: 3 additions & 9 deletions abjad/bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,12 @@ def _bind_component(self, component, check_duplicate_indicator=False):
indicator = self.indicator.indicator
else:
indicator = self.indicator
# if getattr(self.indicator, "context", None) is not None:
if getattr(indicator, "context", None) is not None:
if check_duplicate_indicator is True:
self._warn_duplicate_indicator(component)
self._unbind_component()
self._component = component
self._update_effective_context()
# if getattr(self.indicator, "_mutates_offsets_in_seconds", False):
if getattr(indicator, "_mutates_offsets_in_seconds", False):
self._component._update_later(offsets_in_seconds=True)
component._wrappers.append(self)
Expand All @@ -342,7 +340,6 @@ def _bind_effective_context(self, correct_effective_context):
indicator = self.indicator.indicator
else:
indicator = self.indicator
# if getattr(self.indicator, "_mutates_offsets_in_seconds", False):
if getattr(indicator, "_mutates_offsets_in_seconds", False):
correct_effective_context._update_later(offsets_in_seconds=True)

Expand Down Expand Up @@ -389,7 +386,9 @@ def _get_effective_context(self):
return self._effective_context

def _unbind_component(self):
if self._component is not None and self in self._component._wrappers:
if self._component is not None and id(self) in [
id(_) for _ in self._component._wrappers
]:
self._component._wrappers.remove(self)
self._component = None

Expand Down Expand Up @@ -1266,10 +1265,8 @@ def detach(argument, target=None, by_id=False):
if isinstance(wrapper, argument):
target._wrappers.remove(wrapper)
result.append(wrapper)
# elif isinstance(wrapper.indicator, argument):
elif isinstance(wrapper.unbundle_indicator(), argument):
wrapper._detach()
# result.append(wrapper.indicator)
result.append(wrapper.get_item())
result = tuple(result)
return result
Expand All @@ -1285,16 +1282,13 @@ def detach(argument, target=None, by_id=False):
if wrapper is argument:
wrapper._detach()
result.append(wrapper)
# elif wrapper.indicator == argument:
elif wrapper.unbundle_indicator() == argument:
# if by_id is True and id(argument) != id(wrapper.indicator):
if by_id is True and id(argument) != id(
wrapper.unbundle_indicator()
):
pass
else:
wrapper._detach()
# result.append(wrapper.indicator)
result.append(wrapper.get_item())
result = tuple(result)
return result
Expand Down

0 comments on commit fdc4407

Please sign in to comment.