I'm currently creating a program to assist with realtime sheet music display from midi input (similar to what you see on many digital piano displays).

What is the most logical way for a user to select a key? Should I just list the major keys? I understand that some keys can be expressed as sharp or flat. Which is better to list? Or should I list both?

Below is the structure I've used currently.

I'm currently targetting piano/ keyboard, if that makes any difference.

const signatures = 
  { id: 'C',  key: 'C major', sharps: [], flats: [] },
  { id: 'G',  key: 'G major', sharps: [ 'f' ], flats: [] },
  { id: 'D',  key: 'D major', sharps: [ 'f', 'c' ], flats: [] },
  { id: 'A',  key: 'A major', sharps: [ 'f', 'c', 'g' ], flats: [] },
  { id: 'E',  key: 'E major', sharps: [ 'f', 'c', 'g', 'd' ], flats: [] },
  { id: 'B',  key: 'B major', sharps: [ 'f', 'c', 'g', 'd', 'a' ], flats: [] },
  { id: 'F',  key: 'F major', sharps: [], flats: [ 'b' ] },
  { id: 'Gm',  key: 'G minor', sharps: [], flats: [ 'b', 'e' ] },
  { id: 'Cm',  key: 'C minor', sharps: [], flats: [ 'b', 'e', 'a' ] },
  { id: 'Fm',  key: 'F minor', sharps: [], flats: [ 'b', 'e', 'a', 'd' ] },
  { id: 'DfM', key: 'D-flat major', sharps: [], flats: [ 'b', 'e', 'a', 'd', 'g' ] },
  { id: 'GfM', key: 'G-flat major', sharps: [], flats: [ 'b', 'e', 'a', 'd', 'g', 'c' ] },
  { id: 'CfM', key: 'C-flat major', sharps: [], flats: [ 'b', 'e', 'a', 'd', 'g', 'c', 'f' ] },
  • 1
    Where are F sharp major and C sharp major, especially since C flat major is fair game in your structure?
    – Dekkadeci
    Commented Jun 22, 2018 at 6:07
  • 4
    The MIDI values will be the same for F# and Gb, but the notation will obviously be different since one is a sharp key and the other is a flat key. If you want to be as flexible as possible, then you should list all of the enharmonic variants. If you provided more detail in your question I think we’d be able to help you more. By the way, I’m also a programmer who develops midi-based apps (objective C for the Mac).
    – 02fentym
    Commented Jun 22, 2018 at 6:28
  • Thanks @02fentym, I guess my question is: What is the most logical way to list these (for selection by a user), and store their associated sharps and flats? My goal being to ommit the sharps and flats from the notation if they are in the selected key signature.
    – blairyeah
    Commented Jun 22, 2018 at 6:31
  • 2
    I’m still not entirely sure about the purpose behind all of this. You can handle it programmatically. For instance, if you have an array that stores the distance (in semitones) between each degree of a major scale, you can construct any major scale. It might look like this: {2, 4, 5, 7, 9, 11}.
    – 02fentym
    Commented Jun 22, 2018 at 6:43
  • 1
    You must list both sharp and flat keys. For example, whilst Gb and F# majors will sound pretty much the same - exactly in 12edo, they are deemed to be different keys. Omitting them from the notation when they're in the key sig. is exactly how they work in real music!
    – Tim
    Commented Jun 22, 2018 at 7:25

1 Answer 1


This observation may or may not be helpful. I have found it useful when teaching the piano, especially to beginners, always to use seven accidentals in every key-signature. Firstly, I usually teach the player how to play a chromatic scale (because it's easy) from D to D (because it is symmetrical when played in contrary motion and both hands can be used at the same time. Most children and adults can soon work out that it also works from A flat. Most children learn C major first, but it is a difficult scale to play, particularly for smaller hands. However, pieces using two hands in the key of C can be excellent starters, especially if they utilise simple five-finger positions. I also encourage improvisation on the black keys using fingers 2 and 3 of each hand on the groups of two black keys, and fingers 2,3 and 4 on the groups of three. So here are the main points:

  1. C major has seven naturals. A beginner is soon able to play and name them. With knowledge of the chromatic scale, they can easily learn the simple structure of a major scale. (I introduce the naturals in the same order as the sharps: F,C,G,D,A,E,B - for fun we use a mnemonic 'Father Charles Goes Down And Ends Battle')

  2. Every major scale has a NATURAL minor 'hidden inside' beginning on the 6th note. Whilst this is a great opportunity to begin playing with major/minor triads, there is no need to introduce harmonic or melodic variations for ages (although AB theory books and most piano examining boards do not seem to acknowledge the existence of the natural minor scale in the early grades). It is simple for the beginner to really understand the relationship between the major and relative minor scales (i.e. they are both the same, sharing the same selection of notes, and the same key-signature).

  3. The first major scale played is C FLAT major. This is simple to play compared with C major, and the key-signature equally straightforward because all the naturals become flats. The only thing to remember is that the order is reversed when flats are used ('Battle Ends And Down Goes Charles' Father'). The reason for using C flat major is so that the basic finger patterns for playing all scales can be learned easily (i.e. 1,2,3 OR 1,2,3,4). In the right hand this scale should be learned ASCENDING first (showing the use of the next available [5th] finger to complete the final octave); the left hand should be learned DESCENDING first (showing how the final group of 1,2,3 is also completed by the next available finger [4th].

  4. The next scale learned is C SHARP major. Again, the key-signature is easy - just convert all the naturals from C major into sharps. No need any more to change the order. This scale is as easy to play as C flat major, and provides the first opportunity to learn that although all major (and minor) scales follow the same finger pattern, it doesn't necessarily begin with the thumb [1st].

  5. It doesn't really matter where you go after this as the main principles have been learned, but I would probably opt for F major (RH) which follows the same pattern as C flat major (LH) and where the thumb passes under the 4th finger when it is on a black key. Notice that the black keys have their own dedicated finger (see above} so Bb is still played with the 4th finger (RH) and the 2nd (LH) even though it's the only black key in the scale. The key signature is the same as it was for C flat major, but this time the first flat {Bb) is retained and the remaining six become naturals. After exploring a nice new piece in D minor (relative) it would be great to use the same transposition technique and learn F SHARP major next. Easy to play, just remember the notes are the same as F major, but everything is sharpened, including the Bb which becomes the only natural in what was the C sharp major key signature.

  6. Eventually, all major and minor key-signatures can be covered simply, without having to resort to any weird complications (e.g. the cycle of 5ths).

I wonder if a computer program might emphasise the 'usual' key-signature in one colour (maybe jet black) and the naturals in a different colour (maybe mid-blue or grey) with an option to miss out the naturals for more advanced users.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.