An issue of deciding stem lengths with tremolos
As you probably know, 3.5 optimizes the default layout regarding tremolos. However, there's still a tricky issue which I so far cannot diagnose properly. It's about how a stem length should be lengthened when there's a single-note tremolo on it.
The smart algorithm I introduced works well in most cases, because it makes use of a very effective variable: the distance between tremolo strikes and a certain note. This can help calculate the stem lengths so that they look nice most of the time. The problem is, what note should we use, the one furthest to the tremolo strokes, or the one nearest? Intuitively speaking, I would choose the furthest, because a stem ends on that note. But when I tried it, it didn't always work:
if (up()) height = downPos() - _tremolo->pos().y(); else height = _tremolo->pos().y() + _tremolo->height() - upPos();
Apparently, the stems of the beamed chords are lengthened twice the amount needed.
But when I change it to the nearest note, the stem of the unbeamed chord isn't lengthened enough.
if (up()) height = upPos() - _tremolo->pos().y(); else height = _tremolo->pos().y() + _tremolo->height() - downPos();
I tried to understand the main code (
Chord::defaultStemLength()) of deciding default stem lengths, and from what I saw, the stem length of a chord does include the distance between notes, which means my first speculation should've been correct. Besides this function, I cannot find another one which decides stem lengths or doubles them when the chords are beamed.
I ended up writing my part of the code like this:
if (up()) height = (beam() ? upPos() : downPos()) - _tremolo->pos().y(); else height = _tremolo->pos().y() + _tremolo->height() - (beam() ? downPos() : upPos());
It seems to work nicely. But I wonder whether there's a more logical solution, as I cannot find clear logic in this one.