Improvements to zoom functionality

• Jun 9, 2020 - 12:22
Reported version
Ergonomical (UX)
S4 - Minor

This issue documents an upcoming pull request that makes several significant usability improvements to the zoom functionality in MuseScore, and also fixes a few bugs. Although there are several different changes contained here, the code for them is all intertwined and it would have been difficult and time-consuming to attempt to separate them all into separate PRs.

Zoom box rounding

The zoom box in the toolbar now shows the zoom level rounded to the nearest even integer (i.e., using “banker's rounding”). The true floating-point value is maintained internally but nicely sanitized for display purposes.

Keyboard and mouse zoom precision and consistency

Keyboard and mouse zooming used to be implemented in separate code paths and used unrelated factors for each zoom step (1.7 for the keyboard and 1.1 for the mouse). Both of these values resulted in “random”-seeming zoom levels that were also different depending on whether the user was using the keyboard or the mouse.

For example, here are the keyboard zoom steps (when starting at 100%) that were displayed in the toolbar as the user zoomed in and out:

5% (minimum), 7.04296%, 11.973%, 20.3542%, 34.6021%, 58.8235%, 100%, 170%, 289%, 491.3%, 835.21%, 1419.86%, 1600% (maximum)

And here is an excerpt of the mouse zoom steps (low and high values omitted for the sake of brevity):

… 46.6507%, 51.3158%, 56.4474%, 62.0921%, 68.3013%, 75.1315%, 82.6446%, 90.9091%, 100%, 110%, 121%, 133.1%, 146.41%, 161.051%, 177.156%, 194.872%, 214.359% …

The numbers in boldface are round numbers that correspond to individually selectable zoom presets. Note that there are none at all except for 100% (and 1600%, but only because it's been clamped to the maximum allowed value).

This has been changed so that keyboard and mouse zooming go through exactly the same code path and both use step factors that are nth roots of two. This has the nice effect of producing zoom levels that include all powers of two (in both directions) and that nicely correspond between keyboard and mouse.

Here are the new default keyboard zoom steps (as displayed to the user):

6%, 9%, 12%, 18%, 25%, 35%, 50%, 71%, 100%, 141%, 200%, 283%, 400%, 566%, 800%, 1131%, 1600%

And here are the new default mouse zoom steps (again with low and high values omitted):

50%, 56%, 63%, 71%, 79%, 89%, 100%, 112%, 126%, 141%, 159%, 178%, 200%

Note that both the keyboard and mouse steps now contain all powers of two, and also contain in-between values (such as 71% and 141%) that exactly correspond to each other. This makes it easy to switch between keyboard and mouse zooming while maintaining a consistent sequence of zoom steps.

The number of steps it takes to double the zoom level is the nth root of two, where n has been dubbed the zoom “precision” and is now individually configurable for keyboard and mouse on the Canvas tab of the MuseScore Preferences dialog. The default values for the keyboard and mouse zoom precision are 2 and 6, respectively (producing step factors of ~1.41 and ~1.12); these values have been chosen because they are close in feel to the old step factors (1.7 and 1.1.)

Finally, the zoom-level limits have been changed from 5–1600% to 6.25–1600%. This has been done because 0.0625 is a power of two, which makes it possible to zoom all the way out and then back in while passing through the exact same zoom steps. (Previously, if the user zoomed all the way out to 5%, zooming back in would go through a completely different set of zoom steps.) Additionally, because 0.625 the reciprocal of 16, it means there will always be an equal number of zoom steps in each direction away from 100% before hitting the limit.

Moved zoom preferences

The existing zoom-related preferences have been moved from the Score tab to the Canvas tab of the MuseScore Preferences dialog, joined by the new preferences for keyboard and mouse zoom precision. All zoom preferences are now saved in workspaces as GUI preferences.

Fixed zoom-box 100% selection bug

When the preset 100% zoom level was selected, there was a bug that sometimes caused the free-zoom item in the toolbar zoom box to become selected instead of the preset 100% item. This has been fixed.

Fixed accumulated rounding errors

The now-unified keyboard and mouse zoom-stepping code has been improved to eliminate floating-point rounding errors that would accumulate as the user repeatedly zoomed in and out.

Fixed score-shifting bug

There was a bug that sometimes caused the score to shift to the right and/or downwards for no apparent reason when the user zoomed out a few times using the keyboard. This has been fixed. (Thanks to Matt McClinch for this one.)

Internal: Renamed “zoom”, “magnification”, and “scale” to “zoom level”

The MuseScore codebase inconsistently used multiple terms (“zoom”, “magnification”, and “scale”) to refer to the same thing: the zoom level. This was incredibly confusing, especially because the terms “magnification” and “scale” are also used for various completely different things throughout the codebase. All of the instances relating to the zoom level have been renamed accordingly. The one exception is XML tags, which retain their old names for compatibility reasons.

Note that it was necessary to call it “zoom level” rather an simply “zoom” in order to clearly distinguish it from the “zoom type” (Page Width, Whole Page, etc.).

Additionally, there are two types of zoom level that MuseScore keeps track of internally: the logical zoom level (e.g., 100%) and the physical level (which is the zoom level scaled according to the user's physical screen size for rendering purposes). These two types of zoom levels are converted back and forth to each other all over the place with very little consistency in naming. These have now explicitly been renamed for the purpose of clarity.

Internal: Minor cleanup

Some additional minor cleanup has been done to code that is directly related to the other changes.


Status PR created fixed

Fixed in branch 3.x, commit 846c3706fa

_Fix #306509: Improvements to zoom functionality

Made several significant usability improvements to the zoom functionality, and also fixed several bugs.

Although there are several different changes contained here, the code for them is all intertwined and it would have been difficult and time-consuming to attempt to separate them all into separate PRs._

Fix version