Skip to content

makeTies raises KeyError when bridging a string voice id absent from the next measure #2024

Description

@rdebroiz

music21 version

master

Operating System(s) checked

any

Problem summary

makeRests(fillGaps=True) fills a gap in a voice with a rest of the gap's full length,
unclamped. If that rest crosses a barline, makeTies splits it and looks for the same voice in the next measure. When the voice is not there, the lookup raises instead of falling back, and the export dies.

Steps to reproduce

from music21 import note, stream

p = stream.Part()
m1 = stream.Measure()
v = stream.Voice(id='6')
v.insert(0, note.Note(quarterLength=1))
v.insert(5, note.Note(quarterLength=1))   # gap 1->5 runs past the 4.0 barline
m1.insert(0, v)
m2 = stream.Measure()
m2.insert(0, stream.Voice(id='1'))        # has a voice, but not '6'
p.append(m1)
p.append(m2)
p.write('musicxml')                       # KeyError: '6'

More information

With id=6 and id=1 as integers, the same score exports fine.

if not isinstance(vId, int):
    dst = mNext.voices[vId]          # subscript: raises on a miss
else:
    dst = mNext.getElementById(vId)  # returns None on a miss
...
if dst is None:
    dst = mNext                      # fallback the str branch never reaches

Suggested fix, so the string branch reaches the fallback that already exists:

dst = mNext.voices[vId] if vId in [voice.id for voice in mNext.voices] else None

Related:

#922 added this makeTies call to makeRests to "split rests at measure boundaries"
#890 asks "what happens if it ends and then begins again?"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions