I quite often get tunes in my head, usually melodies but sometimes basslines that I then work out how to play on an instrument and record before I forget them.
I even have a 'memo app' on my phone so that I can 'sing' the tunes into it and preserve them as and when they occur in places where there's no instrument to hand.
I've built up quite the sonic scrapbook over the years.
Problem is I'm never 100% sure if it's something I've come up with spontaneously or whether lt's something I've heard at some point somewhere beore, that's for some reason re-emerged from my subconcious, that I 'm then basically plagiarising.