elm-music / music-theory

Principled library for working with intervals and pitch classes
BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

Different approach to choosing enharmonic spellings #10

Closed duncanmalashock closed 6 years ago

duncanmalashock commented 6 years ago

There are a few main reasons I know of for changing the enharmonic spellings of notes:

  1. To avoid accidentals when natural notes are available (i.e. F and B, not E# and Cb)
  2. To limit accidentals (i.e. prefer D and Eb, not C## and Fbb)
  3. 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.

duncanmalashock commented 6 years ago

for example:

type alias SpellingConfig =
  { preferNaturalNotes : Bool
  , maxAccidentals: Int
  }

respell : SpellingConfig -> PitchClass -> PitchClass