Improve the staff hiding algorithm to allow custom control and bottom alignment
Steps to reproducethe issue:
1) Create a full orchestral score that occupies the whole page
2) Select the "Hide empty staves within systems" option from the Format / Style / Score menu
3) Enter some notes on slightly more than half the total number of staves on enough measures to reach two or more pages.
4) The empty staves on the second page will be hidden, causing the system to occupy lss than the available space but slightly more than half page. Hence, a large blank space will be left below the system.
5) If the number of hidden staves on different pages is different, the blank space will be of variable height.
(This issue originated in the following forum discussion: https://musescore.org/en/comment/938187#comment-938187)
The "hide empty staves within systems" feature is very handy to save space and to allow more music to be included on each page, if that is possible. However, as the feature is currently implemented, it causes potential blank spaces at the bottom of pages and, to make matters worse, these blank spaces may present different heights causing an uneven presentation. The way the leading publishing houses solve this involves two steps: 1) Selectively unhiding some empty staves and 2) adjusting the staff distance so that the last staff is flush with the botom margin.
Step 1 usually follows some criteria such as unhiding empty staves that were not empty in the previous system or will not be empty in the next one, or unhiding groups of related instruments such as French horns, woodwinds, etc. Besides, there is always room for custom selection according to the engraver's criterion and experience.
Step 2 is attained by distributing the space that would remain between the lower staff and the bottom margin into the staff space between consecutive staves. This space will usually be quite small if after step 1 only a fraction of staff + staff space is left below the lower staff.
To allow MuseScore render scores according to the preceding considerations, two main changes are necessary:
1) There must be a way to unhide hidden staves. This may be partially automatic in order to get a reasonable first approximation, and partially manual to allow fine tuning of the general layout.
2) There must be a way to change the staff distance. Currently this is fixed and can only be changed automtically by the autoplacement algorithm in certain cases and manually through spacers. One way would be to replace the Systen distance setting (from the Format / Style / Score dialog) with a minimum and a maximum value
Taking these changes for granted, there are two situations: automatic and manual empty staff hiding / unhiding.
Automatic algorithm proposal
Assuming that Hide empty staves within system has been checked, the following proceeds sequentially starting on page 2. Page 1 usually shows all the staves, regardless of being empty or not, but if not, start on page 1
1) If after hiding empty staves a page has a blank below the last system that is smaller than 20 % of the page (or other suitable percentage, which could be a preference), then stretch the space between staves so that the last staff is aligned with the bottom margin.
2) If it is larger than 20 %, unhide some staves according to the following rules:
a) For each empty staff check if in the previous system it was unhidden; if so count the number of empty measures in that staff at the end of the last system, taking inf (infinite) or a very large number if the complete staff was also empty. Assign that number to an index Ai where i is the number of staff. If no previous system, set Ai = inf.
b) For each empty staff check if in the next system it is not empty; if so, count the number of empty measures in that staff at the beginning of the next system and assign it to an index Bi. If no next system, set Bi = inf
c) Define Ci as the minimum between Ai and Bi.
d) Unhide the empty staves starting from the one with the smaller Ci (i.e., the one having closer non-empty measures). If there are more than one with the same Ci, prefer those staves corresponding to bowed instruments, then brass, then woodwinds, then percussion. NOTE: The order of preference could also be an option
e) Keep unhiding staves until condition 1) is fulfilled and proceed as indicated there.
Manual hide/unhide mangement
The proposal is to add two new items to the contextual menu that opens when right-clicking on an empty part of a staff:
1) Hide / Unhide empty staves in this system, which would be similar to the Format / Style / Score corresponding preference, but more readily accessible and within the compass of the current system only. The typical use is to turn all staves visible to allow selecting which one is to be kept visible in spite of being empty.
2) Hide/Unhide this staff if empty. When Hide is selected, a flag is activated allowing the global setting to take control, so when 1) is activated, the staff in the current system will be hidden if empty. When Unhide is selected, the flag is cleared and the current staff in the current system wil remain visible overriding the global setting.
Staff distance can be increased using spacers. They can be selected in group and their height changed at once from the inspector.
A staff can be unhidden adding an invisible voice with disabled playback.