It's true music theory can be quite frustrating at first and can take a while to figure out, but it can come in handy once you get it. Ghyt is right. Music Theory teaches you the names of things so that when you hear a song that sounds like another song you can think "Aha! they are just using the dominant 7 chord to resolve back to the Tonic", or "I know that one that's a deceptive cadence" Then all of a sudden your brain starts categorizing different sounds created by moving from one chord to another. You'll stop thinking of things in terms of Notes or Frets and start thinking about the distance between notes and the quality of chords. When coming up with a melody I always try to use my ear first though. I'll put my bass line on a loop, and then grab whatever instrument I think I can use. Guitar, keyboard, synth plugins, jew harp, whatever, and mess around until I find the notes that work with the song. (Often the note that makes a song unique is the note that's not in the scale that you would expect to use) That's usually when my brain realizes what key I'm in and what scales are being used. Sometimes I won't figure it out, but I usually learn something by trying.
in C major they would be:
C E G - Cmajor
D F A - D minor
E G B - E minor
F A C - F major
G B D - G major
A C E - A minor
B D F - B diminished
OK.. SOOoooo.. what i would say is this.. if you wrote a baseline in c major that was C C E A A D G C.... you could view each of those notes as the roots of chords. then you could chose other notes from those chords for the melody. The main notes of the melody would be on the chord tones at the same time as the bass with some filler notes in between.
This is just a hack ass crash course way of going about it, but it's the only way I can think to get anything across in such a small blurb.
Of course, all of this depends on if you can figure out what key you're in. Also, if you are in a minor key things get a little more complicated.
If you want minor the same rule applies as long as you just make the 6th note into the 1st note
C major: A minor:
1 = C 1 = A
2 = D 2 = B
3 = E 3 = C
4 = F 4 = D
5 = G 5 =E
6 = A 6 = F
7 = B 7 = G
C E G - Cmajor A C E - A minor
D F A - D minor B D F - B diminished
E G B - E minor C E G - Cmajor
F A C - F major D F A - D minor
G B D - G major E G B - E minor
A C E - A minor F A C - F major
B D F - B diminished G B D - G major
A minor and C major both consist of only white keys on a piano. or natural notes (no sharps or flats) start here black keys are scary.
It always helps to find songs you like and try to figure out what key they are in. What notes they are using and how the chords assist the melody and bass. Have fun!