Now this can be pretty dry stuff, and there is nothing necessarily wrong with just trusting your ears and going with what feels right when composing a melody. Having said that, the more you know about music theory, the more options will be available to you when you are making music. I've already touched on how knowing what frequencies various notes sit at is a useful tool in aiding you to mixdown tracks in my blog entry on EQ'ing your drums and bassline together. However, this works for more than your mixdown, and if you know for example what keys are relative to each other, then you can use a key change as an option when composing. Similarly, if you know what notes make up any given key, you can audition your melody in a range of different keys to see what sound works best in the context of your track. The more options for change that you have, the better.
So how do you do this if you are like me, and never had any musical training? Well there are a number of shortcuts around that i've found to be useful. The techniques below do not by any means compromise an exhaustive list, there's much, much more to music theory (and corresponding shortcuts) than what I have briefly mentioned here.
1. Print a copy of the Circle of Fifths and keep it close by.
The Circle of Fifths will help you understand which keys are relative to each other in a visual way. For example, the key of G Major has one sharp in it, meaning that it's relative keys are F Major (containing one flat) and E Minor (containing one sharp) as represented below. For more information see the Wikipedia entry on relative keys here.
2. Program MIDI Versions of All Major and Minor Keys.
This is something that's really easy to do and will save you heaps of time. Find out what notes are in which key, and program them in on your piano roll as MIDI information. Now move the notes back to behind where the MIDI clip starts, and hide all the notes that are not in the key. Ableton lets you do this by by hitting the "fold" function. Now you can only pencil in notes that are musically related to each other.
Some DAW packages have plugins that can help with this also, like the scale function in Ableton which can be put in front of any virtual instrument to ensure you are only playing notes within a given key. I'd encourage you to get familiar with this tool and download or program some presets for it. Everything that you can have available as an option should be taken advantage of. Interestingly enough, also using a drum pad type MIDI controller (such as an MPD or Trigger Finger) will avoid you pressing the wrong notes as opposed to a MIDI keyboard.
3. Write Down Chords For Each Key / Use Chord Plugins.
A lot of people write melodies by beginning with chord progressions. It's pretty handy to have the chords that work in whatever key you are writing in nearby for quick reference. Working out chords is really easy as well. If you want to work the triad chords for each key, just use every "other" letter.
For example, if you are working in C Major, this key consists of the following notes:
C D E F G A B C
Therefore, the triad chords for this key will be as follows:
(C) D (E) F (G) A B C = (C E G)
C (D) E (F) G (A) B C = (D F A)
C D (E) F (G) A (B) C = (E G B)
... And so on., so that the remaining triad chords in C Major are:
F A C
G B D
A C E
B D F
Again, the other thing you can do if you use lots of chords in your music and you don't want to write them down, is simply to use a chord plugin.
I'd say about 3/4 of music uses simple triad type chords or similar (chords involving 4 or 5 notes maximum) as these are very versatile and can work well in a range of contexts. Having said that, sometimes they can sound a bit boring, and I really love the types of chords often used in Jazz, based on Pentatonic keys and such. The principles for these are similar enough, but this will take a bit more research and understanding to get your head around them. There are a few places where you can find, online, presets for Ableton's chord and scale plugins, though I don't have any links right at this moment. I'd highly recommend that you find and download some of these presets if you use Ableton, as a way of having more tools at your disposal to create interesting tension and changes. More importantly, use the chord and scale plugins together! See here for a guide on how to do this.
4. Learn the Rules, But Don't be Afraid to Break Them
With the above shortcuts, you have a few techniques to easily enhance your use of music theory when you are making music. However, sometimes a key change doesn't sound right in a relative key, or a particular triad chord isn't very interesting in the context of your track, or with the sound that you are working with. Similarly i've made melodies that sound great but work across two different keys or that include notes that are not part of the key i'm working in.
Remember to always trust your ears and go with your instincts, don't blindly follow the rules set out by music theory. Use these rules as a guide and a tool only, it's good to have a working knowledge but not be constrained by them.