Skip to content

Commit c024eee

Browse files
Back out previous fix, make a better fix.
1 parent 8a5d74b commit c024eee

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

musicdiff/comparison.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,13 +1214,13 @@ def _notes_set_distance(original: list[AnnNote], compare_to: list[AnnNote]):
12141214
if unpaired_orig_notes:
12151215
for an in unpaired_orig_notes:
12161216
cost += an.notation_size()
1217-
op_list.append(("notedel", an, None, an.notation_size()))
1217+
op_list.append(("notedel", an, None, an.notation_size(), an.note_idx_in_chord))
12181218

12191219
# noteins
12201220
if unpaired_comp_notes:
12211221
for an in unpaired_comp_notes:
12221222
cost += an.notation_size()
1223-
op_list.append(("noteins", None, an, an.notation_size()))
1223+
op_list.append(("noteins", None, an, an.notation_size(), an.note_idx_in_chord))
12241224

12251225
# notesub
12261226
if paired_notes:

musicdiff/visualization.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,11 @@ def mark_diffs(
655655
if t.TYPE_CHECKING:
656656
assert noteOrChord2 is not None
657657
if len(op) >= 5 and op[4] is not None:
658+
if not isinstance(noteOrChord2, m21.chord.ChordBase):
659+
# Can happen if imported xml has repeated xml:id values,
660+
# so getElementById returns an unexpected GeneralNote.
661+
# Don't crash, but we won't color the note either.
662+
continue
658663
note2 = noteOrChord2.notes[op[4]]
659664
else:
660665
note2 = noteOrChord2
@@ -676,6 +681,11 @@ def mark_diffs(
676681
if t.TYPE_CHECKING:
677682
assert noteOrChord1 is not None
678683
if len(op) >= 5 and op[4] is not None:
684+
if not isinstance(noteOrChord1, m21.chord.ChordBase):
685+
# Can happen if imported xml has repeated xml:id values,
686+
# so getElementById returns an unexpected GeneralNote.
687+
# Don't crash, but we won't color the note either.
688+
continue
679689
note1 = noteOrChord1.notes[op[4]]
680690
else:
681691
note1 = noteOrChord1
@@ -2365,6 +2375,11 @@ def get_text_output(
23652375
if t.TYPE_CHECKING:
23662376
assert noteOrChord2 is not None
23672377
if len(op) >= 5 and op[4] is not None:
2378+
if not isinstance(noteOrChord2, m21.chord.ChordBase):
2379+
# Can happen if imported xml has repeated xml:id values,
2380+
# so getElementById returns an unexpected GeneralNote.
2381+
# Don't crash, but we won't color the note either.
2382+
continue
23682383
note2 = noteOrChord2.notes[op[4]]
23692384
else:
23702385
note2 = noteOrChord2
@@ -2384,6 +2399,11 @@ def get_text_output(
23842399
if t.TYPE_CHECKING:
23852400
assert noteOrChord1 is not None
23862401
if len(op) >= 5 and op[4] is not None:
2402+
if not isinstance(noteOrChord1, m21.chord.ChordBase):
2403+
# Can happen if imported xml has repeated xml:id values,
2404+
# so getElementById returns an unexpected GeneralNote.
2405+
# Don't crash, but we won't color the note either.
2406+
continue
23872407
note1 = noteOrChord1.notes[op[4]]
23882408
else:
23892409
note1 = noteOrChord1

0 commit comments

Comments
 (0)