There are a few main reasons I know of for changing the enharmonic spellings of notes:
To avoid accidentals when natural notes are available (i.e. F and B, not E# and Cb)
To limit accidentals (i.e. prefer D and Eb, not C## and Fbb)
To make note names agree with the intervals they're being raised/lowered by (i.e. C, D, E, not Dbb, D, D##)
In many cases these goals can conflict, for example in the case of the "diminished whole-half" scale. This scale has eight notes and is not diatonic to a key, so it cannot be spelled "correctly"; it will always contain duplicate letter names.
In other cases, "correct" enharmonic spelling may be avoided as a matter of idiomatic preference. The flat-V7 chord in Db major would technically be Abb7, but no jazz musician would actually spell the chord this way; they'd write G7 instead. Preferring to limit spellings to single accidentals is a fairly common use case.
PitchClass.asNaturalOrRaisedOnce and PitchClass.asNaturalOrLoweredOnce are, I believe, intended to accomplish goal 2 above. However, these functions force a user to choose between sharps and flats when this is not always best, and don't allow a user to express his/her preferences in terms of the above goals.
I think a better approach for an enharmonic respeller function would be to generate multiple enharmonic spellings of the same PitchClass and choose between them based on a config parameter. This would allow for the end user to make high-level decisions for how enharmonic spellings should be chosen.
There are a few main reasons I know of for changing the enharmonic spellings of notes:
In many cases these goals can conflict, for example in the case of the "diminished whole-half" scale. This scale has eight notes and is not diatonic to a key, so it cannot be spelled "correctly"; it will always contain duplicate letter names.
In other cases, "correct" enharmonic spelling may be avoided as a matter of idiomatic preference. The flat-V7 chord in Db major would technically be Abb7, but no jazz musician would actually spell the chord this way; they'd write G7 instead. Preferring to limit spellings to single accidentals is a fairly common use case.
PitchClass.asNaturalOrRaisedOnce
andPitchClass.asNaturalOrLoweredOnce
are, I believe, intended to accomplish goal 2 above. However, these functions force a user to choose between sharps and flats when this is not always best, and don't allow a user to express his/her preferences in terms of the above goals.I think a better approach for an enharmonic respeller function would be to generate multiple enharmonic spellings of the same
PitchClass
and choose between them based on a config parameter. This would allow for the end user to make high-level decisions for how enharmonic spellings should be chosen.