-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid creating duplicative ChordStepModifications #1509
Conversation
Prevents comparing two CSM's as unequal if one has interval P1 and the other None.
476c0bd
to
dbd943e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good to me -- the problem with the default P1 interval though seems an issue; people love to transpose intervals inPlace and then our default is gone. Once that's in, feel free to merge.
music21/harmony.py
Outdated
self._interval = None # alteration of degree, alter ints in mxl | ||
self._degree = None # the degree number, where 3 is the third | ||
# use properties if defined | ||
def __init__(self, modType=None, degree=None, intervalObj=interval.Interval('P1')): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not so sure about this change because Interval is mutable. We definitely need an immutable flag on Interval so that this default value isn't ever transposed inPlace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! 34aa5da
music21/harmony.py
Outdated
# use properties if defined | ||
def __init__(self, modType=None, degree=None, intervalObj=interval.Interval('P1')): | ||
self._modType: str | None = None # add, alter, subtract | ||
self._interval: interval.Interval | None = None # alteration of degree, alter ints in mxl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to make it so _interval is always an Interval and never None? Helps with the typing.
self._degree = None # the degree number, where 3 is the third | ||
# use properties if defined | ||
def __init__(self, modType=None, degree=None, intervalObj=interval.Interval('P1')): | ||
self._modType: str | None = None # add, alter, subtract |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can use ''
for None going forward. There were a lot of str | None in the code before typing became a thing but now it's biting us.
def _adjustPitchesForChordStepModifications(self, pitches): | ||
def _adjustPitchesForChordStepModifications( | ||
self, pitches: t.Iterable[pitch.Pitch] | ||
) -> list[pitch.Pitch]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal method. change of type is fine.
Fixes #1500 by not creating duplicative ChordStepModifications.
Also:
_adjustPitchesForChordStepModifications()