cuthbertLab/music21

Missing humdrumPosition in thisSpine.stream.flatten() with root cause analysis

Opened this issue · 1 comments

music21 version

9.1.0

Problem summary

Loaded a krn format into music21 and received the following error message:

AttributeError: 'Dynamic' object has no attribute 'humdrumPosition'

Steps to reproduce

from music21 import converter
score = converter.parse('http://kern.ccarh.org/data?l=beethoven/sonatas&file=sonata06-1.krn')

Expected vs. actual behavior

Expecting the Sonata to render but get error message instead.

Root Cause Analysis

After running the debugger, I noticed that when the parse() method from the DynamSpine class is run in line 1445, and when eventC = 'p', then a Dynamic object is created <music21.dynamics.Dynamic p>. This object has a humdrumPosition attribute. But this attribute is removed from the object in line 1811 (del el.humdrumPosition) which is why when trying to access this attribute in line 1947 (prioritiesToSearch[dynamic.humdrumPosition] = dynamic), we receive the error message.

In this particular sonata, I noticed that the dynamic object is the piano marking in the pickup measure. Curiously, if we remove this marking from the .krn file (line 21), then everything works as expected.

To summarize, it is likely that music21 has difficulty parsing dynamic markings found in pickup measures

Miscellaneous Information
Apple M1 Pro
macOS Sonoma 14.3.1

FWIW, there is an alternate Humdrum reader for music21 over in converter21, based on a port of Craig Sapp's humlib (used by Verovio) to Python.