Note: It would probably be best to read my lesson on chord progressions first, because I will frequently reference things I've mentioned in that lesson.
Believe it or not, this is one aspect of songwriting that is often forgotten. The rules of melody are not near as well-known as the rules for chord progressions/harmony, and few people (even a lot of popular professional musicians) know how to make their melodic content interesting and unique. But fear not! The rules are actually quite simple, quite easy to remember, and most importantly, quite effective.
So again, lets get started.
There are two popular methods of writing melodies. The first is writing the melody first, and then putting the chords under it. This is the method that I personally use when I write (of course I write instrumental "classical" music). The nice thing about writing in this manner is that it keeps your melody untethered. You can write whatever you want, and then you just put the chords under it. That seems pretty straight-forward, and it is.
A common error when using this method is making every single note in the melody a chord-tone. Just to make sure we're up to speed, a "chord-tone" is simply a note that belongs in a given chord. So in a C major chord, the chord-tones are C, E, and G. The problem with putting every note of your melody in a chord is that it usually involves a lot of very rapid chord changes, which is both hard to play and gives your song a stuttery, "skippy" quality. Now if that's what your after, great, but it seems to me that that sort of thing is more of an effect than a general style of writing.
Obviously, just as there are chord-tones, there are non-chord-tones (NCTs). NCTs are notes that are not members of a given chord. Now, there are a bunch of very complex rules about using NCTs, but they really apply more to analyzing a piece of music that's already written than one that is actively being written. The crash-course on NCTs reads something like this:
1. For the most part (there are some very specific exceptions that will be mentioned later) avoid NCTs on a strong beat. In common 4/4 time, this is beats 1 and 3. In 3/4 time, this is beat one only. NCTs work well to move between chord-tones. So, if we're writing over a C chord, we could write the passage C (D) E (F) G. The notes in parenthesis are NCTs, and for the most part, we don't even notice the dissonance that it creates. A rule of thumb is that the faster the NCT goes by, the less we notice the dissonance.
2. If you decide to use an NCT on a strong beat, resolve it into a chord tone. A very common example of this is the very overdone, very common fa-re-mi pattern. (Those names are derived from solfege, which is a choral method for naming the notes of the scale.) This passage dances around the third scale degree of a chord by going above it, then under it, and then finally to that note. In scale degrees, it looks like this. 4-2-3. In note names, if we're over a C major chord, we go F-D-E. Go ahead, play it. It makes you happy to hear, and you'll recognize it as soon as you do.
Now that you've had your fun with that, we can look at the point I was trying to make. Notice that we ultimately resolve to the chord tone, E. This works in other ways. We could go F-E (4-3) A-G (6-5) or D-C (2-1). These all work and are good at creating resolution. Less common is resolution by upward motion, such as B-C (7-8) or F-G (4-5).
3. If you approach an NCT by anything other than step-wise motion, balance it by resolving it in the opposite direction. This one is confusing in explanation, easy in practice. Say, once again, we're over our good friend C Major. If we start at E, and then leap to the NCT A, to balance that leap, we have to resolve down, to G. By the same token, if we start at G and leap to D, we have to resolve upward, to E. This just balances out our melody and keeps everything sounding nice.
4. For the most part, the NCTs should be outnumbered by chord-tones, otherwise we start to lose our sense of key, and for popular Western music, this is a bad thing. Of course, many 20th century composers, like Schoneberg, John Cage, and Steve Reich, live away from the rules of key, but that is a discussion for another time.
Now, the other method of writing melody is by writing the chords first. This isn't much different than writing the melody first, you just write the melody to fit the harmony instead of the other way around. The rules are basically the same.
Okay, off we go. No matter which way you decide to write, these simple rules will help you out.
The first one is to avoid repeated notes. A lot of times, these notes end up sounding like a way to mask that you don't know what to do next. There's almost always a better way to handle these moments, and you should experiment to find what you like best. If you do decide to use repeated notes, they should be used with a purpose. You should almost have to convince yourself to use those guys. Second-guessing is a composers best friend.
The second rule is to use unique high and low points. The high point is the highest note of your melody, and the low note is the lowest note of your melody. By unique, I mean that there should be one of each. The other thing to remember is that these should be strategically placed in your phrase. Putting them right next to each other really robs them both of any effect. A tried-and-true formula is to divide your melody into thirds, and put one at your 1/3 point and one at your 2/3 point. A lot of melodies, if you break them down by pitch content, look a lot like a sine wave. They go up, and then they come down, and then they go down, and then they come up. The important thing to remember is that they always balance. Remember the old adage, what goes up must come down, and vice versa.
3. Think of the larger phrase. Remember how your chord progressions work. Think of your melody as a question-answer. The question usually ends on a dominant chord, or at least a chord of weak resolution. The answer usually resolves to tonic, or sometimes to an embellishing chord, like vi.
3. Repetition is good. From Mozart to Metallica, everyone LOVES repetition. They love it so much, that there's even special names for 'em. A very common one is called a head motive. If I were to diagram it, it'd look like this: Question (Head motive- new material) Answer (Head motive-new material). Assuming we write in 8 bar phrases, each of these guys is 2 bars long. Repetition works by giving your song a sense of unity, and giving your listener a foundation, to where they hear that material and go "Oh yeah, I know where I am now!" But remember, too much of anything is bad. Balance your new material and your repeated material. Both are important.
4. Especially on guitar (or maybe it's just for n00bs like me), it's very easy to fall in a pattern of excessive use of scale-patterns. This is scale degrees such as 1 2 3 4 5 or 8 7 6 5. Now, in small doses, they can be great ways to resolve to a note of what have you. But using too much of these guys makes it sound a lot like you're practicing scales, and a lot less like you're writing a melody.
Once again, this is a crash course, and by no means is it a complete guide to writing melody. The best way you learn that is by experience. The more you write, the more you develop your skills and your style.
At this point, I think it'd be a good idea to mention a couple additional considerations you have to take when you write for horns or other instruments. There are several special things that you have to think about, or you'll create a lot of headaches for yourself.
In all honesty, the best thing you can do is find somebody who is experienced with writing for the instruments you want. You give them the melody and the chords, they arrange it for you.
If you can't or won't do that, these are some very basic things to consider. It should be noted that it is much more difficult to write for an instrument you don't play yourself, and some things that are possible on guitar are not possible on sax or trumpet.
The most important thing to remember is that many wind instruments transpose. This means that the note you write them is not the note that sounds. I'm gonna try to talk to you through how this works, but this is a very involved process, and once again, it is best to get somebody who is experienced with the instrument to do this for you.
Okay. Now lets say you want a trumpet in your latin piece. Most likely, you'll be writing for trumpet in Bb. The "in Bb" part refers to what concert (sounding) pitch sounds when they are given a written C. Confused yet? Yeah, it's very complicated to explain. An example, when a trumpet player plays a C on their instrument, what comes out is a concert Bb. "Concert pitch" refers to the pitch that sounds, as opposed to what is written. So when they are given a G, it sounds an F. When they are given a B, it sounds an A. Now, sometimes it gets a little tricky. We always transpose a whole step, so when you want a concert E, you have to write an F#, because that's a whole step. Concert B is C#, for the same reason. If you write for tenor sax, clarinet, bass clarinet, or flugelhorn, you transpose the same way.
Now, lets say you're writing for Alto Sax, Bari Sax, Eb Clarinet, or Alto Clarinet, the gap is wider. You transpose down a minor sixth, which means that if you give them a written C, they play the concert Eb below it. This distinction is important, because if you assume that they play the note above it, you'll forever be an octave off. So concert C is written as A, and concert Bb is written as G.
Like I said, best to have someone do this for you. It's involved and until you memorize how it works, it's a real headache.
Lucky for you, some instruments are in concert pitch, like flute, oboe, bassoon, all strings, trombone, and tuba. Some of those guys, though, like trombone, tuba, cello, and bass, use bass clef, which is different than reading notes in treble clef. Since the lines on a treble clef are E G B D F (Every Good Boy Does Fine, remember it, it'll serve you well), bass clef is G B D F A (Good Boys Do Fine Always). A great source for figuring this one out is www.musictheory.net, you can see it, which will help you figure it out.
A special note in case for some reason you ever wanna write for french horn. If you're dealing with a competent player, you can write the horn in C. You just need to make a note on the part, mark it as horn in C, and know that we will always transpose down, so if you give us a G, we'll play the D below it.
Here's a table with all the instruments and their transpositions
Piccolo, Flute, Oboe, Bassoon, Trombone, sometimes Horn, Euphonium, Tuba, Timpani, all Keyboard percussion (Xylophone, Marimba, Vibraphone, Glockenspiel, etc.), all strings, including guitar, harp, etc, piano. -non transposing.
Clarinet, Bass Clarinet, Trumpet, Tenor Sax- tranpose down a major second (in Bb)
Alto Sax, Bari Sax, Alto Clarinet, Clarinet in Eb- transpose down a minor sixth (in Eb)
French Horn/English Horn- transpose down a perfect fifth (C is concert F, G is concert C) (in F)
Have I mentioned already that its probably best to get someone who understands this to do it for you?
The other important thing to consider is the ability of your player. If there's ever a question in your mind as to whether a person you write for can play a given part, hold off on it until you can ask them. It should also be noted that musicians greatly exaggerate their abilities (especially trumpet players, for some reason), and so you should be ready to change parts around if you get to rehearsal and it doesn't work out. Always be flexible, and try not to get frustrated.
And one last quick note: Please give your musicians sheet music. We'll try real hard to play the same thing you sing to us, but it's gonna take a while to figure out, and you could do so many more valuable things with your rehearsal time. Let us have it in ample time so we can practice, and listen to us if we tell you we can't play something.
Allright, that's about all I got right now. Hopefully this'll help you out, and you can start writing baller melodies right away. Good luck!