I did some changes to remove code duplication and hence improve maintainability because when refining the beaming logic, the code doesn't have to be changed in multiple places.
It sort of reverses the logic, i.e. instead of starting from a <note>/<chord>/<rest> and looking for a corresponding <beam>/<beamSpan>, the keys start at the <beam>/<beamSpan>s and find the elements they are anchored to. I expect this to be more efficient because:
there are less <beam>/<beamSpan> elements than <note>s/<chord>s/<rest>s elements - i.e. the number of tests should be lower
when starting from <note>/<chord>/<rest>, we don't know whether a beam was specified using <beam>s or <beamSpan>, so we have to check for both things. When starting from <beam>/<beamSpan> this problem does not occur.
This new solution is also more robust. In the also included beams test case, the first beam fails to render correctly as the last element in it is a <handShift> - which is a perfectly valid (though maybe not a very clever) place to put a <handShift>.
A similar approach could be taken e.g. for slurs and hairpins.
Maybe a similar approach could work for a number of things including tuplets, slurs and hairpins. I'll see what I can do, but right now I'm not sure when.
I did some changes to remove code duplication and hence improve maintainability because when refining the beaming logic, the code doesn't have to be changed in multiple places.
It sort of reverses the logic, i.e. instead of starting from a
<note>
/<chord>
/<rest>
and looking for a corresponding<beam>
/<beamSpan>
, the keys start at the<beam>
/<beamSpan>
s and find the elements they are anchored to. I expect this to be more efficient because:<beam>
/<beamSpan>
elements than<note>
s/<chord>
s/<rest>
s elements - i.e. the number of tests should be lower<note>
/<chord>
/<rest>
, we don't know whether a beam was specified using<beam>
s or<beamSpan>
, so we have to check for both things. When starting from<beam>
/<beamSpan>
this problem does not occur.This new solution is also more robust. In the also included beams test case, the first beam fails to render correctly as the last element in it is a
<handShift>
- which is a perfectly valid (though maybe not a very clever) place to put a<handShift>
.A similar approach could be taken e.g. for slurs and hairpins.