It's important to distinguish between copyright and publishing (in the legal sense). If you hear a song being played, and you're influenced, even subconsciously, to create something similar then the other party have a claim potentially, whether its useful or worthwhile pursuing it or not is another matter.
As said above, you need proof of your contribution or your prior art in creating it in the case of just hearing it in a pub
So tab it out, write it down, record it on your phone, then send it to a third party. You don't need a lawyer, just someone reliable, perhaps a parent. Put a statement on it, verbally or written of the date and your name.