Which came first, the mind or the guitar?

We disscussed this point and I wanted to raise it as a comment on other posts but it did not follow completely. When I sit down to play guitar, more specifically to write a song, I may already have a melody in my head that I want to figure out the notes for it on guitar. So I find the root note of the melody, and use the relative pitch in my mind and play notes on the guitar until the pitches match up–relative pitch is where given two notes you can hear how far they are apart, say a third, a fifth, or an octave. I now have a root note and the next note of the melody, which is still fresh in my mind. From there it is usually pretty easy to match up the rest of the melody with the notes on the guitar using relative pitch. Viola, the melody in my head is now one that I can play on guitar, move it up an octave, and even tease it when I am soloing over a chord progression. Then there are other times where I may be soloing or just messing around on the guitar and I play a string of notes that sound good together, repeat them, decide I like the sound, and turn that into a melody. Can you say that in the first instance I wrote the melody and in the latter situation the guitar wrote a melody? If the mind is the homefront of all ideas, and I hear something after I have played it, without really thinking about what I was playing, and decide that I like this new sound, did I actually create this sound myself or does the guitar deserve credit?