Better line breaking algorithm
This might be a huge request with need for some discussion, therefore I post here first instead of directly to GitHub. Also, I don’t know anything about the line breaking code yet.
The line breaking should be improved. I always wondered why the last system doesn’t fill the whole line width by default – until I saw this comment pointing me to the relevant setting in the style preferences which I had not know before. I don’t think I have ever seen well engraved music that doesn’t fill the last line. So the first part of my feature request is: Change the “Last system fill threshold” default setting to 0%.
But then you’ll see that the measures are not evenly distributed. Instead it looks like there is some greedy algorithm making line-breaks that are locally optimal but not globally. I don’t know how other Music notation software does this but I’ve heard that TeX/LaTeX uses some sort of Dijkstra algorithm to optimize line breaking (shortest way in a graph consisting of nodes = possible line breaks and edges = resulting line lengths).
Maybe one could have a look at the LilyPond line breaking code? LilyPond has several options, see attached pdf. MuseScore’s default behaviour is something like LilyPond’s “ragged-last = true if last system is filled 30% or less”.
Attachment | Size |
---|---|
Line_breaking_LilyPond.pdf | 30.98 KB |
Comments
FWIW, When I enter your example in 4.1.1, the result is just like your 3rd example. I haven't changed any settings.
In reply to FWIW, When I enter your… by bobjp
That’s right. Maybe the example I chose is not the best to show my point. Have a look at a 16 measure empty score and “Twinkle twinkle little star” instead:
MuseScore empty score, spacing is much denser in the first line than in the second line (11+5 measures):
MuseScore song, last line does not fill the whole line width (7+8+1 measures):
LilyPond empty score, spacing is more even (8+8 measures):
LilyPond song, the score fits on two lines (7+9 measures):
Both the empty score (uneven spacing) and the song (short last line) make a bad impression to a first time user. And as I said above I didn’t even realise there is a setting to avoid a short last line until yesterday. However, even if this is used one has to manually adjust the spacing because just setting the “last line fill threshold” to 0% leads to the following ugliness:
Tonight I had an idea what might stand against having a fancy line breaking algorithm by default: It is time-consuming. Both TeX and LilyPond are programs that compile some code to layouted (?) text/sheet music when the user triggers the compilation. And at least in the case of music this seems to be a hard problem, line and page breaking takes much of LilyPond’s compilation time. That’s of course not an option for a WYSIWYG program.
So if “optimal” line breaking is not possible in the WYSIWYG context one could have at least some small improvements that don’t consume much computing power? And maybe an option to trigger an advanced line breaking manually and saving the results as a new type of line break markers (so that you can see the difference between user-set line breaks and algorithmically set line breaks).