As for the ear training, is that literally just sitting at keyboard and hitting notes over and over again until eveytime you hear one you can recall it being an Fb etc?
its the composition or the familiarity of the keyboard or the voicings as well as the fingering that gives you the hint of what note is being played. And thus it will guess for you by ear. for Example an Eb key is a well known sweet key because where it sits in the keyboard. If you continously practice or are familiar with all the keys and know how they sound, they will tell you the notes. Almost all violin concertoes are written in the key of D. Because of where the violin sits. therefore one has a head start of what notes are being played. I learned this from an englishman in LA his name is peter something, i forget his last name, but he scored The charlies angels series among others. Elderly Experience somtimes is the best way to learn. The sensuous of man is truly remarkable.
As of the topic about writing music down fast enough before the thought disappears.
This is truly why the great composers died very young, it was to write continuously with no disrupt untill the composition was complete. Write it down quickly, untill the body gives up and research shown at 35 its when the body gives up. Its true to athletes also. Makes sense to me.
I've spend most of my life understanding these issues. My studies have been documented and published. It is without a doubt that speed in writting comes from knowledge and knowledge is theory. When I first got starterd, theory in books meant the scales and chords. Very elementary. There are some books like ramau and a couple of others, good luck trying to make sense out of century old written texts for the most part, nevertheless they didn't sufficiently supply me with the great composers tools. I had to discover and document as I went along. And most of my discoveries were all by accidental sensuous ear comparison. It took years to unvail.
Orchestration books are of-course helpfull also. For orchestration.
if you are a piano player of-course also makes a difference. The other instrumentalist all play piano also.