Piano Forum

Topic: How to figure out key signature  (Read 4338 times)

Offline playmypianodotcom

  • PS Silver Member
  • Newbie
  • ***
  • Posts: 12
How to figure out key signature
on: April 09, 2011, 11:40:29 PM
Say I know the following information about how many times each type of key is played in a song. How can I figure out what key signature the song is in? (I am writing a computer program to calculate it). Is it possible to tell if the key is major or minor? How accurate overall would this be? For example I have a song with:

A: 80 (This key was pressed 80 times throughout the song)
A#/Bb: 406 (This key was pressed 406 times throughout the song)
B: 66 (This key was pressed 66 times throughout the song)
C: 208 (This key was pressed 205 times throughout the song)
C#/Db: 458 (This key was pressed 458 times throughout the song)
D: 6 (This key was pressed 6 times throughout the song)
D#/Eb: 432 (This key was pressed 432 times throughout the song)
E: 94 (This key was pressed 94 times throughout the song)
F: 312 (This key was pressed 312 times throughout the song)
F#/Gb: 444 (This key was pressed 444 times throughout the song)
G: 12 (This key was pressed 12 times throughout the song)
G#/Ab: 468 (This key was pressed 468 times throughout the song)

Thanks for any help you can provide!

Offline perfect_pitch

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 9213
Re: How to figure out key signature
Reply #1 on: April 10, 2011, 02:06:01 AM
Although computer programming won't help you, due to the fact that some pieces modulate to other keys, potentially skweing the results of which key its in dependent on the amount of keys pressed...

Also - depends on the length of a piece of music - you'd have much greater chance of it working with smaller pieces (less than a minute say), than longer pieces.

However - if I were to guess, I'd say the piece you chose in this example was in D flat major possibly... Five flats (or maybe it's relative minor).

Or... you could learn to read key signatures which is a pretty good tool to have, you know - if you want to play piano.    8)

Which piece did you use in this example???

Offline Bob

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 16364
Re: How to figure out key signature
Reply #2 on: April 10, 2011, 03:22:19 AM
Wow.  Just have the program look at the last and lowest note.  That's probably it.  And analyze the chord, major or minor... and then compare it to the first chord I guess... *Bob darns those Piccardi thirds.*

Or instead of a program you could just look at the key signature and the last notes.
Favorite new teacher quote -- "You found the only possible wrong answer."

Offline playmypianodotcom

  • PS Silver Member
  • Newbie
  • ***
  • Posts: 12
Re: How to figure out key signature
Reply #3 on: April 10, 2011, 03:30:45 AM
Thanks for the tips. I need a computer program because it needs to be an automated system that will do this thousands of times. I will never actually see it.

The example I gave you was Claire de Lune....which is 5 flats! Nice work.

Offline perfect_pitch

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 9213
Re: How to figure out key signature
Reply #4 on: April 10, 2011, 06:17:04 AM
Just have the program look at the last and lowest note.  That's probably it.  And analyze the chord, major or minor...

What about Baroque Tierce de Picarde's??? Again - may skew the results.

But yeah... Read the key signature. Best way.

Offline playmypianodotcom

  • PS Silver Member
  • Newbie
  • ***
  • Posts: 12
Re: How to figure out key signature
Reply #5 on: April 10, 2011, 12:16:09 PM
Well I have no idea what Baroque Tierce de Picarses are. haha I will have to research that when I get a chance.

There is no key signature to read. Like I said, this will all be automated and read in from a MIDI file. Even if there was a key signature, I would never see it.

Offline tunneller

  • Jr. Member
  • **
  • Posts: 67
I like this question
Reply #6 on: April 10, 2011, 03:25:05 PM
I like this question because it captures a misunderstanding I had, actually one that I still struggle with: what is the purpose of having a key!!  ;)

In the old days (i.e, 2-3 years ago before I found this website), I thought they the purpose of key marking was simply a way to minimize the number of accidentals drawn on the page. So then the plymypianodotcom's question is easy:
   You put A#, C#, D#, F# and G# at the beginning of the sheet of music and you are done. (Or do the same with flats if you care).

But now I'm starting to understand that if you have a "key" then you have certain chords in that key that will sound "recognizable" to ears that have been listening to western classical music. And conversely that the pianist should be bringing out in the music <this bit I find hard to put in words>. So the way plymypianodotcom computer program should be heading is not counting keys, but counting chord patterns. And by chords that means arpeggios too.

Offline lunchalpha

  • PS Silver Member
  • Newbie
  • ***
  • Posts: 5
Re: I like this question
Reply #7 on: April 10, 2011, 08:20:30 PM
I like this question because it captures a misunderstanding I had, actually one that I still struggle with: what is the purpose of having a key!!  ;)

In the old days (i.e, 2-3 years ago before I found this website), I thought they the purpose of key marking was simply a way to minimize the number of accidentals drawn on the page. So then the plymypianodotcom's question is easy:
   You put A#, C#, D#, F# and G# at the beginning of the sheet of music and you are done. (Or do the same with flats if you care).

But now I'm starting to understand that if you have a "key" then you have certain chords in that key that will sound "recognizable" to ears that have been listening to western classical music. And conversely that the pianist should be bringing out in the music <this bit I find hard to put in words>. So the way plymypianodotcom computer program should be heading is not counting keys, but counting chord patterns. And by chords that means arpeggios too.


