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

Verticality.makeElement unpitched aware #1678

Merged
merged 2 commits into from
Jan 3, 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
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
Loading