Skip to content

Commit

Permalink
Simplify ChordBase duration creation
Browse files Browse the repository at this point in the history
  • Loading branch information
TimFelixBeyer committed Feb 27, 2024
1 parent 0927e39 commit 80adf72
Showing 1 changed file with 9 additions and 17 deletions.
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

0 comments on commit 80adf72

Please sign in to comment.