Segmenting a sound file before each of its attacks
If it is a single instrument playing without any background noise/instruments, then the problem becomes simple. All you have to do is keep track of energy, which is calculated at a defined window size (say 40 milliseconds). Wherever you see the energy increasing and sustaining for a while (you'll have to define how long a note is good for you to split your audio), you can mark the ascent of such an energy plot as the point to split. 

You can also split audio when a particular note is played, for this you'll have to track energy in the respective spectrum band of the note you want to split the audio on. For example to track note A4 (a') which has 440Hz frequency. You might have to track the energy in a band around 440 Hz, say 420 to 460 Hz. Mind you, this splitting business based on notes played gets more complicated when complex notes are played.

Also, this problem gets really difficult when you have multiple instruments.