Skip to content

Commit

Permalink
Merge pull request #1678 from cuthbertLab/supersede-1652
Browse files Browse the repository at this point in the history
Verticality.makeElement unpitched aware
  • Loading branch information
mscuthbert authored Jan 3, 2024
2 parents eab94f1 + a5f5f2d commit e2ec77f
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions music21/tree/verticality.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,14 @@ def newNote(ts, n: note.Note) -> note.Note:

offsetDifference = common.opFrac(self.offset - ts.offset)
endTimeDifference = common.opFrac(ts.endTime - (self.offset + quarterLength))
if t.TYPE_CHECKING:
assert endTimeDifference is not None

# noinspection PyTypeChecker
if offsetDifference == 0 and endTimeDifference <= 0:
addTie = None
elif offsetDifference > 0:
# noinspection PyTypeChecker
if endTimeDifference > 0:
addTie = 'continue'
else:
Expand Down Expand Up @@ -869,26 +874,32 @@ def conditionalAdd(ts, n: note.Note) -> None:
if not isinstance(timeSpan, spans.PitchedTimespan):
continue
el = timeSpan.element
if isinstance(el, chord.Chord):
if len(el) == 0:
if isinstance(el, chord.ChordBase):
firstNoteElement: note.Note | None = None
for subEl in el:
if isinstance(subEl, note.Note):
firstNoteElement = subEl
break

if firstNoteElement is None:
continue

if el.articulations or el.expressions:
firstSubEl = copy.deepcopy(el[0]) # this makes an additional deepcopy
firstSubEl.articulations += el.articulations
firstSubEl.expressions += el.expressions
# make a deepcopy of the first note element
# adding all articulations and expressions from the Chord to it.
originalPitch = firstNoteElement.pitch
firstNoteElement = copy.deepcopy(firstNoteElement)
firstNoteElement.articulations += el.articulations
firstNoteElement.expressions += el.expressions
if not copyPitches:
firstSubEl.pitch = el[0].pitch
else:
firstSubEl = el[0]
conditionalAdd(timeSpan, firstSubEl)
firstNoteElement.pitch = originalPitch
conditionalAdd(timeSpan, firstNoteElement)

if len(el) > 1:
for subEl in list(el)[1:]:
conditionalAdd(timeSpan, subEl)
else:
if t.TYPE_CHECKING:
assert isinstance(el, note.Note)
if isinstance(subEl, note.Note):
conditionalAdd(timeSpan, subEl)
elif isinstance(el, note.Note):
conditionalAdd(timeSpan, el)

seenArticulations = set()
Expand Down

0 comments on commit e2ec77f

Please sign in to comment.