I think when composing your own melodies advanced knowledge of music theory is very much helpful in any situation. If you are completely sample based, in my opinion you can get by with the basics. I have been producing for 8 years (completely sample based) and I've noticed I just have a good ear for tone. I know if it's in the right key or not just by going off my ears. Never took a piano lesson or any other music lesson. Just picked it up and learned as I went. I think the more time you spend making beats and listening to music, the more sophisticated your ear will become. It's just like drum programming, the more you fuck with it the better you get. But I will say I am jealous of people like my homeboy that can play a shit load of instruments by ear. That is a great gift to have.