friend, who did
take all those music theory
classes, describes his process thusly:
"I hear the music, and I write it down."
I think the music theory comes into play after the initial idea has taken hold in the artist's brain, when it's time to flesh out the main idea with a counterpoint/bridge/chorus/melody/etc.
Some trivia for wharfinger: In instances of extreme talent, music still played and popular today has been written by composers that never actually heard what they wrote played. Mozart wrote his own requiem on his deathbed, and at the end of his life, Beethoven was too deaf to hear what his compositions actually sounded like.