Paul McCartney said that he woke up one morning only to find "Yesterday" in his head. Apparently he just sat at the piano and it just played itself, as though already finished. Apparently it just came so naturally to him that his reaction was "this is someone else's song and I must have heard it before". He had to play the tune for several people before he was convinced that it wasn't an already existing song but his own original instead!Funny that you bring this up. Just yesterday I started reading a book on how a lot of great music was written as the result of a dream.
The book I'm reading purports that some of the greatest songs were "downloaded" to musicians in their sleep. Many many musician' accounts state that they didn't write the song, they "uncovered" it, like an architect. All of these accounts claim that the song wrote itself in a very short period of time as well.