My own private theory: melody is the result of the balancing of two natural measures of likeness: similar pitch (two notes are close if their pitch is similar in height), and similar harmonically (their pitches are a simple division).
Melodies are sequences of harmonically pleasing notes (1/2, the octave; 2/3, the fifth; 4/5, the third) with 'filler' notes in between, notes that fill the
gaps in pitch, and that are still acceptable harmonically
(a C-D, or do-re, interval is 8/9).