I struggled a bit to find a good title for this question since I can only really describe it with an example.
I have been spending some time on chord progressions and improvising and would think that this is a simple melody in C major using a
I IV I progression:
X:1 M:4/4 K:C |"C"C2D2E2F2|G2A2B2c2 |"F"d2c2B2A2|G2F2E2D2|"C"C8|
The notes all belong to the key of C as I would expect.
Now consider this melody over the same chord progression:
X:1 M:4/4 K:C |"C"C2D2E2F2|G2F2E2G2 |"F"F2G2A2_B2|c2_B2A2F2|"C"C8|
To my ears, the melody demands the flat b in measure 3 and 4 and doesn't sound right without it. Likewise in the example above, the b in measure 2 and 3 only sounds right to me when it is natural.
So my question is why does one of these two simple and fairly similar melodies seem to require an out of key note?
Does the second example actually change keys and is not the
IV of C major but the
I of F major? If so, is there a logic to what enables this (in terms of music theory)? It must lie somewhere in the way the melody moves I guess.
It seems like I am missing some fundamental piece of knowledge and would be happy if someone could direct me to where I can learn more about this (terminology, links).
Edit: I can't seem to get SE to print the melody along with the chords the way I want. Trying to fix this.