cuthbertLab / music21

music21 is a Toolkit for Computational Musicology
https://www.music21.org/
Other
2.05k stars 390 forks source link

Measure.rightBarline not being correctly set when appending bar.Repeat #1703

Open ggsimao opened 3 months ago

ggsimao commented 3 months ago

music21 version

9.1.0

Problem summary When appending an object like bar.Repeat(direction="end") to a measure object, the barline attributes of that measure object aren't being correctly set.

Steps to reproduce

>>> m1 = stream.Measure()
>>> m2 = stream.Measure()
>>> repeat_b = bar.Repeat(direction="start")
>>> repeat_e = bar.Repeat(direction="end")
>>> m1.append(repeat_b)
>>> m1.leftBarline
<music21.bar.Repeat direction=start>
>>> m1.rightBarline
>>> m2.append(repeat_e)
>>> m2.rightBarline
>>> m2.leftBarline
<music21.bar.Repeat direction=end>
>>> r1 = note.Rest("whole")
>>> r2 = note.Rest("whole")
>>> m1 = stream.Measure()
>>> m2 = stream.Measure()
>>> m1.append(repeat_b)
>>> m1.append(r1)
>>> m2.append(r2)
>>> m2.append(repeat_e)
>>> m1.leftBarline
<music21.bar.Repeat direction=start>
>>> m1.rightBarline
>>> m2.rightBarline
>>> m2.leftBarline
>>> 

Expected vs. actual behavior When appending a bar.Repeat object with direction=="end" to a measure, the rightBarline attribute should receive it as its value. Instead, it sets leftBarline sometimes and not rightBarline.

OS is Linux Mint 21.2. I'd fix it myself, but I can't find where the attributes are being set when appending the bar.Repeat object. If anyone can help in that regard, that would be much appreciated.

Edit: Apparently this is because Measure._getRightBarline() only checks for elements of _endElements, and I'm assuming append() doesn't modify this attribute. Not sure if this is the intended behavior.

TimFelixBeyer commented 2 months ago

As a workaround you can try using storeAtEnd instead of append. I agree that append should probably be smarter about this though.