musescore/MuseScore — pull request #1261 by MarcSabatella (2014-09-01 23:19:08+00:00)
Title: fix #31571: no key signature upon adding a transposing instrument to a C score

The main fix here is in instrdialog.cpp. This is where I check to see if there is an explicit key signature in the map at tick 0 in the source staff (the staff used to seed the key signatures in the added instruments), and add it if not.

However, things were in a very inconsistent state in terms of when and where "C" key signatures were created. For instance, upon creation of a new score, initial "C" key signatures are inserted - and saved in the MSCX file - but these were not added to the staves' maps, which was the cause of the current bug. Then, upon load of a file with explicit "C" key signatures, the key signatures were thrown away, with the result that loading and immediately re-saving a score would strip off the "C" key signatures that had originally been created. And there is a visible difference between a score with no key signature versus one with a "C" key signature. A score with no key signature at all has the time signature too close to the clef (compared with 1.3, and also compared to how Gould shows it). The "C" key signatures were stripped off as part of the fix to avoid *empty* keysig segments, but it was not necessary to strip them off completely just to avoid empty segments. And unless we fix the layout for staves with no key signatures at all, it seems harmful to remove them. There is also another bug with transpose by key that results from staves with no key signature at all - spurious accidentals created as a result of the missing key signature in the original.

So in the end, I elected to standardize on having "C" key signatures explicit both in the score and in the staves' key maps. With my changes, the "C" key signatures are created when new scores are, they are added to the staves' maps, they are saved, and they are preserved upon reload. This solves the bug with adding new transposing instruments, it also solves the accidentals-on-transposition issue, and it also solves the time signature layout issue. And even if we do encounter a score with no key signature at all, I still create a key signature for newly added transposing instruments. So the current bug is fixed either way.

The fix required updating a lot of tests to account for the fact that "C" key signatures present in the test files are no longer stripped off on read (basically, undoing that part of the change from a couple of weeks ago). I verified that nothing else in the tests changed. The one test that appeared to show a slightly bigger change was just a fluke of how diff reports the results.