From 80adf72a1a869985e939662eae3e18ade7e2e208 Mon Sep 17 00:00:00 2001 From: TimFelix <35711942+TimFelixBeyer@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:24:28 +0100 Subject: [PATCH] Simplify ChordBase duration creation --- music21/chord/__init__.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/music21/chord/__init__.py b/music21/chord/__init__.py index db050b439..934d4e7a0 100644 --- a/music21/chord/__init__.py +++ b/music21/chord/__init__.py @@ -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 @@ -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