There is a definite connection between the notes of the melody and the notes of the chord.
This is a big subject and musicians love to break the rules, so this explanation will be short and imperfect—but should give you the basic idea.
You can think about it as “which chords fit this melody?” or “what melody would go with these chords?”: a song can be written either way round!
- For the first question, see the article “Learn To Harmonize By Ear” which explains how you put chords to a melody.
If you’re interested in playing by ear or e.g. improvising on saxophone, you’re probably more interested in the second question.
Both the melody and the chords will generally draw their notes from the song’s key, i.e. its scale. It’s generally “safe” to play any notes from that scale in the melody, but the notes which sound best will be the ones from the chord currently being played.
A simple way to put this into practice would be playing the chord’s notes, for example playing an arpeggio or broken chord. However, to keep things interesting you will probably want to branch out from just these notes. You might choose to introduce notes in between those (but still from the scale), or add grace notes (or “blue notes”) which sax players would often do by bending the pitch down a bit to add expression.
An initial approach to improvising over a I,IV,V,vi progression would be to play freely around the scale (the major scale corresponding to the I chord) but aim to hit the 4, 5, and 6 notes during the bars which use those chords. You might also like to hit the notes which are distinctive to those chords – for example, hitting note 7 of the scale during the V chord.
Ear training chords, chord progressions or scales will help you learn to hear which notes you can use in your improvization.