musescore/MuseScore — pull request #596 by MarcSabatella (2013-12-17 17:23:15+00:00)
Title: fix #22131: bad diatonic transposition of Cb, Cbb

Walking through the code, the problem is clearly that pitch2absStepByKey returns the wrong value if the tpc parameter indicates Cb or Cbb. The octave is calculated based on the pitch only, and Cb / Cbb are at the very *end* of the octave. But the step value is calculated from the tpc as 0, since "C" is at the *beginning* of the octave. So depending on how you look at it, either the octave is off by one, or the step is off by seven.

There is probably a more elegant of reconciling this, but my proposed fix here does work, and seems safe since pitch2absStepByKey is only called in this one situation (diatonic transposition).