Skip to content
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

Fix #1382: Simplify ChordBase duration creation #1691

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions music21/chord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,17 @@ def __init__(self,
# if provided.

super().__init__(**keywords)

# inherit Duration object from GeneralNote
# keep it here in case we have no notes
durationKeyword = None
if 'duration' in keywords:
durationKeyword = keywords['duration']

durationKeyword = self._add_core_or_init(notes, useDuration=durationKeyword)

if durationKeyword is not None:
self.duration = durationKeyword
elif 'type' in keywords or 'quarterLength' in keywords: # dots dont cut it
self.duration = Duration(**keywords)

# Normally, we inherit Duration object from GeneralNote
# It is overridden here in case no chord duration is specified
if not any(k in keywords for k in ('duration', 'type', 'quarterLength')):
self._add_core_or_init(notes, useDuration=None)
else:
self._add_core_or_init(notes, useDuration=self.duration)

def __eq__(self, other):
if not super().__eq__(other):
return False
if not len(self.notes) == len(other.notes):
if len(self.notes) != len(other.notes):
return False
return True

Expand Down Expand Up @@ -237,13 +229,13 @@ def _add_core_or_init(self,
elif isinstance(n, ChordBase):
for newNote in n._notes:
self._notes.append(copy.deepcopy(newNote))
if quickDuration is True:
if quickDuration:
self.duration = n.duration
useDuration = None
quickDuration = False
elif isinstance(n, note.NotRest):
self._notes.append(n)
if quickDuration is True:
if quickDuration:
self.duration = n.duration
useDuration = None
quickDuration = False
Expand Down
Loading