I'm no expert, but I believe you're only partially correct. The key of a piece also acts to establish the "tonal center," or the overall tone of the piece. For example, in the key of C Major, C is the tonal center because it is the first note of the C Major scale. Every other key in C Major can be thought of as relative to C. This may be confusing if you think that every song in C Major HAS to start on C, or if the tonal center is the first key you press in a piece, because the key signature simply tells you what notes you should be using. I prefer to think of the key signature at the beginning of the piece as a handy tool as to what scale I'll be using.

But really, I think I'm over complicating it. A key signature is just a fancy word for saying what tone the piece is in. If I play a song in D, then in F, it's the same song, just with a different tone. You're right when you say that each key has it's own chords, because each key has a special chord that goes with each note in their scale. Sometimes two keys' chords are enharmonic (sound the same) because they are essentially the same scale (C Major and A minor for example. The only difference is C is the tone of one and A the tone of the other).

Sorry if this is somewhat vague. I'm 100% sure I left out a few theory explanations that would be easy to confuse if they've never been heard of before.  :-[

Offline pianowolfi

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 5654
Re: How to figure out key signature
Reply #8 on: April 10, 2011, 08:31:32 PM
Say I know the following information about how many times each type of key is played in a song. How can I figure out what key signature the song is in? (I am writing a computer program to calculate it). Is it possible to tell if the key is major or minor? How accurate overall would this be? For example I have a song with:

A: 80 (This key was pressed 80 times throughout the song)
A#/Bb: 406 (This key was pressed 406 times throughout the song)
B: 66 (This key was pressed 66 times throughout the song)
C: 208 (This key was pressed 205 times throughout the song)
C#/Db: 458 (This key was pressed 458 times throughout the song)
D: 6 (This key was pressed 6 times throughout the song)
D#/Eb: 432 (This key was pressed 432 times throughout the song)
E: 94 (This key was pressed 94 times throughout the song)
F: 312 (This key was pressed 312 times throughout the song)
F#/Gb: 444 (This key was pressed 444 times throughout the song)
G: 12 (This key was pressed 12 times throughout the song)
G#/Ab: 468 (This key was pressed 468 times throughout the song)

Thanks for any help you can provide!

Well if you are really good at music theory you will for sure figure out a much better program.
But every program will only be as good as for instance "google translator" when it comes to analyzing music. And I think everybody knows what ridiculous results google translator can deliver. Music is made for the human ear (and mind) and only a human ear can really establish a relation to a key note. Rules are only valid to some extent.

Offline Bob

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 16364
Re: How to figure out key signature
Reply #9 on: April 10, 2011, 10:04:07 PM
It really doesn't matter how many times a key was struck during a piece.  That has nothing to do with the tonal center.  At least not directly.  A composer might just like a melody with lots of notes that hovers around a note other than the tonic.

I think Finale and Sibelius can already do this.  You do have to give it something of the rules of music though.  I'm not sure how that's done.  Or how it handles extended chords or very dissonant music.
Favorite new teacher quote -- "You found the only possible wrong answer."

Offline playmypianodotcom

  • PS Silver Member
  • Newbie
  • ***
  • Posts: 12
Re: How to figure out key signature
Reply #10 on: April 10, 2011, 11:32:35 PM
I know there is no 100% perfect method of doing this programatically. Just hoping to get as close as possible.

Offline liszt1022

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 659
Re: How to figure out key signature
Reply #11 on: April 11, 2011, 12:27:13 AM
Not sure why you'd need to write a program for this... if it's classical piano, the key signature will be written in. If it's an improvisation, it really doesn't matter what the key is if you like the way it sounds. And if you would like to know for the purposes of being sure you're improvising in a real key and not a mode, learn some basic music theory.

Offline Bob

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 16364
Favorite new teacher quote -- "You found the only possible wrong answer."

Offline brogers70

  • PS Silver Member
  • Sr. Member
  • ***
  • Posts: 1756
Re: How to figure out key signature
Reply #13 on: April 11, 2011, 05:34:54 AM
It is an interesting problem in programming. OK, you can't look at the music or the key signature. Can you get your program to look only at the last chord? If so, that is very likely to be the tonic chord in the key the piece was in. The exceptions will probably be more modern pieces with which any program you write will have trouble anyway.

If you want to ask the question "What is the dominant tonality in a given interval of time in this piece?" based on the frequency with which notes are struck during that interval, then I think it really is a very interesting programming problem. I think that you would need to do neural nets rather than a straightforward counting program.

So if you want the key of the piece as a whole and can get the software to focus on the final chord, then it's almost trivial, with due allowance for the Tierce de Picardy (which is the situation in which a piece in a minor key has a final chord in the corresponding major key, E minor-E major, for example). On the other hand, if you want to train a computer to recognize what tonality a piece is in at any given moment, then that's a cool but difficult problem.

Offline playmypianodotcom

  • PS Silver Member
  • Newbie
  • ***
  • Posts: 12
Re: How to figure out key signature
Reply #14 on: April 13, 2011, 07:20:32 PM
Thanks brogers70 for the advice. I think I should be able to get the last chord of the piece. I will try it out and let you know how it works!
For more information about this topic, click search below!

Piano Street Magazine:
When Practice Stagnates – Breaking the Performance Ceiling: Robotic Training for Pianists

“Practice makes perfect” is a common mantra for any pianist, but we all know it’s an oversimplification. While practice often leads to improvement, true perfection is elusive. But according to recent research, a robotic exoskeleton hand could help pianists improve their speed of performing difficult pianistic patterns, by overcoming the well-known “ceiling effect”. Read more
 

Logo light pianostreet.com - the website for classical pianists, piano teachers, students and piano music enthusiasts.

Subscribe for unlimited access

Sign up

Follow us

Piano Street Digicert