Skip to content

Commit f82a14e

Browse files
authored
Merge pull request #1691 from TimFelixBeyer/patch-13
Fix #1382: Simplify ChordBase duration creation
2 parents c5e3ca3 + 80adf72 commit f82a14e

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

music21/chord/__init__.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,17 @@ def __init__(self,
138138
# if provided.
139139

140140
super().__init__(**keywords)
141-
142-
# inherit Duration object from GeneralNote
143-
# keep it here in case we have no notes
144-
durationKeyword = None
145-
if 'duration' in keywords:
146-
durationKeyword = keywords['duration']
147-
148-
durationKeyword = self._add_core_or_init(notes, useDuration=durationKeyword)
149-
150-
if durationKeyword is not None:
151-
self.duration = durationKeyword
152-
elif 'type' in keywords or 'quarterLength' in keywords: # dots dont cut it
153-
self.duration = Duration(**keywords)
154-
141+
# Normally, we inherit Duration object from GeneralNote
142+
# It is overridden here in case no chord duration is specified
143+
if not any(k in keywords for k in ('duration', 'type', 'quarterLength')):
144+
self._add_core_or_init(notes, useDuration=None)
145+
else:
146+
self._add_core_or_init(notes, useDuration=self.duration)
155147

156148
def __eq__(self, other):
157149
if not super().__eq__(other):
158150
return False
159-
if not len(self.notes) == len(other.notes):
151+
if len(self.notes) != len(other.notes):
160152
return False
161153
return True
162154

@@ -237,13 +229,13 @@ def _add_core_or_init(self,
237229
elif isinstance(n, ChordBase):
238230
for newNote in n._notes:
239231
self._notes.append(copy.deepcopy(newNote))
240-
if quickDuration is True:
232+
if quickDuration:
241233
self.duration = n.duration
242234
useDuration = None
243235
quickDuration = False
244236
elif isinstance(n, note.NotRest):
245237
self._notes.append(n)
246-
if quickDuration is True:
238+
if quickDuration:
247239
self.duration = n.duration
248240
useDuration = None
249241
quickDuration = False

0 commit comments

Comments
 (0)